MCPcopy Create free account
hub / github.com/efficientgo/e2e / TestDockerEnvironment

Function TestDockerEnvironment

env_docker_ext_test.go:23–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21}
22
23func TestDockerEnvironment(t *testing.T) {
24 t.Parallel()
25
26 e, err := e2e.New()
27 testutil.Ok(t, err)
28 t.Cleanup(e.Close)
29
30 p1 := e2edb.NewPrometheus(e, "prometheus-1")
31 testutil.Equals(t, "prometheus-1", p1.Name())
32 testutil.Equals(t, filepath.Join(e.SharedDir(), "data", p1.Name()), p1.Dir())
33 testutil.Equals(t, "e2e-80D5E99C3992-prometheus-1:9090", p1.InternalEndpoint("http"))
34 testutil.Equals(t, "", p1.InternalEndpoint("not-existing"))
35 testutil.Assert(t, !p1.IsRunning())
36
37 // Errors as p1 was not started yet.
38 testutil.NotOk(t, p1.WaitReady())
39 testutil.Ok(t, p1.Stop())
40 testutil.Ok(t, p1.Kill())
41
42 testutil.NotOk(t, p1.Exec(wgetFlagsCmd("localhost:9090")))
43 testutil.Equals(t, "stopped", p1.Endpoint("http"))
44 testutil.Equals(t, "stopped", p1.Endpoint("not-existing"))
45
46 p2 := e2edb.NewPrometheus(e, "prometheus-2")
47 testutil.Ok(t, e2e.StartAndWaitReady(p1, p2))
48 testutil.Ok(t, p1.WaitReady())
49 testutil.Ok(t, p1.WaitReady())
50
51 testutil.Ok(t, p1.WaitSumMetrics(e2emon.Greater(50), "prometheus_tsdb_head_samples_appended_total"))
52
53 testutil.Equals(t, "prometheus-1", p1.Name())
54 testutil.Equals(t, filepath.Join(e.SharedDir(), "data", p1.Name()), p1.Dir())
55 testutil.Equals(t, "e2e-80D5E99C3992-prometheus-1:9090", p1.InternalEndpoint("http"))
56 testutil.Equals(t, "", p1.InternalEndpoint("not-existing"))
57 testutil.Assert(t, p1.IsRunning())
58
59 expectedFlagsOutputProm1 := "{\"status\":\"success\",\"data\":{\"alertmanager.notification-queue-capacity\":\"10000\",\"alertmanager.timeout\":\"\",\"config.file\":\"" + filepath.Join(e.SharedDir(), "/data/prometheus-1/prometheus.yml") + "\",\"enable-feature\":\"\",\"log.format\":\"logfmt\",\"log.level\":\"info\",\"query.lookback-delta\":\"5m\",\"query.max-concurrency\":\"20\",\"query.max-samples\":\"50000000\",\"query.timeout\":\"2m\",\"rules.alert.for-grace-period\":\"10m\",\"rules.alert.for-outage-tolerance\":\"1h\",\"rules.alert.resend-delay\":\"1m\",\"scrape.adjust-timestamps\":\"true\",\"scrape.discovery-reload-interval\":\"5s\",\"scrape.timestamp-tolerance\":\"2ms\",\"storage.agent.no-lockfile\":\"false\",\"storage.agent.path\":\"data-agent/\",\"storage.agent.retention.max-time\":\"0s\",\"storage.agent.retention.min-time\":\"0s\",\"storage.agent.wal-compression\":\"true\",\"storage.agent.wal-segment-size\":\"0B\",\"storage.agent.wal-truncate-frequency\":\"0s\",\"storage.remote.flush-deadline\":\"1m\",\"storage.remote.read-concurrent-limit\":\"10\",\"storage.remote.read-max-bytes-in-frame\":\"1048576\",\"storage.remote.read-sample-limit\":\"50000000\",\"storage.tsdb.allow-overlapping-blocks\":\"false\",\"storage.tsdb.head-chunks-write-queue-size\":\"0\",\"storage.tsdb.max-block-chunk-segment-size\":\"0B\",\"storage.tsdb.max-block-duration\":\"2h\",\"storage.tsdb.min-block-duration\":\"2h\",\"storage.tsdb.no-lockfile\":\"false\",\"storage.tsdb.path\":\"" + filepath.Join(e.SharedDir(), "/data/prometheus-1/") + "\",\"storage.tsdb.retention\":\"0s\",\"storage.tsdb.retention.size\":\"0B\",\"storage.tsdb.retention.time\":\"0s\",\"storage.tsdb.wal-compression\":\"true\",\"storage.tsdb.wal-segment-size\":\"0B\",\"web.config.file\":\"\",\"web.console.libraries\":\"console_libraries\",\"web.console.templates\":\"consoles\",\"web.cors.origin\":\".*\",\"web.enable-admin-api\":\"false\",\"web.enable-lifecycle\":\"false\",\"web.enable-remote-write-receiver\":\"false\",\"web.external-url\":\"\",\"web.listen-address\":\":9090\",\"web.max-connections\":\"512\",\"web.page-title\":\"Prometheus Time Series Collection and Processing Server\",\"web.read-timeout\":\"5m\",\"web.route-prefix\":\"/\",\"web.user-assets\":\"\"}}"
60 expectedFlagsOutputProm2 := "{\"status\":\"success\",\"data\":{\"alertmanager.notification-queue-capacity\":\"10000\",\"alertmanager.timeout\":\"\",\"config.file\":\"" + filepath.Join(e.SharedDir(), "/data/prometheus-2/prometheus.yml") + "\",\"enable-feature\":\"\",\"log.format\":\"logfmt\",\"log.level\":\"info\",\"query.lookback-delta\":\"5m\",\"query.max-concurrency\":\"20\",\"query.max-samples\":\"50000000\",\"query.timeout\":\"2m\",\"rules.alert.for-grace-period\":\"10m\",\"rules.alert.for-outage-tolerance\":\"1h\",\"rules.alert.resend-delay\":\"1m\",\"scrape.adjust-timestamps\":\"true\",\"scrape.discovery-reload-interval\":\"5s\",\"scrape.timestamp-tolerance\":\"2ms\",\"storage.agent.no-lockfile\":\"false\",\"storage.agent.path\":\"data-agent/\",\"storage.agent.retention.max-time\":\"0s\",\"storage.agent.retention.min-time\":\"0s\",\"storage.agent.wal-compression\":\"true\",\"storage.agent.wal-segment-size\":\"0B\",\"storage.agent.wal-truncate-frequency\":\"0s\",\"storage.remote.flush-deadline\":\"1m\",\"storage.remote.read-concurrent-limit\":\"10\",\"storage.remote.read-max-bytes-in-frame\":\"1048576\",\"storage.remote.read-sample-limit\":\"50000000\",\"storage.tsdb.allow-overlapping-blocks\":\"false\",\"storage.tsdb.head-chunks-write-queue-size\":\"0\",\"storage.tsdb.max-block-chunk-segment-size\":\"0B\",\"storage.tsdb.max-block-duration\":\"2h\",\"storage.tsdb.min-block-duration\":\"2h\",\"storage.tsdb.no-lockfile\":\"false\",\"storage.tsdb.path\":\"" + filepath.Join(e.SharedDir(), "/data/prometheus-2/") + "\",\"storage.tsdb.retention\":\"0s\",\"storage.tsdb.retention.size\":\"0B\",\"storage.tsdb.retention.time\":\"0s\",\"storage.tsdb.wal-compression\":\"true\",\"storage.tsdb.wal-segment-size\":\"0B\",\"web.config.file\":\"\",\"web.console.libraries\":\"console_libraries\",\"web.console.templates\":\"consoles\",\"web.cors.origin\":\".*\",\"web.enable-admin-api\":\"false\",\"web.enable-lifecycle\":\"false\",\"web.enable-remote-write-receiver\":\"false\",\"web.external-url\":\"\",\"web.listen-address\":\":9090\",\"web.max-connections\":\"512\",\"web.page-title\":\"Prometheus Time Series Collection and Processing Server\",\"web.read-timeout\":\"5m\",\"web.route-prefix\":\"/\",\"web.user-assets\":\"\"}}"
61
62 var out bytes.Buffer
63 testutil.Ok(t, p1.Exec(wgetFlagsCmd("localhost:9090"), e2e.WithExecOptionStdout(&out)))
64 testutil.Equals(t, expectedFlagsOutputProm1, out.String())
65
66 resp, err := http.Get("http://" + p1.Endpoint("http") + "/api/v1/status/flags")
67 testutil.Ok(t, err)
68 defer resp.Body.Close()
69
70 b, err := io.ReadAll(resp.Body)
71 testutil.Ok(t, err)
72 testutil.Equals(t, expectedFlagsOutputProm1, string(b))
73 testutil.Equals(t, "", p1.Endpoint("not-existing"))
74
75 // Now try the same but cross containers.
76 out.Reset()
77 testutil.Ok(t, p1.Exec(wgetFlagsCmd(p2.InternalEndpoint("http")), e2e.WithExecOptionStdout(&out)))
78 testutil.Equals(t, expectedFlagsOutputProm2, out.String())
79
80 testutil.NotOk(t, p1.Start()) // Starting ok, should fail.

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
StartAndWaitReadyFunction · 0.92
WithExecOptionStdoutFunction · 0.92
NewCommandRunUntilStopFunction · 0.92
NewCommandFunction · 0.92
wgetFlagsCmdFunction · 0.85
NameMethod · 0.65
SharedDirMethod · 0.65
DirMethod · 0.65
InternalEndpointMethod · 0.65
IsRunningMethod · 0.65
WaitReadyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…