From: Mauro Scomparin Date: Wed, 26 Feb 2020 21:24:38 +0000 (+0100) Subject: moved test and created Dockerfile X-Git-Url: https://git.scompo.it/?a=commitdiff_plain;h=4a98ff511ef0a31d9f9650751ca2648d25e23b35;p=static-server.git moved test and created Dockerfile --- diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ddf89e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:alpine as builder +RUN mkdir /build +ADD . /build/ +WORKDIR /build +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -tags netgo -ldflags '-w' -o server server.go + +FROM scratch +COPY --from=builder /build/server /app/ +WORKDIR /app +CMD ["./server"] diff --git a/server_test.go b/server_test.go new file mode 100644 index 0000000..7d269c3 --- /dev/null +++ b/server_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "testing" + "os" +) + +const ( + defaultValue = "DEFAULT VALUE" + envVar = "MY_TEST_VAR" + expectedValue = "MY TEST VALUE" +) + +func TestReadEnvVarReturnsDefaultValueWhenEnvVarNotSet(t *testing.T) { + res := ReadEnvVar("NOT_PRESENT", defaultValue) + if res != defaultValue { + t.Errorf("Did not return the default value when the enviroinment variable wasn't set") + } +} + +func TestReadEnvVarReturnsTheExpectedValueWhenSet(t *testing.T) { + os.SetEnv(envVar, expectedValue) + res := ReadEnvVar(envVar, defaultValue) + if res != expectedValue { + t.Errorf("Did not return the expected value set in the enviroinment variable") + } +} \ No newline at end of file diff --git a/test/server_test.go b/test/server_test.go deleted file mode 100644 index 7d269c3..0000000 --- a/test/server_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "testing" - "os" -) - -const ( - defaultValue = "DEFAULT VALUE" - envVar = "MY_TEST_VAR" - expectedValue = "MY TEST VALUE" -) - -func TestReadEnvVarReturnsDefaultValueWhenEnvVarNotSet(t *testing.T) { - res := ReadEnvVar("NOT_PRESENT", defaultValue) - if res != defaultValue { - t.Errorf("Did not return the default value when the enviroinment variable wasn't set") - } -} - -func TestReadEnvVarReturnsTheExpectedValueWhenSet(t *testing.T) { - os.SetEnv(envVar, expectedValue) - res := ReadEnvVar(envVar, defaultValue) - if res != expectedValue { - t.Errorf("Did not return the expected value set in the enviroinment variable") - } -} \ No newline at end of file