From 77e6cc55b75adf182d1c2f0a310638b6c7cfd4f7 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 26 Jan 2022 13:12:15 +0000 Subject: [PATCH] Add test --- go.mod | 3 +++ hello.go | 8 ++++++-- hello_test.go | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 go.mod create mode 100644 hello_test.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..afdf576 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module hello + +go 1.17 diff --git a/hello.go b/hello.go index 8117330..a53bfbb 100644 --- a/hello.go +++ b/hello.go @@ -2,6 +2,10 @@ package main import "fmt" -func main() { - fmt.Println("Hello, world") +func Hello() string { + return "Hello, world" +} + +func main() { + fmt.Println(Hello()) } diff --git a/hello_test.go b/hello_test.go new file mode 100644 index 0000000..0531825 --- /dev/null +++ b/hello_test.go @@ -0,0 +1,12 @@ +package main + +import "testing" + +func TestHello(t *testing.T) { + got := Hello() + want := "Hello, world" + + if got != want { + t.Errorf("got %q want %q", got, want) + } +}