-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7028348
commit 2f0a16c
Showing
2 changed files
with
108 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2023 Canonical Ltd. | ||
// Licensed under the Apache License, Version 2.0, see LICENCE file for details. | ||
|
||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAcc_DataSourceApplication_Edge(t *testing.T) { | ||
if testingCloud != LXDCloudTesting { | ||
t.Skip(t.Name() + " only runs with LXD") | ||
} | ||
modelName := acctest.RandomWithPrefix("tf-datasource-application-test-model") | ||
applicationName := acctest.RandomWithPrefix("tf-datasource-application-test-name") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: frameworkProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceApplication(modelName, applicationName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.juju_application.this", "model", modelName), | ||
resource.TestCheckResourceAttr("data.juju_application.this", "name", applicationName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAcc_DataSourceApplication_UpgradeProvider(t *testing.T) { | ||
if testingCloud != LXDCloudTesting { | ||
t.Skip(t.Name() + " only runs with LXD") | ||
} | ||
modelName := acctest.RandomWithPrefix("tf-datasource-application-test-model") | ||
applicationName := acctest.RandomWithPrefix("tf-datasource-application-test-name") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
|
||
Steps: []resource.TestStep{ | ||
{ | ||
ExternalProviders: map[string]resource.ExternalProvider{ | ||
"juju": { | ||
VersionConstraint: TestProviderStableVersion, | ||
Source: "juju/juju", | ||
}, | ||
}, | ||
Config: testAccDataSourceApplication(modelName, applicationName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.juju_application.this", "model", modelName), | ||
resource.TestCheckResourceAttr("data.juju_application.this", "name", applicationName), | ||
), | ||
}, | ||
{ | ||
ProtoV6ProviderFactories: frameworkProviderFactories, | ||
Config: testAccDataSourceApplication(modelName, applicationName), | ||
PlanOnly: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceApplication(modelName, applicationName string) string { | ||
return fmt.Sprintf(` | ||
resource "juju_model" "model" { | ||
name = %q | ||
} | ||
resource "juju_application" "this" { | ||
name = %q | ||
model = juju_model.model.name | ||
units = 2 | ||
charm { | ||
name = "ubuntu" | ||
channel = "edge" | ||
revision = 24 | ||
series = "trusty" | ||
} | ||
} | ||
data "juju_application" "this" { | ||
model = juju_model.model.name | ||
name = juju_application.this.name | ||
}`, modelName, applicationName) | ||
} |