2017-11-22 13:06:14 +00:00
|
|
|
// +build e2e_test
|
|
|
|
|
|
|
|
// Tests in `./lib` package will run only when `e2e_test` build tag is provided.
|
|
|
|
// It's required to prevent some files from being included in the binary.
|
|
|
|
// Check out `lib/utils.go` for more details.
|
|
|
|
|
2016-11-05 17:12:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2017-08-10 15:31:29 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2016-11-05 17:12:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// the actual test functions are in non-_test.go files (so that they can use cgo i.e. import "C")
|
|
|
|
// the only intent of these wrappers is for gotest can find what tests are exposed.
|
|
|
|
func TestExportedAPI(t *testing.T) {
|
|
|
|
allTestsDone := make(chan struct{}, 1)
|
|
|
|
go testExportedAPI(t, allTestsDone)
|
|
|
|
|
2016-12-18 20:36:17 +00:00
|
|
|
<-allTestsDone
|
2016-11-05 17:12:24 +00:00
|
|
|
}
|
2017-08-10 15:31:29 +00:00
|
|
|
|
|
|
|
func TestValidateNodeConfig(t *testing.T) {
|
2018-03-29 09:20:55 +00:00
|
|
|
noErrorsCallback := func(resp APIDetailedResponse) {
|
2017-08-10 15:31:29 +00:00
|
|
|
require.True(t, resp.Status, "expected status equal true")
|
|
|
|
require.Empty(t, resp.FieldErrors)
|
|
|
|
require.Empty(t, resp.Message)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
Name string
|
|
|
|
Config string
|
2018-03-29 09:20:55 +00:00
|
|
|
Callback func(APIDetailedResponse)
|
2017-08-10 15:31:29 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "response for valid config",
|
|
|
|
Config: `{
|
|
|
|
"NetworkId": 1,
|
|
|
|
"DataDir": "/tmp"
|
|
|
|
}`,
|
|
|
|
Callback: noErrorsCallback,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "response for invalid JSON string",
|
|
|
|
Config: `{"Network": }`,
|
2018-03-29 09:20:55 +00:00
|
|
|
Callback: func(resp APIDetailedResponse) {
|
2017-08-10 15:31:29 +00:00
|
|
|
require.False(t, resp.Status)
|
|
|
|
require.Contains(t, resp.Message, "validation: invalid character '}'")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "response for config with multiple errors",
|
|
|
|
Config: `{}`,
|
2018-03-29 09:20:55 +00:00
|
|
|
Callback: func(resp APIDetailedResponse) {
|
2017-08-10 15:31:29 +00:00
|
|
|
required := map[string]string{
|
|
|
|
"NodeConfig.NetworkID": "required",
|
|
|
|
"NodeConfig.DataDir": "required",
|
|
|
|
}
|
|
|
|
|
|
|
|
require.False(t, resp.Status)
|
|
|
|
require.Contains(t, resp.Message, "validation: validation failed")
|
|
|
|
require.Equal(t, 2, len(resp.FieldErrors))
|
|
|
|
|
|
|
|
for _, err := range resp.FieldErrors {
|
|
|
|
require.Contains(t, required, err.Parameter)
|
|
|
|
require.Contains(t, err.Error(), required[err.Parameter])
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Logf("TestValidateNodeConfig: %s", tc.Name)
|
|
|
|
testValidateNodeConfig(t, tc.Config, tc.Callback)
|
|
|
|
}
|
|
|
|
}
|