Skip to content

Commit

Permalink
Rename struct name
Browse files Browse the repository at this point in the history
Fix failing tests
  • Loading branch information
wongni committed Jun 14, 2022
1 parent f6dd751 commit 948c64a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/executables/cmk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
)

var execConfig = decoder.CloudStackExecConfig{
Instances: []decoder.CloudStackInstanceConfig{
Instances: []decoder.CloudStackProfileConfig{
{
ApiKey: "test",
SecretKey: "test",
Expand Down
3 changes: 1 addition & 2 deletions pkg/providers/cloudstack/cloudstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ const (
eksd119Release = "kubernetes-1-19-eks-4"

/* Generated from ini file (like the following) then b64 encoded: `cat fake-cloud-config.ini | base64 | tr -d '\n'`
[Global]
verify-ssl = false
[Instance1]
api-key = test-key1
secret-key = test-secret1
api-url = http://127.16.0.1:8080/client/api
*/
expectedCloudStackCloudConfig = "W0dsb2JhbF0KdmVyaWZ5LXNzbCA9IGZhbHNlCgpbSW5zdGFuY2UxXQphcGkta2V5ID0gdGVzdC1rZXkxCnNlY3JldC1rZXkgPSB0ZXN0LXNlY3JldDEKYXBpLXVybCA9IGh0dHA6Ly8xMjcuMTYuMC4xOjgwODAvY2xpZW50L2FwaQ=="
expectedCloudStackCloudConfig = "dmVyaWZ5LXNzbCA9IGZhbHNlCgpbSW5zdGFuY2UxXQphcGkta2V5ID0gdGVzdC1rZXkxCnNlY3JldC1rZXkgPSB0ZXN0LXNlY3JldDEKYXBpLXVybCA9IGh0dHA6Ly8xMjcuMTYuMC4xOjgwODAvY2xpZW50L2FwaQo="
)

func givenClusterConfig(t *testing.T, fileName string) *v1alpha1.Cluster {
Expand Down
11 changes: 5 additions & 6 deletions pkg/providers/cloudstack/decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const (
EksacloudStackCloudConfigB64SecretKey = "EKSA_CLOUDSTACK_B64ENCODED_SECRET"
CloudStackCloudConfigB64SecretKey = "CLOUDSTACK_B64ENCODED_SECRET"
EksaCloudStackHostPathToMount = "EKSA_CLOUDSTACK_HOST_PATHS_TO_MOUNT"
defaultSectionName = "DEFAULT"
)

// ParseCloudStackSecret parses the input b64 string into the ini object to extract out the api key, secret key, and url
Expand All @@ -32,10 +31,10 @@ func ParseCloudStackSecret() (*CloudStackExecConfig, error) {
}

verifySslValue := "true"
cloudstackInstances := []CloudStackInstanceConfig{}
cloudstackInstances := []CloudStackProfileConfig{}
sections := cfg.Sections()
for _, section := range sections {
if section.Name() == defaultSectionName {
if section.Name() == "DEFAULT" {
verifySsl, err := section.GetKey("verify-ssl")
if err == nil {
verifySslValue = verifySsl.Value()
Expand All @@ -58,7 +57,7 @@ func ParseCloudStackSecret() (*CloudStackExecConfig, error) {
if err != nil {
return nil, fmt.Errorf("failed to extract value of 'api-url' from %s: %v", EksacloudStackCloudConfigB64SecretKey, err)
}
cloudstackInstances = append(cloudstackInstances, CloudStackInstanceConfig{
cloudstackInstances = append(cloudstackInstances, CloudStackProfileConfig{
Name: section.Name(),
ApiKey: apiKey.Value(),
SecretKey: secretKey.Value(),
Expand All @@ -77,12 +76,12 @@ func ParseCloudStackSecret() (*CloudStackExecConfig, error) {
}

type CloudStackExecConfig struct {
Instances []CloudStackInstanceConfig
Instances []CloudStackProfileConfig
VerifySsl string
Timeout string
}

type CloudStackInstanceConfig struct {
type CloudStackProfileConfig struct {
Name string
ApiKey string
SecretKey string
Expand Down
8 changes: 4 additions & 4 deletions pkg/providers/cloudstack/decoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestCloudStackConfigDecoder(t *testing.T) {
configFile: "../testdata/cloudstack_config_valid.ini",
wantErr: false,
wantConfig: &decoder.CloudStackExecConfig{
Instances: []decoder.CloudStackInstanceConfig{
Instances: []decoder.CloudStackProfileConfig{
{
Name: "Instance1",
ApiKey: "test-key1",
Expand All @@ -57,7 +57,7 @@ func TestCloudStackConfigDecoder(t *testing.T) {
configFile: "../testdata/cloudstack_config_multiple_instances.ini",
wantErr: false,
wantConfig: &decoder.CloudStackExecConfig{
Instances: []decoder.CloudStackInstanceConfig{
Instances: []decoder.CloudStackProfileConfig{
{
Name: "Instance1",
ApiKey: "test-key1",
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestCloudStackConfigDecoder(t *testing.T) {
configFile: "../testdata/cloudstack_config_missing_verifyssl.ini",
wantErr: false,
wantConfig: &decoder.CloudStackExecConfig{
Instances: []decoder.CloudStackInstanceConfig{
Instances: []decoder.CloudStackProfileConfig{
{
Name: "Instance1",
ApiKey: "test-key1",
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestCloudStackConfigDecoder(t *testing.T) {
g := NewWithT(t)
configString := test.ReadFile(t, tc.configFile)
encodedConfig := base64.StdEncoding.EncodeToString([]byte(configString))
os.Setenv(decoder.EksacloudStackCloudConfigB64SecretKey, encodedConfig)
tt.Setenv(decoder.EksacloudStackCloudConfigB64SecretKey, encodedConfig)

gotConfig, err := decoder.ParseCloudStackSecret()
if tc.wantErr {
Expand Down

0 comments on commit 948c64a

Please sign in to comment.