Skip to content

Commit

Permalink
Fix tests, admission-controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelpereyma committed Nov 15, 2021
1 parent 7f4249f commit 2e278fc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
4 changes: 4 additions & 0 deletions selectel/data_source_selectel_mks_kube_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func dataSourceMKSFeatureGatesV1() *schema.Resource {
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
},
},
},
Expand Down Expand Up @@ -183,6 +184,7 @@ func dataSourceMKSAdmissionControllersV1() *schema.Resource {
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
},
},
},
Expand Down Expand Up @@ -214,6 +216,8 @@ func dataSourceMKSAdmissionControllersV1Read(ctx context.Context, d *schema.Reso
return diag.FromErr(err)
}
d.SetId(checksum)

return nil
}

filterMap := filterSet.List()[0].(map[string]interface{})
Expand Down
25 changes: 15 additions & 10 deletions selectel/data_source_selectel_mks_kube_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ func TestAccMKSAvailableAdmissionControllersV1Basic(t *testing.T) {
var project projects.Project

projectName := acctest.RandomWithPrefix("tf-acc")
kubeVersion := "1.17.3"
kubeVersion := testAccMKSClusterV1GetDefaultKubeVersion(t)
kubeVersionMinor, err := kubeVersionTrimToMinor(kubeVersion)
if err != nil {
t.Fatal(err)
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccSelectelPreCheck(t) },
Expand All @@ -79,7 +83,7 @@ func TestAccMKSAvailableAdmissionControllersV1Basic(t *testing.T) {
Config: testKubeOptionsV1BasicConfig(projectName, dataSourceAdmissionControllers, kubeVersion),
Check: resource.ComposeTestCheckFunc(
testAccCheckVPCV2ProjectExists("selectel_vpc_project_v2.project_tf_acc_test_1", &project),
resource.TestCheckResourceAttr("data."+dataSourceAdmissionControllers+".dt", "admission_controllers.0.kube_version_minor", kubeVersion),
resource.TestCheckResourceAttr("data."+dataSourceAdmissionControllers+".dt", "admission_controllers.0.kube_version_minor", kubeVersionMinor),
testAdmissionControllersIsNotEmpty("data."+dataSourceAdmissionControllers+".dt"),
),
},
Expand Down Expand Up @@ -115,7 +119,8 @@ func testFeatureGatesIsNotEmpty(n string) resource.TestCheckFunc {
return fmt.Errorf("not found: %s", n)
}

availableFeatureGates, ok := rs.Primary.Attributes["feature_gates.0.names"]
availableFeatureGates, ok := rs.Primary.Attributes["feature_gates.#"]
//availableFeatureGates, ok := rs.Primary.Attributes["feature_gates.0.names.0"]
if !ok {
return fmt.Errorf("attribute 'feature_gates' is not found")
}
Expand All @@ -134,19 +139,19 @@ func testFeatureGatesNoFilter(n string) resource.TestCheckFunc {
return fmt.Errorf("not found: %s", n)
}

availableFeatureGates, ok := rs.Primary.Attributes["feature_gates.0.names"]
availableFeatureGates, ok := rs.Primary.Attributes["feature_gates.0.names.#"]
if !ok {
return fmt.Errorf("attribute 'feature_gates' is not found")
}
if availableFeatureGates == "" {
return fmt.Errorf("names is not set at 'feature_gates'")
}

fgLen, err := strconv.Atoi(rs.Primary.Attributes["feature_gates.#"])
fgCount, err := strconv.Atoi(availableFeatureGates)
if err != nil {
return fmt.Errorf("failed to get len of 'feature_gates': %w", err)
}
if fgLen <= 1 {
if fgCount <= 1 {
return fmt.Errorf("received only one or less item in 'feature_gates'")
}

Expand All @@ -161,7 +166,7 @@ func testAdmissionControllersIsNotEmpty(n string) resource.TestCheckFunc {
return fmt.Errorf("not found: %s", n)
}

availableAdmissionControllers, ok := rs.Primary.Attributes["admission_controllers.0.names"]
availableAdmissionControllers, ok := rs.Primary.Attributes["admission_controllers.#"]
if !ok {
return fmt.Errorf("attribute 'admission_controllers' is not found")
}
Expand All @@ -180,19 +185,19 @@ func testAdmissionControllersNoFilter(n string) resource.TestCheckFunc {
return fmt.Errorf("not found: %s", n)
}

availableAdmissionControllers, ok := rs.Primary.Attributes["admission_controllers.0.names"]
availableAdmissionControllers, ok := rs.Primary.Attributes["admission_controllers.0.names.#"]
if !ok {
return fmt.Errorf("attribute 'admission_controllers' is not found")
}
if availableAdmissionControllers == "" {
return fmt.Errorf("names is not set at 'admission_controllers'")
}

fgLen, err := strconv.Atoi(rs.Primary.Attributes["admission_controllers.#"])
acCount, err := strconv.Atoi(availableAdmissionControllers)
if err != nil {
return fmt.Errorf("failed to get len of 'admission_controllers': %w", err)
}
if fgLen <= 1 {
if acCount <= 1 {
return fmt.Errorf("received only one or less item in 'admission_controllers'")
}

Expand Down
8 changes: 4 additions & 4 deletions selectel/mks.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,10 @@ func flattenFeatureGatesFromSlice(kubeVersion string, featureGates []string) []i

func flattenAdmissionControllers(views []*kubeoptions.View) []interface{} {
availableAdmissionControllers := make([]interface{}, len(views))
for i, fg := range views {
for i, ac := range views {
availableAdmissionControllers[i] = map[string]interface{}{
"kube_version_minor": fg.KubeVersion,
"names": strings.Join(fg.Names, ","),
"kube_version_minor": ac.KubeVersion,
"names": ac.Names,
}
}

Expand All @@ -493,7 +493,7 @@ func flattenAdmissionControllersFromSlice(kubeVersion string, admissionControlle
availableAdmissionControllers := make([]interface{}, 1)
availableAdmissionControllers[0] = map[string]interface{}{
"kube_version_minor": kubeVersion,
"names": strings.Join(admissionControllers, ","),
"names": admissionControllers,
}

return availableAdmissionControllers
Expand Down

0 comments on commit 2e278fc

Please sign in to comment.