Skip to content

Commit

Permalink
MKS V1: fix maintenance window start time in tests (#147)
Browse files Browse the repository at this point in the history
Add testAccMKSClusterV1GetMaintenanceWindowStart function.
Update tests.
  • Loading branch information
kolsean authored Jan 26, 2021
1 parent fc6feb2 commit f537578
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 37 deletions.
7 changes: 5 additions & 2 deletions selectel/import_selectel_mks_cluster_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package selectel

import (
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -12,14 +13,15 @@ func TestAccMKSClusterV1ImportBasic(t *testing.T) {
projectName := acctest.RandomWithPrefix("tf-acc")
clusterName := acctest.RandomWithPrefix("tf-acc-cl")
kubeVersion := testAccMKSClusterV1GetDefaultKubeVersion(t)
maintenanceWindowStart := testAccMKSClusterV1GetMaintenanceWindowStart(12 * time.Hour)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccSelectelPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckVPCV2ProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccMKSClusterV1Basic(projectName, clusterName, kubeVersion),
Config: testAccMKSClusterV1Basic(projectName, clusterName, kubeVersion, maintenanceWindowStart),
Check: testAccCheckSelectelImportEnv(resourceName),
},
{
Expand All @@ -36,14 +38,15 @@ func TestAccMKSClusterV1ImportZonal(t *testing.T) {
projectName := acctest.RandomWithPrefix("tf-acc")
clusterName := acctest.RandomWithPrefix("tf-acc-cl")
kubeVersion := testAccMKSClusterV1GetDefaultKubeVersion(t)
maintenanceWindowStart := testAccMKSClusterV1GetMaintenanceWindowStart(12 * time.Hour)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccSelectelPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckVPCV2ProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccMKSClusterV1Zonal(projectName, clusterName, kubeVersion),
Config: testAccMKSClusterV1Zonal(projectName, clusterName, kubeVersion, maintenanceWindowStart),
Check: testAccCheckSelectelImportEnv(resourceName),
},
{
Expand Down
4 changes: 3 additions & 1 deletion selectel/import_selectel_mks_nodegroup_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package selectel

import (
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -12,14 +13,15 @@ func TestAccMKSNodegroupV1ImportBasic(t *testing.T) {
projectName := acctest.RandomWithPrefix("tf-acc")
clusterName := acctest.RandomWithPrefix("tf-acc-cl")
kubeVersion := testAccMKSClusterV1GetDefaultKubeVersion(t)
maintenanceWindowStart := testAccMKSClusterV1GetMaintenanceWindowStart(12 * time.Hour)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccSelectelPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckVPCV2ProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccMKSNodegroupV1Basic(projectName, clusterName, kubeVersion),
Config: testAccMKSNodegroupV1Basic(projectName, clusterName, kubeVersion, maintenanceWindowStart),
Check: testAccCheckSelectelImportEnv(resourceName),
},
{
Expand Down
47 changes: 27 additions & 20 deletions selectel/resource_selectel_mks_cluster_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -25,14 +26,16 @@ func TestAccMKSClusterV1Basic(t *testing.T) {
projectName := acctest.RandomWithPrefix("tf-acc")
clusterName := acctest.RandomWithPrefix("tf-acc-cl")
kubeVersion := testAccMKSClusterV1GetDefaultKubeVersion(t)
maintenanceWindowStart := testAccMKSClusterV1GetMaintenanceWindowStart(12 * time.Hour)
maintenanceWindowStartUpdated := testAccMKSClusterV1GetMaintenanceWindowStart(14 * time.Hour)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccSelectelPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckVPCV2ProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccMKSClusterV1Basic(projectName, clusterName, kubeVersion),
Config: testAccMKSClusterV1Basic(projectName, clusterName, kubeVersion, maintenanceWindowStart),
Check: resource.ComposeTestCheckFunc(
testAccCheckVPCV2ProjectExists("selectel_vpc_project_v2.project_tf_acc_test_1", &project),
testAccCheckMKSClusterV1Exists("selectel_mks_cluster_v1.cluster_tf_acc_test_1", &mksCluster),
Expand All @@ -41,22 +44,20 @@ func TestAccMKSClusterV1Basic(t *testing.T) {
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "region", "ru-3"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_autorepair", "true"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_patch_version_auto_upgrade", "true"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_start", "01:00:00"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_end", "03:00:00"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_start", maintenanceWindowStart),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "status", "ACTIVE"),
),
},
{
Config: testAccMKSClusterV1Update(projectName, clusterName, kubeVersion),
Config: testAccMKSClusterV1Update(projectName, clusterName, kubeVersion, maintenanceWindowStartUpdated),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "name", clusterName),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "kube_version", kubeVersion),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "region", "ru-3"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_autorepair", "false"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_patch_version_auto_upgrade", "false"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_pod_security_policy", "false"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_start", "02:00:00"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_end", "04:00:00"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_start", maintenanceWindowStartUpdated),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "status", "ACTIVE"),
),
},
Expand All @@ -73,14 +74,15 @@ func TestAccMKSClusterV1Zonal(t *testing.T) {
projectName := acctest.RandomWithPrefix("tf-acc")
clusterName := acctest.RandomWithPrefix("tf-acc-cl")
kubeVersion := testAccMKSClusterV1GetDefaultKubeVersion(t)
maintenanceWindowStart := testAccMKSClusterV1GetMaintenanceWindowStart(12 * time.Hour)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccSelectelPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckVPCV2ProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccMKSClusterV1Zonal(projectName, clusterName, kubeVersion),
Config: testAccMKSClusterV1Zonal(projectName, clusterName, kubeVersion, maintenanceWindowStart),
Check: resource.ComposeTestCheckFunc(
testAccCheckVPCV2ProjectExists("selectel_vpc_project_v2.project_tf_acc_test_1", &project),
testAccCheckMKSClusterV1Exists("selectel_mks_cluster_v1.cluster_tf_acc_test_1", &mksCluster),
Expand All @@ -90,15 +92,18 @@ func TestAccMKSClusterV1Zonal(t *testing.T) {
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_autorepair", "true"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_patch_version_auto_upgrade", "false"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "zonal", "true"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_start", "01:00:00"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_end", "03:00:00"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_start", maintenanceWindowStart),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "status", "ACTIVE"),
),
},
},
})
}

