github.com/koderover/helm@v2.17.0+incompatible/pkg/timeconv/timeconv_test.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package timeconv 18 19 import ( 20 "testing" 21 "time" 22 ) 23 24 func TestNow(t *testing.T) { 25 now := time.Now() 26 ts := Now() 27 var drift int64 = 5 28 if ts.Seconds < int64(now.Second())-drift { 29 t.Errorf("Unexpected time drift: %d", ts.Seconds) 30 } 31 } 32 33 func TestTimestamp(t *testing.T) { 34 now := time.Now() 35 ts := Timestamp(now) 36 37 if now.Unix() != ts.Seconds { 38 t.Errorf("Unexpected time drift: %d to %d", now.Second(), ts.Seconds) 39 } 40 41 if now.Nanosecond() != int(ts.Nanos) { 42 t.Errorf("Unexpected nano drift: %d to %d", now.Nanosecond(), ts.Nanos) 43 } 44 } 45 46 func TestTime(t *testing.T) { 47 nowts := Now() 48 now := Time(nowts) 49 50 if now.Unix() != nowts.Seconds { 51 t.Errorf("Unexpected time drift %d", now.Unix()) 52 } 53 } 54 55 func TestFormat(t *testing.T) { 56 now := time.Now() 57 nowts := Timestamp(now) 58 59 if now.Format(time.ANSIC) != Format(nowts, time.ANSIC) { 60 t.Error("Format mismatch") 61 } 62 }