diff --git a/pkg/util/time_utils.go b/pkg/util/time_utils.go index 320c740..b750ee7 100644 --- a/pkg/util/time_utils.go +++ b/pkg/util/time_utils.go @@ -6,9 +6,10 @@ package util import ( "fmt" + "time" + rolloutv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" "k8s.io/klog/v2" - "time" ) const ( diff --git a/pkg/util/time_utils_test.go b/pkg/util/time_utils_test.go index df2989e..849b2f9 100644 --- a/pkg/util/time_utils_test.go +++ b/pkg/util/time_utils_test.go @@ -5,11 +5,12 @@ Copyright 2022 The KubePort Authors. package util import ( + "testing" + "time" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" rolloutv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" - "testing" - "time" ) var allowTime = &rolloutv1alpha1.AllowRunTime{ @@ -69,6 +70,37 @@ func TestTimeInSlice(t *testing.T) { } } +func TestTimeZone(t *testing.T) { + RegisterFailHandler(Fail) + test := []struct { + name string + data *rolloutv1alpha1.TimeZone + expect *time.Location + }{ + { + name: "local", + data: nil, + expect: time.Local, + }, + { + name: "UTC", + data: &rolloutv1alpha1.TimeZone{ + Name: "UTC", + Offset: 28800, + }, + expect: time.FixedZone("UTC", 28800), + }, + } + for _, s := range test { + t.Run(s.name, func(t *testing.T) { + zone := TimeZone(s.data) + now := time.Now() + Expect(now.In(zone).Unix()).Should(Equal(now.In(s.expect).Unix())) + }) + } + +} + func TestValidateTime(t *testing.T) { RegisterFailHandler(Fail) test := []struct {