Browse code

use consts for health-status in tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/04/26 22:03:26
Showing 3 changed files
... ...
@@ -148,13 +148,13 @@ func TestViewWithHealthCheck(t *testing.T) {
148 148
 
149 149
 	one.Health = &Health{
150 150
 		Health: container.Health{
151
-			Status: "starting",
151
+			Status: container.Starting,
152 152
 		},
153 153
 	}
154 154
 	assert.NilError(t, one.CheckpointTo(context.Background(), db))
155 155
 	s, err := db.Snapshot().Get(one.ID)
156 156
 	assert.NilError(t, err)
157
-	assert.Equal(t, s.Health, "starting")
157
+	assert.Equal(t, s.Health, container.Starting)
158 158
 }
159 159
 
160 160
 func TestTruncIndex(t *testing.T) {
... ...
@@ -76,19 +76,19 @@ func (s *DockerCLIHealthSuite) TestHealth(c *testing.T) {
76 76
 
77 77
 	// Start
78 78
 	cli.DockerCmd(c, "start", name)
79
-	waitForHealthStatus(c, name, "starting", "healthy")
79
+	waitForHealthStatus(c, name, container.Starting, container.Healthy)
80 80
 
81 81
 	// Make it fail
82 82
 	cli.DockerCmd(c, "exec", name, "rm", "/status")
83
-	waitForHealthStatus(c, name, "healthy", "unhealthy")
83
+	waitForHealthStatus(c, name, container.Healthy, container.Unhealthy)
84 84
 
85 85
 	// Inspect the status
86 86
 	out = cli.DockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name).Stdout()
87
-	assert.Equal(c, out, "unhealthy\n")
87
+	assert.Equal(c, strings.TrimSpace(out), container.Unhealthy)
88 88
 
89 89
 	// Make it healthy again
90 90
 	cli.DockerCmd(c, "exec", name, "touch", "/status")
91
-	waitForHealthStatus(c, name, "unhealthy", "healthy")
91
+	waitForHealthStatus(c, name, container.Unhealthy, container.Healthy)
92 92
 
93 93
 	// Remove container
94 94
 	cli.DockerCmd(c, "rm", "-f", name)
... ...
@@ -113,9 +113,9 @@ func (s *DockerCLIHealthSuite) TestHealth(c *testing.T) {
113 113
 		"--health-cmd=cat /status",
114 114
 		"no_healthcheck",
115 115
 	)
116
-	waitForHealthStatus(c, "fatal_healthcheck", "starting", "healthy")
116
+	waitForHealthStatus(c, "fatal_healthcheck", container.Starting, container.Healthy)
117 117
 	health := getHealth(c, "fatal_healthcheck")
118
-	assert.Equal(c, health.Status, "healthy")
118
+	assert.Equal(c, health.Status, container.Healthy)
119 119
 	assert.Equal(c, health.FailingStreak, 0)
120 120
 	last := health.Log[len(health.Log)-1]
121 121
 	assert.Equal(c, last.ExitCode, 0)
... ...
@@ -123,7 +123,7 @@ func (s *DockerCLIHealthSuite) TestHealth(c *testing.T) {
123 123
 
124 124
 	// Fail the check
125 125
 	cli.DockerCmd(c, "exec", "fatal_healthcheck", "rm", "/status")
126
-	waitForHealthStatus(c, "fatal_healthcheck", "healthy", "unhealthy")
126
+	waitForHealthStatus(c, "fatal_healthcheck", container.Healthy, container.Unhealthy)
127 127
 
128 128
 	failsStr := cli.DockerCmd(c, "inspect", "--format={{.State.Health.FailingStreak}}", "fatal_healthcheck").Combined()
129 129
 	fails, err := strconv.Atoi(strings.TrimSpace(failsStr))
... ...
@@ -135,10 +135,10 @@ func (s *DockerCLIHealthSuite) TestHealth(c *testing.T) {
135 135
 	// Note: if the interval is too small, it seems that Docker spends all its time running health
136 136
 	// checks and never gets around to killing it.
137 137
 	cli.DockerCmd(c, "run", "-d", "--name=test", "--health-interval=1s", "--health-cmd=sleep 5m", "--health-timeout=1s", imageName)
138
-	waitForHealthStatus(c, "test", "starting", "unhealthy")
138
+	waitForHealthStatus(c, "test", container.Starting, container.Unhealthy)
139 139
 	health = getHealth(c, "test")
140 140
 	last = health.Log[len(health.Log)-1]
141
-	assert.Equal(c, health.Status, "unhealthy")
141
+	assert.Equal(c, health.Status, container.Unhealthy)
142 142
 	assert.Equal(c, last.ExitCode, -1)
143 143
 	assert.Equal(c, last.Output, "Health check exceeded timeout (1s)")
144 144
 	cli.DockerCmd(c, "rm", "-f", "test")
... ...
@@ -173,5 +173,5 @@ ENTRYPOINT /bin/sh -c "sleep 600"`))
173 173
 
174 174
 	// Start
175 175
 	cli.DockerCmd(c, "start", name)
176
-	waitForHealthStatus(c, name, "starting", "healthy")
176
+	waitForHealthStatus(c, name, container.Starting, container.Healthy)
177 177
 }
... ...
@@ -135,7 +135,7 @@ func TestHealthStartInterval(t *testing.T) {
135 135
 		if err != nil {
136 136
 			return poll.Error(err)
137 137
 		}
138
-		if inspect.State.Health.Status != "healthy" {
138
+		if inspect.State.Health.Status != containertypes.Healthy {
139 139
 			if len(inspect.State.Health.Log) > 0 {
140 140
 				t.Log(inspect.State.Health.Log[len(inspect.State.Health.Log)-1])
141 141
 			}