From: Mauro Scomparin Date: Wed, 26 Feb 2020 21:24:38 +0000 (+0100) Subject: Created Dockerfile and run tests X-Git-Url: https://git.scompo.it/?a=commitdiff_plain;h=3e67b28f4f480f80bc2ee7afdad3a0b6b497520e;p=static-server.git Created Dockerfile and run tests --- diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f4915a4..984a4b7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -25,7 +25,7 @@ jobs: fi - name: Test - run: go test -v + run: go test -v ./... - name: Build - run: go build -v . + run: go build -v 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..e94b28e --- /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