Skip to content

Commit

Permalink
test: Attempt to fix failing unit tests in CI
Browse files Browse the repository at this point in the history
Signed-off-by: Mahendra Paipuri <[email protected]>
  • Loading branch information
mahendrapaipuri committed Oct 19, 2024
1 parent ee31bdd commit 6235510
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/api/resource/openstack/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ package openstack

import (
"encoding/json"
"os"
"strconv"
"time"
)

func init() {
// If we are in CI env, use fixed time location
// for e2e tests
if os.Getenv("CI") != "" {
t, _ := time.Parse("2006-01-02 15:04:05 MST", "2023-09-27 18:00:00 CEST")
currentLocation = t.Location()
} else {
currentLocation = time.Now().Location()
}
}

const RFC3339MilliNoZ = "2006-01-02T15:04:05.999999"

var currentLocation *time.Location

type JSONRFC3339MilliNoZ time.Time

func (jt *JSONRFC3339MilliNoZ) UnmarshalJSON(data []byte) error {
Expand Down Expand Up @@ -35,7 +49,7 @@ func (jt *JSONRFC3339MilliNoZ) UnmarshalJSON(data []byte) error {
t.Minute(),
t.Second(),
t.Nanosecond(),
time.Now().Location(),
currentLocation,
),
)

Expand Down Expand Up @@ -151,7 +165,7 @@ func (r *Server) UnmarshalJSON(b []byte) error {
r.CreatedAt.Minute(),
r.CreatedAt.Second(),
r.CreatedAt.Nanosecond(),
time.Now().Location(),
currentLocation,
)
r.UpdatedAt = time.Date(
r.UpdatedAt.Year(),
Expand All @@ -161,7 +175,7 @@ func (r *Server) UnmarshalJSON(b []byte) error {
r.UpdatedAt.Minute(),
r.UpdatedAt.Second(),
r.UpdatedAt.Nanosecond(),
time.Now().Location(),
currentLocation,
)

return err
Expand Down

0 comments on commit 6235510

Please sign in to comment.