From 2bf1de58e0baf4955e18b552aa9813b63e46f24c Mon Sep 17 00:00:00 2001 From: Adam Fisher Date: Tue, 4 Aug 2026 14:20:34 +0000 Subject: [PATCH] Fix build: add go.mod, proper imports, and make test pass The project did not build: - No go.mod, so the GOPATH-era relative import "./src" in main.go was rejected. - SayHello() returned "hi" but TestSimpleString expected "hello". Adds go.mod with module path github.com/guardian/coding-exercise-project/go, switches main.go to the module-qualified import, and returns "hello" from SayHello(). script/test runs `go test ./...` from the module root rather than `pushd src && go test`. Removes TestNothing, a t.Skip stub. Replaces the println builtin, which writes to stderr, with fmt.Println. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- go/go.mod | 3 +++ go/main.go | 8 ++++++-- go/script/test | 8 +++----- go/src/pairing.go | 2 +- go/src/pairing_test.go | 10 +++------- 5 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 go/go.mod diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 0000000..fcb18b1 --- /dev/null +++ b/go/go.mod @@ -0,0 +1,3 @@ +module github.com/guardian/coding-exercise-project/go + +go 1.21 diff --git a/go/main.go b/go/main.go index 630d398..039bd26 100644 --- a/go/main.go +++ b/go/main.go @@ -1,7 +1,11 @@ package main -import "./src" +import ( + "fmt" + + "github.com/guardian/coding-exercise-project/go/src" +) func main() { - println(pairing.SayHello()) + fmt.Println(pairing.SayHello()) } diff --git a/go/script/test b/go/script/test index 1a21bbb..5cae49c 100755 --- a/go/script/test +++ b/go/script/test @@ -1,9 +1,7 @@ #!/usr/bin/env bash -set -e +set -euo pipefail -pushd src +cd "$(dirname "${BASH_SOURCE[0]}")/.." -go test - -popd +go test ./... diff --git a/go/src/pairing.go b/go/src/pairing.go index 8931531..9d8cffb 100644 --- a/go/src/pairing.go +++ b/go/src/pairing.go @@ -1,5 +1,5 @@ package pairing func SayHello() string { - return "hi" + return "hello" } diff --git a/go/src/pairing_test.go b/go/src/pairing_test.go index bb74fa3..f6402de 100644 --- a/go/src/pairing_test.go +++ b/go/src/pairing_test.go @@ -2,12 +2,8 @@ package pairing import "testing" -func TestNothing(t *testing.T) { - t.Skip("no implemented") -} - func TestSimpleString(t *testing.T) { - if SayHello() != "hello" { - t.Error("couldn't get hello message") - } + if SayHello() != "hello" { + t.Error("couldn't get hello message") + } }