github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/soliton/timeutil/time_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSES/QL-LICENSE file. 4 5 // Copyright 2020 WHTCORPS INC, Inc. 6 // 7 // Licensed under the Apache License, Version 2.0 (the "License"); 8 // you may not use this file except in compliance with the License. 9 // You may obtain a copy of the License at 10 // 11 // http://www.apache.org/licenses/LICENSE-2.0 12 // 13 // Unless required by applicable law or agreed to in writing, software 14 // distributed under the License is distributed on an "AS IS" BASIS, 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 18 package timeutil 19 20 import ( 21 "os" 22 "testing" 23 24 . "github.com/whtcorpsinc/check" 25 ) 26 27 var _ = Suite(&testTimeSuite{}) 28 29 func TestT(t *testing.T) { 30 TestingT(t) 31 } 32 33 type testTimeSuite struct{} 34 35 func (s *testTimeSuite) TestgetTZNameFromFileName(c *C) { 36 tz, err := inferTZNameFromFileName("/usr/share/zoneinfo/Asia/Shanghai") 37 38 c.Assert(err, IsNil) 39 c.Assert(tz, Equals, "Asia/Shanghai") 40 41 tz, err = inferTZNameFromFileName("/usr/share/zoneinfo.default/Asia/Shanghai") 42 43 c.Assert(err, IsNil) 44 c.Assert(tz, Equals, "Asia/Shanghai") 45 } 46 47 func (s *testTimeSuite) TestLocal(c *C) { 48 os.Setenv("TZ", "Asia/Shanghai") 49 systemTZ.CausetStore(InferSystemTZ()) 50 loc := SystemLocation() 51 c.Assert(systemTZ.Load(), Equals, "Asia/Shanghai") 52 c.Assert(loc.String(), Equals, "Asia/Shanghai") 53 54 os.Setenv("TZ", "UTC") 55 // reset systemTZ 56 systemTZ.CausetStore(InferSystemTZ()) 57 loc = SystemLocation() 58 c.Assert(loc.String(), Equals, "UTC") 59 60 os.Setenv("TZ", "") 61 // reset systemTZ 62 systemTZ.CausetStore(InferSystemTZ()) 63 loc = SystemLocation() 64 c.Assert(loc.String(), Equals, "UTC") 65 os.Unsetenv("TZ") 66 }