adding unit tests for config.go
This commit is contained in:
parent
9a0524a8c2
commit
b99ad6da99
@ -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 {
|
||||
|
14
fedilogue/config_test.go
Normal file
14
fedilogue/config_test.go
Normal 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)
|
||||
}
|
@ -27,6 +27,10 @@ func statusReportHandler() {
|
||||
}
|
||||
}
|
||||
|
||||
/* Tests:
|
||||
- TestStatusReport_empty_run
|
||||
- TestStatusReport_full_content
|
||||
*/
|
||||
func StatusReport() {
|
||||
running := 0
|
||||
keepalive := 0
|
||||
|
15
fedilogue/testhelper.go
Normal file
15
fedilogue/testhelper.go
Normal 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))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user