airshipctl/cmd/config/set_management_configuration_test.go
Drew Walters 383cffed4d Add set-management-configuration command
This change adds a set-management-configuration command that allows the
user, typically CI, to change management configuration settings
imperatively.

Change-Id: I7a106a46f57fef0ea2a8c5dd8c8786d8a103305c
Signed-off-by: Drew Walters <andrew.walters@att.com>
2020-05-28 21:59:44 +00:00

167 lines
5.2 KiB
Go

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cmd "opendev.org/airship/airshipctl/cmd/config"
"opendev.org/airship/airshipctl/pkg/config"
"opendev.org/airship/airshipctl/pkg/environment"
redfishdell "opendev.org/airship/airshipctl/pkg/remote/redfish/vendors/dell"
"opendev.org/airship/airshipctl/testutil"
)
func TestConfigSetManagementConfigurationCmd(t *testing.T) {
conf, cleanup := testutil.InitConfig(t)
defer cleanup(t)
settings := &environment.AirshipCTLSettings{
Config: conf,
}
cmdTests := []*testutil.CmdTest{
{
Name: "config-cmd-set-management-config-with-help",
CmdLine: "--help",
Cmd: cmd.NewSetManagementConfigCommand(nil),
},
{
Name: "config-cmd-set-management-config-no-args",
CmdLine: "",
Cmd: cmd.NewSetManagementConfigCommand(nil),
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 0),
},
{
Name: "config-cmd-set-management-config-excess-args",
CmdLine: "arg1 arg2",
Cmd: cmd.NewSetManagementConfigCommand(nil),
Error: fmt.Errorf("accepts %d arg(s), received %d", 1, 2),
},
{
Name: "config-cmd-set-management-config-not-found",
CmdLine: fmt.Sprintf("%s-test", config.AirshipDefaultContext),
Cmd: cmd.NewSetManagementConfigCommand(settings),
Error: config.ErrManagementConfigurationNotFound{
Name: fmt.Sprintf("%s-test", config.AirshipDefaultContext),
},
},
}
for _, tt := range cmdTests {
testutil.RunTest(t, tt)
}
}
func TestConfigSetManagementConfigurationInsecure(t *testing.T) {
conf, cleanup := testutil.InitConfig(t)
defer cleanup(t)
settings := &environment.AirshipCTLSettings{
Config: conf,
}
require.False(t, settings.Config.ManagementConfiguration[config.AirshipDefaultContext].Insecure)
testutil.RunTest(t, &testutil.CmdTest{
Name: "config-cmd-set-management-config-change-insecure",
CmdLine: fmt.Sprintf("%s --insecure=true", config.AirshipDefaultContext),
Cmd: cmd.NewSetManagementConfigCommand(settings),
})
assert.True(t, settings.Config.ManagementConfiguration[config.AirshipDefaultContext].Insecure)
}
func TestConfigSetManagementConfigurationType(t *testing.T) {
conf, cleanup := testutil.InitConfig(t)
defer cleanup(t)
settings := &environment.AirshipCTLSettings{
Config: conf,
}
require.NotEqual(t, redfishdell.ClientType,
settings.Config.ManagementConfiguration[config.AirshipDefaultContext].Type)
cmdTests := []*testutil.CmdTest{
{
Name: "config-cmd-set-management-config-unknown-type",
CmdLine: fmt.Sprintf("%s --management-type=foo", config.AirshipDefaultContext),
Cmd: cmd.NewSetManagementConfigCommand(settings),
Error: config.ErrUnknownManagementType{Type: "foo"},
},
{
Name: "config-cmd-set-management-config-change-type",
CmdLine: fmt.Sprintf("%s --management-type=%s", config.AirshipDefaultContext,
redfishdell.ClientType),
Cmd: cmd.NewSetManagementConfigCommand(settings),
},
}
for _, tt := range cmdTests {
testutil.RunTest(t, tt)
}
assert.Equal(t, redfishdell.ClientType,
settings.Config.ManagementConfiguration[config.AirshipDefaultContext].Type)
}
func TestConfigSetManagementConfigurationUseProxy(t *testing.T) {
conf, cleanup := testutil.InitConfig(t)
defer cleanup(t)
settings := &environment.AirshipCTLSettings{
Config: conf,
}
require.False(t, settings.Config.ManagementConfiguration[config.AirshipDefaultContext].UseProxy)
testutil.RunTest(t, &testutil.CmdTest{
Name: "config-cmd-set-management-config-change-use-proxy",
CmdLine: fmt.Sprintf("%s --use-proxy=true", config.AirshipDefaultContext),
Cmd: cmd.NewSetManagementConfigCommand(settings),
})
assert.True(t, settings.Config.ManagementConfiguration[config.AirshipDefaultContext].UseProxy)
}
func TestConfigSetManagementConfigurationMultipleOptions(t *testing.T) {
conf, cleanup := testutil.InitConfig(t)
defer cleanup(t)
settings := &environment.AirshipCTLSettings{
Config: conf,
}
require.NotEqual(t, redfishdell.ClientType,
settings.Config.ManagementConfiguration[config.AirshipDefaultContext].Type)
require.False(t, settings.Config.ManagementConfiguration[config.AirshipDefaultContext].UseProxy)
testutil.RunTest(t, &testutil.CmdTest{
Name: "config-cmd-set-management-config-change-type",
CmdLine: fmt.Sprintf("%s --management-type=%s --use-proxy=true", config.AirshipDefaultContext,
redfishdell.ClientType),
Cmd: cmd.NewSetManagementConfigCommand(settings),
})
assert.Equal(t, redfishdell.ClientType,
settings.Config.ManagementConfiguration[config.AirshipDefaultContext].Type)
assert.True(t, settings.Config.ManagementConfiguration[config.AirshipDefaultContext].UseProxy)
}