Skip to content

Commit

Permalink
test: move ACC test to microk8s cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
anvial committed Oct 7, 2024
1 parent e0e45f9 commit 6614cef
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/juju/kubernetesClouds.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package juju

import (
"crypto/rand"
"encoding/hex"
"math/rand"
"strings"

jujuclock "github.com/juju/clock"
Expand Down
17 changes: 8 additions & 9 deletions internal/juju/kubernetesClouds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 `
Expand Down
37 changes: 29 additions & 8 deletions internal/provider/resource_kubernetes_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
`
Expand Down

0 comments on commit 6614cef

Please sign in to comment.