From 6d291906e73fb0a84ed23e09fa684410a75cb90b Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Mon, 16 Sep 2024 16:12:01 -0400 Subject: [PATCH] Hello MQTT --- go.mod | 3 +++ main.go | 15 +++++++++++++++ main_test.go | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 go.mod create mode 100644 main.go create mode 100644 main_test.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a6fa431 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.runcible.io/learning/learn_mqtt_go + +go 1.23.1 diff --git a/main.go b/main.go new file mode 100644 index 0000000..d477410 --- /dev/null +++ b/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "io" + "os" +) + +func printMessage(w io.Writer, msg string) { + fmt.Fprint(w, msg) +} + +func main() { + printMessage(os.Stdout, "Hello MQTT\n") +} diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..e7ee9fd --- /dev/null +++ b/main_test.go @@ -0,0 +1,17 @@ +package main + +import ( + "bytes" + "testing" +) + +func TestPrintMessage(t *testing.T) { + buffer := bytes.Buffer{} + printMessage(&buffer, "Hello MQTT\n") + got := buffer.String() + want := "Hello MQTT\n" + + if got != want { + t.Errorf("Error. Got %s but wanted %s", got, want) + } +}