Skip to content

Commit 78a3901

Browse files
add basic test
1 parent d01d635 commit 78a3901

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

codefresh/resource_account_gitops_settings.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ func resourceAccountGitopsSettings() *schema.Resource {
1616
Read: resourceAccountGitopsSettingsRead,
1717
Create: resourceAccountGitopsSettingsUpdate,
1818
Update: resourceAccountGitopsSettingsUpdate,
19+
Importer: &schema.ResourceImporter{
20+
State: schema.ImportStatePassthrough,
21+
},
1922
// Delete not implemenented as gitops settings cannot be removed, only updated
2023
Delete: resourceAccountGitopsSettingsDelete,
2124
Schema: map[string]*schema.Schema{
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package codefresh
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient"
8+
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/internal/gitops"
9+
//"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
12+
)
13+
14+
func TestAccCodefreshAccountGitopsSettings_basic(t *testing.T) {
15+
resourceName := "codefresh_account_gitops_settings.test"
16+
17+
expectedDefaultApiURLGithub, _ := gitops.GetDefaultAPIUrlForProvider(gitops.GitProviderGitHub)
18+
//expectedDefaultApiURLGithub := "https://bnlah.com"
19+
20+
resource.Test(t, resource.TestCase{
21+
PreCheck: func() { testAccPreCheck(t) },
22+
Providers: testAccProviders,
23+
//CheckDestroy: testAccCheckCodefreshProjectDestroy,
24+
Steps: []resource.TestStep{
25+
{
26+
Config: testAccountGitopsSettingsGithubDefaultApiUrl("https://github.com/codefresh-io/terraform-provider-isc-test.git"),
27+
Check: resource.ComposeTestCheckFunc(
28+
testAccCheckGitopsSettings(resourceName, gitops.GitProviderGitHub, *expectedDefaultApiURLGithub, "https://github.com/codefresh-io/terraform-provider-isc-test.git"),
29+
resource.TestCheckResourceAttr(resourceName, "git_provider", gitops.GitProviderGitHub),
30+
),
31+
},
32+
{
33+
ResourceName: resourceName,
34+
ImportState: true,
35+
ImportStateVerify: true,
36+
},
37+
},
38+
})
39+
}
40+
41+
func testAccCheckGitopsSettings(resource string, gitProvider string, gitProviderApiUrl string, sharedConfigRepository string) resource.TestCheckFunc {
42+
return func(state *terraform.State) error {
43+
rs, ok := state.RootModule().Resources[resource]
44+
if !ok {
45+
return fmt.Errorf("Not found: %s", resource)
46+
}
47+
if rs.Primary.ID == "" {
48+
return fmt.Errorf("No Record ID is set")
49+
}
50+
51+
apiClient := testAccProvider.Meta().(*cfclient.Client)
52+
53+
accGitopsInfo, err := apiClient.GetActiveGitopsAccountInfo()
54+
55+
if err != nil {
56+
return fmt.Errorf("failed getting gitops settings with error %s", err)
57+
}
58+
59+
if accGitopsInfo.GitApiUrl != gitProviderApiUrl {
60+
return fmt.Errorf("expecting APIUrl to be %s but got %s", gitProviderApiUrl, accGitopsInfo.GitApiUrl)
61+
}
62+
63+
if accGitopsInfo.GitProvider != gitProvider {
64+
return fmt.Errorf("expecting provider to be %s but got %s", gitProvider, accGitopsInfo.GitProvider)
65+
}
66+
67+
if accGitopsInfo.SharedConfigRepo != sharedConfigRepository {
68+
return fmt.Errorf("expecting shared config repository to be %s but got %s", sharedConfigRepository, accGitopsInfo.SharedConfigRepo)
69+
}
70+
71+
return nil
72+
}
73+
}
74+
75+
// CONFIGS
76+
func testAccountGitopsSettingsGithubDefaultApiUrl(sharedConfigRepository string) string {
77+
return fmt.Sprintf(`
78+
resource "codefresh_account_gitops_settings" "test" {
79+
git_provider = "GITHUB"
80+
shared_config_repository = "%s"
81+
}`, sharedConfigRepository)
82+
}

0 commit comments

Comments
 (0)