adding unit tests for config.go

This commit is contained in:
Farhan Khan 2021-09-29 06:43:06 +00:00
parent 9a0524a8c2
commit b99ad6da99
4 changed files with 34 additions and 0 deletions

View File

@ -45,6 +45,7 @@ type Settings struct {
var settings Settings var settings Settings
/* Test: TestStringexists */
func stringexists(needle string, haystack []string) bool { func stringexists(needle string, haystack []string) bool {
for _, check := range haystack { for _, check := range haystack {
if check == needle { if check == needle {

14
fedilogue/config_test.go Normal file
View File

@ -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)
}

View File

@ -27,6 +27,10 @@ func statusReportHandler() {
} }
} }
/* Tests:
- TestStatusReport_empty_run
- TestStatusReport_full_content
*/
func StatusReport() { func StatusReport() {
running := 0 running := 0
keepalive := 0 keepalive := 0

15
fedilogue/testhelper.go Normal file
View File

@ -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))
}