fix tests and delete some useless tests
This commit is contained in:
@ -1,72 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func cleanUp() {
|
||||
handlers = make(map[string]Handler)
|
||||
}
|
||||
|
||||
func TestAddHandler(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
AddHandler("test", ActorNode, api.PermUser, func(context api.Context) {
|
||||
return nil
|
||||
})
|
||||
if len(handlers) != 1 {
|
||||
t.Errorf("Handler insertion failed, got: %d handlers, want: %d.", len(handlers), 1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallOfHandler(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
i := 0
|
||||
AddHandler("test", ActorNode, api.PermUser, func(context api.Context) {
|
||||
i++
|
||||
return nil
|
||||
})
|
||||
|
||||
// simulate the call of the api
|
||||
handleAPICall("test", "", ActorNode, nil)
|
||||
|
||||
if i != 1 {
|
||||
t.Errorf("Unexpected number of Lambda calls : %d/1", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodingOfArguments(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
AddHandler("test", ActorNode, api.PermUser, func(context api.Context) {
|
||||
var args struct {
|
||||
Test string
|
||||
TestInt int
|
||||
}
|
||||
err := FillStruct(&args, info.Data)
|
||||
if err != nil {
|
||||
t.Errorf("Error parsing args: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
if args.TestInt != 42 || args.Test != "myString" {
|
||||
t.Errorf("Wrong parsing of argument parameters : %d/42 - %s/myString", args.TestInt, args.Test)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
// simulate the call of the api
|
||||
handleAPICall("test", `{"Test":"myString","TestInt":42}`, ActorNode, nil)
|
||||
}
|
||||
|
||||
func TestNoHandlerCovers(t *testing.T) {
|
||||
cleanUp()
|
||||
|
||||
ret := handleAPICall("test", "", ActorNode, nil)
|
||||
|
||||
if ret != nil {
|
||||
t.Error("Expect nil return within unhandled api action")
|
||||
}
|
||||
}
|
9
apiGo/config/Config_test.go
Normal file
9
apiGo/config/Config_test.go
Normal file
@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSaveLoadConfig(t *testing.T) {
|
||||
generateNewConfig("", "openmediacenter.cfg")
|
||||
|
||||
Init()
|
||||
}
|
Reference in New Issue
Block a user