Skip to content

Commit cd5e3a5

Browse files
authored
test: improve date parsing robustness (runfinch#206)
* test: improve date parsing robustness Signed-off-by: Justin Alvarez <[email protected]> * add debug logging Signed-off-by: Justin Alvarez <[email protected]> * more debug Signed-off-by: Justin Alvarez <[email protected]> * bump test versions Signed-off-by: Justin Alvarez <[email protected]> * undo debug changes Signed-off-by: Justin Alvarez <[email protected]> * unfocus test Signed-off-by: Justin Alvarez <[email protected]> --------- Signed-off-by: Justin Alvarez <[email protected]>
1 parent b98eef9 commit cd5e3a5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

e2e/tests/container_restart.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"fmt"
99
"io"
1010
"net/http"
11+
"strings"
1112
"time"
13+
"unicode"
1214

1315
. "github.com/onsi/ginkgo/v2"
1416
. "github.com/onsi/gomega"
@@ -40,7 +42,10 @@ func ContainerRestart(opt *option.Option) {
4042
It("should start and restart the container", func() {
4143
containerShouldBeRunning(opt, testContainerName)
4244

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)
4449

4550
restartRelativeUrl := fmt.Sprintf("/containers/%s/restart", testContainerName)
4651
res, err := uClient.Post(client.ConvertToFinchUrl(version, restartRelativeUrl), "application/json", nil)
@@ -57,8 +62,13 @@ func ContainerRestart(opt *option.Option) {
5762
body, err := io.ReadAll(res.Body)
5863
Expect(err).Should(BeNil())
5964

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())
6272
Expect(before.Before(date)).Should(BeTrue())
6373
})
6474
It("should fail to restart container that does not exist", func() {

setup-test-env.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22
# Set versions
3-
RUNC_VERSION=1.1.14
4-
NERDCTL_VERSION=2.0.0
5-
BUILDKIT_VERSION=0.15.2
3+
RUNC_VERSION=1.2.4
4+
NERDCTL_VERSION=2.0.3
5+
BUILDKIT_VERSION=0.18.1
66
CNI_VERSION=1.6.2
77

88
apt update && apt install -y make gcc linux-libc-dev libseccomp-dev pkg-config git

0 commit comments

Comments
 (0)