Added more test cases to config
* Fixed typo with cluster and authinfo message formatting. * Added more test case to config ( add cluster, add credential, add context ) Change-Id: I35d7533d308fb9048d3060e81b65abbad342e770
This commit is contained in:
parent
eadf3ae4ee
commit
64b3e9cf7e
@ -23,8 +23,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
fakeFile string = "/fake/config/path"
|
||||
testFile string = "testdata/airshipui.json"
|
||||
fakeFile string = "/fake/config/path"
|
||||
testFile string = "testdata/airshipui.json"
|
||||
invalidTestFile string = "testdata/airshipui_invalid.json"
|
||||
)
|
||||
|
||||
func TestSetUIConfig(t *testing.T) {
|
||||
@ -43,6 +44,9 @@ func TestSetUIConfig(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, conf, configs.UIConfig)
|
||||
|
||||
err = configs.SetUIConfig(invalidTestFile)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestFileNotFound(t *testing.T) {
|
||||
|
7
internal/configs/testdata/airshipui_invalid.json
vendored
Normal file
7
internal/configs/testdata/airshipui_invalid.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"authMethod": {
|
||||
"url": "http://fake.auth.method.com/auth"
|
||||
},
|
||||
"plugins": "",
|
||||
"clusters": ""
|
||||
}
|
@ -157,9 +157,9 @@ func setContext(request configs.WsMessage) (string, error) {
|
||||
|
||||
var message string
|
||||
if modified {
|
||||
message = fmt.Sprintf("Context %q modified.", request.ClusterOptions.Name)
|
||||
message = fmt.Sprintf("Context %q modified.", request.ContextOptions.Name)
|
||||
} else {
|
||||
message = fmt.Sprintf("Context %q created.", request.ClusterOptions.Name)
|
||||
message = fmt.Sprintf("Context %q created.", request.ContextOptions.Name)
|
||||
}
|
||||
|
||||
return message, err
|
||||
@ -171,9 +171,9 @@ func setCredential(request configs.WsMessage) (string, error) {
|
||||
|
||||
var message string
|
||||
if modified {
|
||||
message = fmt.Sprintf("Credential %q modified.", request.ClusterOptions.Name)
|
||||
message = fmt.Sprintf("Credential %q modified.", request.AuthInfoOptions.Name)
|
||||
} else {
|
||||
message = fmt.Sprintf("Credential %q created.", request.ClusterOptions.Name)
|
||||
message = fmt.Sprintf("Credential %q created.", request.AuthInfoOptions.Name)
|
||||
}
|
||||
|
||||
return message, err
|
||||
|
@ -71,6 +71,33 @@ func TestHandleDefaultConfigRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
assert.Equal(t, expected, response)
|
||||
|
||||
request = configs.WsMessage{
|
||||
Type: configs.AirshipCTL,
|
||||
Component: configs.CTLConfig,
|
||||
SubComponent: configs.SetCredential,
|
||||
AuthInfoOptions: testutil.DummyAuthInfoOptions(),
|
||||
}
|
||||
response = HandleConfigRequest(request)
|
||||
assert.Contains(t, response.Message, "created")
|
||||
|
||||
request = configs.WsMessage{
|
||||
Type: configs.AirshipCTL,
|
||||
Component: configs.CTLConfig,
|
||||
SubComponent: configs.SetCluster,
|
||||
ClusterOptions: testutil.DummyClusterOptions(),
|
||||
}
|
||||
response = HandleConfigRequest(request)
|
||||
assert.Contains(t, response.Message, "created")
|
||||
|
||||
request = configs.WsMessage{
|
||||
Type: configs.AirshipCTL,
|
||||
Component: configs.CTLConfig,
|
||||
SubComponent: configs.SetContext,
|
||||
ContextOptions: testutil.DummyContextOptions(),
|
||||
}
|
||||
response = HandleConfigRequest(request)
|
||||
assert.Contains(t, response.Message, "created")
|
||||
}
|
||||
|
||||
func TestHandleUnknownConfigSubComponent(t *testing.T) {
|
||||
|
@ -195,3 +195,38 @@ func DummyCompleteConfig() configs.Config {
|
||||
Clusters: []configs.Cluster{c},
|
||||
}
|
||||
}
|
||||
|
||||
// DummyContextOptions creates ContextOptions config object
|
||||
// for unit testing
|
||||
func DummyContextOptions() *config.ContextOptions {
|
||||
co := &config.ContextOptions{}
|
||||
co.Name = "dummy_context"
|
||||
co.Manifest = "dummy_manifest"
|
||||
co.AuthInfo = "dummy_user"
|
||||
co.CurrentContext = false
|
||||
co.Namespace = "dummy_namespace"
|
||||
return co
|
||||
}
|
||||
|
||||
// DummyClusterOptions creates ClusterOptions config object
|
||||
// for unit testing
|
||||
func DummyClusterOptions() *config.ClusterOptions {
|
||||
co := &config.ClusterOptions{}
|
||||
co.Name = "dummy_cluster"
|
||||
co.ClusterType = config.Ephemeral
|
||||
co.Server = "http://1.1.1.1"
|
||||
co.InsecureSkipTLSVerify = false
|
||||
co.CertificateAuthority = ""
|
||||
co.EmbedCAData = false
|
||||
|
||||
return co
|
||||
}
|
||||
|
||||
// DummyAuthInfoOptions creates AuthInfoOptions config object
|
||||
// for unit testing
|
||||
func DummyAuthInfoOptions() *config.AuthInfoOptions {
|
||||
authinfo := &config.AuthInfoOptions{}
|
||||
authinfo.Username = "dummy_username"
|
||||
authinfo.Password = "dummy_password"
|
||||
return authinfo
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user