Skip to content

Commit

Permalink
fix: acceptance test for kubernetes cloud resource
Browse files Browse the repository at this point in the history
  • Loading branch information
anvial committed Oct 11, 2024
1 parent a5c04d1 commit 94da83c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ jobs:
if: ${{ matrix.action-operator.cloud == 'lxd' }}
# language=bash
run: |
sudo microk8s.config > /home/$USER/microk8s-config.yaml
sudo microk8s.config view > /home/$USER/microk8s-config.yaml
{
echo 'MICROK8S_CONFIG<<EOF'
sudo microk8s.config view
echo EOF
} >> "$GITHUB_ENV"
- run: go mod download
- env:
TF_ACC: "1"
Expand Down
34 changes: 14 additions & 20 deletions internal/provider/resource_kubernetes_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,47 @@ import (
)

func TestAcc_ResourceKubernetesCloud(t *testing.T) {
// TODO: Skip this ACC test until we have a way to run correctly with kubernetes_config
// attribute set to a correct k8s config in github action environment
t.Skip(t.Name() + " is skipped until we have a way to run correctly with kubernetes_config attribute set to a correct k8s config in github action environment")

if testingCloud != LXDCloudTesting {
t.Skip(t.Name() + " only runs with LXD")
}
cloudName := acctest.RandomWithPrefix("tf-test-k8scloud")
modelName := acctest.RandomWithPrefix("tf-test-model")
cloudConfig := os.Getenv("MICROK8S_CONFIG")
cloudName := acctest.RandomWithPrefix("test-k8scloud")
modelName := "test-model"
userName := os.Getenv("USER")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: frameworkProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccResourceKubernetesCloud(cloudName, modelName, cloudConfig),
Config: testAccResourceKubernetesCloud(cloudName, modelName, userName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("juju_kubernetes_cloud."+cloudName, "name", cloudName),
resource.TestCheckResourceAttr("juju_kubernetes_cloud."+cloudName, "model", modelName),
resource.TestCheckResourceAttr("juju_kubernetes_cloud.test-k8scloud", "name", cloudName),
resource.TestCheckResourceAttr("juju_model.test-model", "name", modelName),
),
},
},
})
}

func testAccResourceKubernetesCloud(cloudName string, modelName string, config string) string {
func testAccResourceKubernetesCloud(cloudName string, modelName string, userName string) string {
return internaltesting.GetStringFromTemplateWithData(
"testAccResourceSecret",
"testAccResourceKubernetesCloud",
`
resource "juju_kubernetes_cloud" "tf-test-k8scloud" {
resource "juju_kubernetes_cloud" "test-k8scloud" {
name = "{{.CloudName}}"
kubernetes_config = file("~/microk8s-config.yaml")
kubernetes_config = file("/home/{{.UserName}}/microk8s-config.yaml")
}
resource "juju_model" {{.ModelName}} {
resource "juju_model" "test-model" {
name = "{{.ModelName}}"
credential = juju_kubernetes_cloud.tf-test-k8scloud.credential
credential = juju_kubernetes_cloud.test-k8scloud.credential
cloud {
name = juju_kubernetes_cloud.tf-test-k8scloud.name
name = juju_kubernetes_cloud.test-k8scloud.name
}
}
`, internaltesting.TemplateData{
"CloudName": cloudName,
"ModelName": modelName,
"Config": config,
"UserName": userName,
})
}

0 comments on commit 94da83c

Please sign in to comment.