func testAccMKSClusterV1GetMaintenanceWindowStart(delay time.Duration) string {
return time.Now().UTC().Add(delay).Format("15:04:00")
}

func testAccMKSClusterV1GetDefaultKubeVersion(t *testing.T) string {
var (
kubeVersion string
Expand Down Expand Up @@ -214,22 +219,23 @@ func testAccCheckMKSClusterV1Exists(n string, mksCluster *cluster.View) resource
}
}

func testAccMKSClusterV1Basic(projectName, clusterName, kubeVersion string) string {
func testAccMKSClusterV1Basic(projectName, clusterName, kubeVersion, maintenanceWindowStart string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
resource "selectel_mks_cluster_v1" "cluster_tf_acc_test_1" {
name = "%s"
kube_version = "%s"
project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}"
region = "ru-3"
}`, projectName, clusterName, kubeVersion)
name = "%s"
kube_version = "%s"
project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}"
region = "ru-3"
maintenance_window_start = "%s"
}`, projectName, clusterName, kubeVersion, maintenanceWindowStart)
}

func testAccMKSClusterV1Update(projectName, clusterName, kubeVersion string) string {
func testAccMKSClusterV1Update(projectName, clusterName, kubeVersion, maintenanceWindowStart string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
Expand All @@ -241,14 +247,14 @@ resource "selectel_mks_cluster_v1" "cluster_tf_acc_test_1" {
kube_version = "%s"
project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}"
region = "ru-3"
maintenance_window_start = "02:00:00"
maintenance_window_start = "%s"
enable_autorepair = false
enable_patch_version_auto_upgrade = false
enable_pod_security_policy = false
}`, projectName, clusterName, kubeVersion)
}`, projectName, clusterName, kubeVersion, maintenanceWindowStart)
}

