From b09336614e1dc9d6a3cd77557b8e77c2af11ce2c Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Thu, 5 Sep 2024 16:51:04 +0200 Subject: [PATCH 1/2] Bump Docker base image to Alpine Linux 3.20 (#182) --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a46d12a..5cb28ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.6 +FROM alpine:3.20 RUN apk --no-cache add \ ca-certificates curl @@ -16,4 +16,4 @@ EXPOSE 8082 8083 8084 ENTRYPOINT ["mmock","-config-path","/config","-tls-path","/tls"] CMD ["-server-ip","0.0.0.0","-console-ip","0.0.0.0"] -HEALTHCHECK --interval=30s --timeout=3s --start-period=3s --retries=2 CMD curl -f http://localhost:8082 || exit 1 +HEALTHCHECK --interval=30s --timeout=3s --start-period=3s --retries=2 CMD curl -fsS http://localhost:8082 || exit 1 From e9640eb8f6a023cf1091775829d6ce4fa7118cd5 Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Thu, 5 Sep 2024 16:53:53 +0200 Subject: [PATCH 2/2] Use httptest.Server to provide local test server in TestHTTPContent() (#185) Use httptest.Server to provide local test server in TestHTTPContent() https://pkg.go.dev/net/http/httptest#Server --------- Co-authored-by: Jonathan C. Dietrich Co-authored-by: Jonathan Dietrich <105676949+jdietrich-tc@users.noreply.github.com> --- pkg/vars/stream_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/vars/stream_test.go b/pkg/vars/stream_test.go index 75770a7..398c321 100644 --- a/pkg/vars/stream_test.go +++ b/pkg/vars/stream_test.go @@ -3,6 +3,8 @@ package vars import ( "fmt" "io/ioutil" + "net/http" + "net/http/httptest" "os" "path/filepath" "strings" @@ -44,7 +46,13 @@ func TestReadFile(t *testing.T) { func TestHTTPContent(t *testing.T) { st := Stream{} - k := "http.contents(https://golang.org/)" + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte("Go\n")) + })) + defer server.Close() + + k := fmt.Sprintf("http.contents(%s)", server.URL) holders := []string{k} result := st.Fill(holders) @@ -53,7 +61,7 @@ func TestHTTPContent(t *testing.T) { t.Errorf("Stream key not found") } - if !strings.Contains(v[0], "Go") { + if strings.TrimSpace(v[0]) != "Go" { t.Errorf("Couldn't get the content. Value: %s", v) } }