v2.31.0-dev9 062dcae

runtime_health_status_test.go RawHistoryFolder

1package docker
2
3import (
4	"context"
5	"net/http"
6	"net/http/httptest"
7	"testing"
8
9	"github.com/stretchr/testify/assert"
10	"github.com/stretchr/testify/require"
11)
12
13func TestRuntime_GetContainerHealthStatus_ConfiguredHealthcheck(t *testing.T) {
14	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15		assert.Equal(t, http.MethodGet, r.Method)
16		assert.Equal(t, "/v1.41/containers/test-container/json", r.URL.Path)
17
18		w.Header().Set("Content-Type", "application/json")
19		_, _ = w.Write([]byte(`{
20			"Id":"test-container",
21			"State":{"Status":"running","Health":{"Status":"healthy","FailingStreak":0,"Log":[]}},
22			"Config":{"Healthcheck":{"Test":["CMD-SHELL","curl -f http://localhost/health || exit 1"]}}
23		}`))
24	}))
25	defer server.Close()
26
27	runtime := newRuntimeForHTTPServer(t, server)
28	status, hasHealthcheck, err := runtime.GetContainerHealthStatus(context.Background(), "test-container")
29
30	require.NoError(t, err)
31	assert.True(t, hasHealthcheck)
32	assert.Equal(t, "healthy", status)
33}
34
35func TestRuntime_GetContainerHealthStatus_NoConfiguredHealthcheckWithStateHealthObject(t *testing.T) {
36	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
37		assert.Equal(t, http.MethodGet, r.Method)
38		assert.Equal(t, "/v1.41/containers/test-container/json", r.URL.Path)
39
40		w.Header().Set("Content-Type", "application/json")
41		_, _ = w.Write([]byte(`{
42			"Id":"test-container",
43			"State":{"Status":"running","Health":{"Status":"","FailingStreak":0,"Log":null}},
44			"Config":{"Healthcheck":null}
45		}`))
46	}))
47	defer server.Close()
48
49	runtime := newRuntimeForHTTPServer(t, server)
50	status, hasHealthcheck, err := runtime.GetContainerHealthStatus(context.Background(), "test-container")
51
52	require.NoError(t, err)
53	assert.False(t, hasHealthcheck)
54	assert.Equal(t, "", status)
55}
56
57func TestRuntime_GetContainerHealthStatus_DisabledHealthcheck(t *testing.T) {
58	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
59		assert.Equal(t, http.MethodGet, r.Method)
60		assert.Equal(t, "/v1.41/containers/test-container/json", r.URL.Path)
61
62		w.Header().Set("Content-Type", "application/json")
63		_, _ = w.Write([]byte(`{
64			"Id":"test-container",
65			"State":{"Status":"running","Health":{"Status":"starting","FailingStreak":0,"Log":[]}},
66			"Config":{"Healthcheck":{"Test":["NONE"]}}
67		}`))
68	}))
69	defer server.Close()
70
71	runtime := newRuntimeForHTTPServer(t, server)
72	status, hasHealthcheck, err := runtime.GetContainerHealthStatus(context.Background(), "test-container")
73
74	require.NoError(t, err)
75	assert.False(t, hasHealthcheck)
76	assert.Equal(t, "", status)
77}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close