8
8
"fmt"
9
9
"io"
10
10
"net/http"
11
+ "strings"
11
12
"time"
13
+ "unicode"
12
14
13
15
. "github.com/onsi/ginkgo/v2"
14
16
. "github.com/onsi/gomega"
@@ -40,7 +42,10 @@ func ContainerRestart(opt *option.Option) {
40
42
It ("should start and restart the container" , func () {
41
43
containerShouldBeRunning (opt , testContainerName )
42
44
43
- before := time .Now ().Round (0 )
45
+ // use location to ensure all times are UTC since
46
+ // the default location is different on different platforms
47
+ lo , _ := time .LoadLocation ("UTC" )
48
+ before := time .Now ().In (lo ).Round (0 )
44
49
45
50
restartRelativeUrl := fmt .Sprintf ("/containers/%s/restart" , testContainerName )
46
51
res , err := uClient .Post (client .ConvertToFinchUrl (version , restartRelativeUrl ), "application/json" , nil )
@@ -57,8 +62,13 @@ func ContainerRestart(opt *option.Option) {
57
62
body , err := io .ReadAll (res .Body )
58
63
Expect (err ).Should (BeNil ())
59
64
60
- dateStr := string (body [8 : len (body )- 1 ])
61
- date , _ := time .Parse (time .UnixDate , dateStr )
65
+ // get the second date from the container logs, which are newline delimited
66
+ // and strip newlines, spaces, and non-printable characters
67
+ dateStr := strings .TrimFunc (strings .Split (string (body ), "\n " )[1 ], func (r rune ) bool {
68
+ return ! unicode .IsGraphic (r ) || unicode .IsSpace (r )
69
+ })
70
+ date , err := time .ParseInLocation (time .UnixDate , dateStr , lo )
71
+ Expect (err ).Should (BeNil ())
62
72
Expect (before .Before (date )).Should (BeTrue ())
63
73
})
64
74
It ("should fail to restart container that does not exist" , func () {
0 commit comments