fi
- name: Test
- run: go test -v
+ run: go test -v ./...
- name: Build
- run: go build -v .
+ run: go build -v
--- /dev/null
+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"]
--- /dev/null
+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
+++ /dev/null
-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