Created Dockerfile and run tests
authorMauro Scomparin <scompo@gmail.com>
Wed, 26 Feb 2020 21:24:38 +0000 (22:24 +0100)
committerMauro Scomparin <scompo@gmail.com>
Wed, 26 Feb 2020 21:33:14 +0000 (22:33 +0100)
.github/workflows/go.yml
Dockerfile [new file with mode: 0644]
server_test.go [new file with mode: 0644]
test/server_test.go [deleted file]

index f4915a41f18b9bd2bcd791f52de888516541b96d..984a4b7058e5c96142b299f78739738e55e6726a 100644 (file)
@@ -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 (file)
index 0000000..4ddf89e
--- /dev/null
@@ -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 (file)
index 0000000..e94b28e
--- /dev/null
@@ -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 (file)
index 7d269c3..0000000
+++ /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