From 6614cefcabb18c964ef6bce8a6fedc25df433c60 Mon Sep 17 00:00:00 2001 From: Vitaly Antonenko Date: Mon, 7 Oct 2024 12:44:08 +0300 Subject: [PATCH] test: move ACC test to microk8s cloud --- .github/workflows/test_integration.yml | 3 ++ internal/juju/kubernetesClouds.go | 2 +- internal/juju/kubernetesClouds_test.go | 17 ++++----- .../resource_kubernetes_cloud_test.go | 37 +++++++++++++++---- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test_integration.yml b/.github/workflows/test_integration.yml index 59ef5fd8..5f2e9e73 100644 --- a/.github/workflows/test_integration.yml +++ b/.github/workflows/test_integration.yml @@ -88,6 +88,9 @@ jobs: echo "EOF" >> $GITHUB_ENV echo "TEST_MANAGEMENT_BR=10.150.40.0/24" >> $GITHUB_ENV echo "TEST_PUBLIC_BR=10.170.80.0/24" >> $GITHUB_ENV + - name: "Set additional enviroment for microk8s" + if: ${{ matrix.action-operator.cloud == 'microk8s' }} + run: | echo "MICROK8S_CONFIG<<-EOT" >> $GITHUB_ENV microk8s.config view >> $GITHUB_ENV echo "EOT" >> $GITHUB_ENV diff --git a/internal/juju/kubernetesClouds.go b/internal/juju/kubernetesClouds.go index e68d6b64..8cb21501 100644 --- a/internal/juju/kubernetesClouds.go +++ b/internal/juju/kubernetesClouds.go @@ -4,8 +4,8 @@ package juju import ( + "crypto/rand" "encoding/hex" - "math/rand" "strings" jujuclock "github.com/juju/clock" diff --git a/internal/juju/kubernetesClouds_test.go b/internal/juju/kubernetesClouds_test.go index b3b243b0..c0696902 100644 --- a/internal/juju/kubernetesClouds_test.go +++ b/internal/juju/kubernetesClouds_test.go @@ -6,7 +6,6 @@ package juju import ( "testing" - "github.com/juju/juju/api" k8s "github.com/juju/juju/caas/kubernetes" k8scloud "github.com/juju/juju/caas/kubernetes/cloud" "github.com/stretchr/testify/suite" @@ -32,14 +31,14 @@ func (s *KubernetesCloudSuite) setupMocks(t *testing.T) *gomock.Controller { return ctlr } -func (s *KubernetesCloudSuite) getKubernetesCloudClient() kubernetesCloudsClient { - return kubernetesCloudsClient{ - SharedClient: s.JujuSuite.mockSharedClient, - getKubernetesCloudAPIClient: func(connection api.Connection) KubernetesCloudAPIClient { - return s.mockKubernetesCloudClient - }, - } -} +//func (s *KubernetesCloudSuite) getKubernetesCloudClient() kubernetesCloudsClient { +// return kubernetesCloudsClient{ +// SharedClient: s.JujuSuite.mockSharedClient, +// getKubernetesCloudAPIClient: func(connection api.Connection) KubernetesCloudAPIClient { +// return s.mockKubernetesCloudClient +// }, +// } +//} func getFakeCloudConfig() string { return ` diff --git a/internal/provider/resource_kubernetes_cloud_test.go b/internal/provider/resource_kubernetes_cloud_test.go index 57c6a79e..14c09601 100644 --- a/internal/provider/resource_kubernetes_cloud_test.go +++ b/internal/provider/resource_kubernetes_cloud_test.go @@ -10,29 +10,50 @@ import ( ) func TestAcc_ResourceKubernetesCloud(t *testing.T) { - if testingCloud != LXDCloudTesting { - t.Skip(t.Name() + " only runs with LXD") + if testingCloud != MicroK8sTesting { + t.Skip(t.Name() + " only runs with MicroK8s") } cloudName := acctest.RandomWithPrefix("tf-test-k8scloud") cloudConfig := os.Getenv("MICROK8S_CONFIG") - //Debug print plan - t.Logf("Plan: %s", testAccResourceKubernetesCloud(cloudName, cloudConfig)) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: frameworkProviderFactories, Steps: []resource.TestStep{ { - Config: testAccResourceKubernetesCloud(cloudName, cloudConfig), + Config: testAccResourceKubernetesCloudWithoutModel(cloudName, cloudConfig), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("juju_kubernetes_cloud."+cloudName, "name", cloudName)), + resource.TestCheckResourceAttr("juju_kubernetes_cloud."+cloudName, "name", cloudName), + ), }, }, }) } -func testAccResourceKubernetesCloud(cloudName string, config string) string { +//func testAccResourceKubernetesCloud(cloudName string, modelName string, config string) string { +// return internaltesting.GetStringFromTemplateWithData( +// "testAccResourceSecret", +// ` +//resource "juju_kubernetes_cloud" {{.CloudName}} { +// name = "{{.CloudName}}" +// kubernetes_config = {{.Config}} +//} +// +//resource "juju_model" {{.ModelName}} { +// name = "{{.ModelName}}" +// credential = juju_kubernetes_cloud.{{.CloudName}}.credential +// cloud { +// name = juju_kubernetes_cloud.{{.CloudName}}.name +// } +//} +//`, internaltesting.TemplateData{ +// "CloudName": cloudName, +// "ModelName": modelName, +// "Config": config, +// }) +//} + +func testAccResourceKubernetesCloudWithoutModel(cloudName string, config string) string { return internaltesting.GetStringFromTemplateWithData( "testAccResourceSecret", `