func testAccMKSClusterV1Zonal(projectName, clusterName, kubeVersion string) string {
func testAccMKSClusterV1Zonal(projectName, clusterName, kubeVersion, maintenanceWindowStart string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
Expand All @@ -260,7 +266,8 @@ func testAccMKSClusterV1Zonal(projectName, clusterName, kubeVersion string) stri
kube_version = "%s"
project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}"
region = "ru-3"
maintenance_window_start = "%s"
enable_patch_version_auto_upgrade = false
zonal = true
}`, projectName, clusterName, kubeVersion)
}`, projectName, clusterName, kubeVersion, maintenanceWindowStart)
}
32 changes: 18 additions & 14 deletions selectel/resource_selectel_mks_nodegroup_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -24,14 +25,15 @@ func TestAccMKSNodegroupV1Basic(t *testing.T) {
projectName := acctest.RandomWithPrefix("tf-acc")
clusterName := acctest.RandomWithPrefix("tf-acc-cl")
kubeVersion := testAccMKSClusterV1GetDefaultKubeVersion(t)
maintenanceWindowStart := testAccMKSClusterV1GetMaintenanceWindowStart(12 * time.Hour)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccSelectelPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckVPCV2ProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccMKSNodegroupV1Basic(projectName, clusterName, kubeVersion),
Config: testAccMKSNodegroupV1Basic(projectName, clusterName, kubeVersion, maintenanceWindowStart),
Check: resource.ComposeTestCheckFunc(
testAccCheckVPCV2ProjectExists("selectel_vpc_project_v2.project_tf_acc_test_1", &project),
testAccCheckMKSNodegroupV1Exists("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", &mksNodegroup),
Expand Down Expand Up @@ -59,7 +61,7 @@ func TestAccMKSNodegroupV1Basic(t *testing.T) {
),
},
{
Config: testAccMKSNodegroupV1Update(projectName, clusterName, kubeVersion),
Config: testAccMKSNodegroupV1Update(projectName, clusterName, kubeVersion, maintenanceWindowStart),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "availability_zone", "ru-3a"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "nodes_count", "2"),
Expand Down Expand Up @@ -137,18 +139,19 @@ func testAccCheckMKSNodegroupV1Exists(n string, mksNodegroup *nodegroup.View) re
}
}

func testAccMKSNodegroupV1Basic(projectName, clusterName, kubeVersion string) string {
func testAccMKSNodegroupV1Basic(projectName, clusterName, kubeVersion, maintenanceWindowStart string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
resource "selectel_mks_cluster_v1" "cluster_tf_acc_test_1" {
name = "%s"
kube_version = "%s"
project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}"
region = "ru-3"
name = "%s"
kube_version = "%s"
project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}"
region = "ru-3"
maintenance_window_start = "%s"
}
resource "selectel_mks_nodegroup_v1" "nodegroup_tf_acc_test_1" {
Expand Down Expand Up @@ -181,21 +184,22 @@ resource "selectel_mks_nodegroup_v1" "nodegroup_tf_acc_test_1" {
value = "test-value-2"
effect = "PreferNoSchedule"
}
}`, projectName, clusterName, kubeVersion)
}`, projectName, clusterName, kubeVersion, maintenanceWindowStart)
}

func testAccMKSNodegroupV1Update(projectName, clusterName, kubeVersion string) string {
func testAccMKSNodegroupV1Update(projectName, clusterName, kubeVersion, maintenanceWindowStart string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
resource "selectel_mks_cluster_v1" "cluster_tf_acc_test_1" {
name = "%s"
kube_version = "%s"
project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}"
region = "ru-3"
name = "%s"
kube_version = "%s"
project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}"
region = "ru-3"
maintenance_window_start = "%s"
}
resource "selectel_mks_nodegroup_v1" "nodegroup_tf_acc_test_1" {
Expand Down Expand Up @@ -227,5 +231,5 @@ resource "selectel_mks_nodegroup_v1" "nodegroup_tf_acc_test_1" {
value = "test-value-2"
effect = "PreferNoSchedule"
}
}`, projectName, clusterName, kubeVersion)
}`, projectName, clusterName, kubeVersion, maintenanceWindowStart)
}

0 comments on commit f537578

Please sign in to comment.