From b99ad6da99e981d38fdcecaec4dd69b093e90c21 Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Wed, 29 Sep 2021 06:43:06 +0000 Subject: [PATCH] adding unit tests for config.go --- fedilogue/config.go | 1 + fedilogue/config_test.go | 14 ++++++++++++++ fedilogue/fedilogue.go | 4 ++++ fedilogue/testhelper.go | 15 +++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 fedilogue/config_test.go create mode 100644 fedilogue/testhelper.go diff --git a/fedilogue/config.go b/fedilogue/config.go index d799f21..611250e 100644 --- a/fedilogue/config.go +++ b/fedilogue/config.go @@ -45,6 +45,7 @@ type Settings struct { var settings Settings +/* Test: TestStringexists */ func stringexists(needle string, haystack []string) bool { for _, check := range haystack { if check == needle { diff --git a/fedilogue/config_test.go b/fedilogue/config_test.go new file mode 100644 index 0000000..40369a8 --- /dev/null +++ b/fedilogue/config_test.go @@ -0,0 +1,14 @@ +package main + +import ( + "testing" +) + +func TestStringexists(t *testing.T) { + var empty_strings = []string {} + var three_strings = []string {"first", "second", "third"} + + AssertEqual(t, stringexists("amything", empty_strings), false) + AssertEqual(t, stringexists("second", three_strings), true) + AssertEqual(t, stringexists("fourth", three_strings), false) +} diff --git a/fedilogue/fedilogue.go b/fedilogue/fedilogue.go index 44e66bf..863f11c 100644 --- a/fedilogue/fedilogue.go +++ b/fedilogue/fedilogue.go @@ -27,6 +27,10 @@ func statusReportHandler() { } } +/* Tests: + - TestStatusReport_empty_run + - TestStatusReport_full_content +*/ func StatusReport() { running := 0 keepalive := 0 diff --git a/fedilogue/testhelper.go b/fedilogue/testhelper.go new file mode 100644 index 0000000..9baca3a --- /dev/null +++ b/fedilogue/testhelper.go @@ -0,0 +1,15 @@ +package main + +import ( + "reflect" + "testing" +) + +// AssertEqual checks if values are equal +func AssertEqual(t *testing.T, a interface{}, b interface{}) { + if a == b { + return + } + // debug.PrintStack() + t.Errorf("Received %v (type %v), expected %v (type %v)", a, reflect.TypeOf(a), b, reflect.TypeOf(b)) +}