@@ -10,11 +10,10 @@ import (
1010 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1111)
1212
13- func TestAccDataSourceChaosHub (t * testing.T ) {
14- // Check for required environment variables
15- accountId := os .Getenv ("HARNESS_ACCOUNT_ID" )
16- if accountId == "" {
17- t .Skip ("Skipping test because HARNESS_ACCOUNT_ID is not set" )
13+ func TestAccDataSourceChaosHub_ProjectLevel (t * testing.T ) {
14+ chaosGithubToken := os .Getenv ("CHAOS_GITHUB_TOKEN" )
15+ if chaosGithubToken == "" {
16+ t .Skip ("Skipping test because CHAOS_GITHUB_TOKEN is not set" )
1817 }
1918
2019 // Generate unique identifiers
@@ -26,133 +25,80 @@ func TestAccDataSourceChaosHub(t *testing.T) {
2625 resource .UnitTest (t , resource.TestCase {
2726 PreCheck : func () { acctest .TestAccPreCheck (t ) },
2827 ProviderFactories : acctest .ProviderFactories ,
28+ ExternalProviders : map [string ]resource.ExternalProvider {
29+ "time" : {},
30+ },
2931 Steps : []resource.TestStep {
3032 {
31- Config : testAccDataSourceChaosHubConfig (rName , id , "main" ),
33+ Config : testAccDataSourceChaosHubProjectLevelConfig (rName , id , "master" , chaosGithubToken ),
3234 Check : resource .ComposeTestCheckFunc (
3335 resource .TestCheckResourceAttr (dataSourceName , "name" , rName ),
34- resource .TestCheckResourceAttrPair (dataSourceName , "id" , resourceName , "id" ),
36+ resource .TestCheckResourceAttrPair (dataSourceName , "project_id" , resourceName , "project_id" ),
37+ resource .TestCheckResourceAttrPair (dataSourceName , "org_id" , resourceName , "org_id" ),
3538 resource .TestCheckResourceAttrPair (dataSourceName , "connector_id" , resourceName , "connector_id" ),
3639 resource .TestCheckResourceAttrPair (dataSourceName , "repo_branch" , resourceName , "repo_branch" ),
37- resource .TestCheckResourceAttr (dataSourceName , "connector_scope" , "ACCOUNT" ),
3840 resource .TestCheckResourceAttrSet (dataSourceName , "created_at" ),
3941 resource .TestCheckResourceAttrSet (dataSourceName , "is_available" ),
42+ resource .TestCheckResourceAttrSet (dataSourceName , "last_synced_at" ),
43+ resource .TestCheckResourceAttrSet (dataSourceName , "total_experiments" ),
44+ resource .TestCheckResourceAttrSet (dataSourceName , "total_faults" ),
45+ resource .TestCheckResourceAttrSet (dataSourceName , "updated_at" ),
4046 ),
4147 },
4248 },
4349 })
4450}
4551
46- func TestAccDataSourceChaosHub_ProjectLevel (t * testing.T ) {
47- // Check for required environment variables
48- accountId := os .Getenv ("HARNESS_ACCOUNT_ID" )
49- if accountId == "" {
50- t .Skip ("Skipping test because HARNESS_ACCOUNT_ID is not set" )
51- }
52-
53- // Generate unique identifiers
54- id := fmt .Sprintf ("%s_%s" , t .Name (), utils .RandStringBytes (5 ))
55- rName := id
56- dataSourceName := "data.harness_chaos_hub.test"
57- resourceName := "harness_chaos_hub.test"
58-
59- resource .UnitTest (t , resource.TestCase {
60- PreCheck : func () { acctest .TestAccPreCheck (t ) },
61- ProviderFactories : acctest .ProviderFactories ,
62- Steps : []resource.TestStep {
63- {
64- Config : testAccDataSourceChaosHubProjectLevelConfig (rName , id , "develop" ),
65- Check : resource .ComposeTestCheckFunc (
66- resource .TestCheckResourceAttr (dataSourceName , "name" , rName ),
67- resource .TestCheckResourceAttrPair (dataSourceName , "id" , resourceName , "id" ),
68- resource .TestCheckResourceAttrPair (dataSourceName , "project_id" , resourceName , "project_id" ),
69- resource .TestCheckResourceAttrPair (dataSourceName , "org_id" , resourceName , "org_id" ),
70- resource .TestCheckResourceAttr (dataSourceName , "connector_scope" , "PROJECT" ),
71- ),
72- },
73- },
74- })
75- }
76-
77- func testAccDataSourceChaosHubConfig (name , id , branch string ) string {
78- // Use the account ID from environment variables
79- accountId := os .Getenv ("HARNESS_ACCOUNT_ID" )
80- if accountId == "" {
81- accountId = "test" // Default for test cases when not set
82- }
83-
84- return fmt .Sprintf (`
85- resource "harness_platform_connector_github" "test" {
86- identifier = "%[2]s"
87- name = "%[1]s"
88- description = "Test connector"
89- url = "https://github.com"
90- connection_type = "Account"
91- validation_repo = "harness/chaos-hub"
92-
93- credentials {
94- http {
95- username = "test"
96- token_ref = "account.do_not_delete_harness_platform_qa_token"
97- }
98- }
99- }
100-
101- resource "harness_chaos_hub" "test" {
102- name = "%[1]s"
103- connector_id = harness_platform_connector_github.test.id
104- connector_scope = "ACCOUNT"
105- repo_branch = "%[3]s"
106- description = "Test chaos hub"
107- tags = ["test:true", "chaos:true"]
108- }
109-
110- data "harness_chaos_hub" "test" {
111- name = harness_chaos_hub.test.name
112- }
113- ` , name , id , branch )
114- }
115-
116- func testAccDataSourceChaosHubProjectLevelConfig (name , id , branch string ) string {
117- // Use the account ID from environment variables
118- accountId := os .Getenv ("HARNESS_ACCOUNT_ID" )
119- if accountId == "" {
120- accountId = "test" // Default for test cases when not set
121- }
52+ // Terraform Configurations
12253
54+ func testAccDataSourceChaosHubProjectLevelConfig (name , id , branch , githubToken string ) string {
12355 return fmt .Sprintf (`
12456 resource "harness_platform_organization" "test" {
12557 identifier = "%[2]s"
12658 name = "%[1]s"
127- account_id = "%[4]s"
12859 }
12960
13061 resource "harness_platform_project" "test" {
13162 identifier = "%[2]s"
13263 name = "%[1]s"
13364 org_id = harness_platform_organization.test.id
134- account_id = "%[4]s"
13565 color = "#0063F7"
13666 description = "Test project for Chaos Hub"
13767 tags = ["foo:bar", "baz:qux"]
13868 }
69+
70+ resource "harness_platform_secret_text" "test" {
71+ identifier = "%[2]s"
72+ name = "%[1]s"
73+ description = "test"
74+ tags = ["foo:bar"]
75+
76+ secret_manager_identifier = "harnessSecretManager"
77+ value_type = "Inline"
78+ value = "%[4]s"
79+ }
13980
14081 resource "harness_platform_connector_github" "test" {
14182 identifier = "%[2]s"
14283 name = "%[1]s"
14384 description = "Test connector"
144- url = "https://github.com"
145- connection_type = "Project"
146- validation_repo = "harness/chaos-hub"
85+ url = "https://github.com/litmuschaos/chaos-charts"
86+ connection_type = "Repo"
14787 project_id = harness_platform_project.test.id
14888 org_id = harness_platform_organization.test.id
14989
15090 credentials {
15191 http {
152- username = "test "
153- token_ref = "account.do_not_delete_harness_platform_qa_token "
92+ username = "admin "
93+ token_ref = "account.${harness_platform_secret_text.test.id} "
15494 }
15595 }
96+ depends_on = [time_sleep.wait_4_seconds]
97+ }
98+
99+ resource "time_sleep" "wait_4_seconds" {
100+ depends_on = [harness_platform_secret_text.test]
101+ destroy_duration = "4s"
156102 }
157103
158104 resource "harness_chaos_hub" "test" {
@@ -171,5 +117,5 @@ func testAccDataSourceChaosHubProjectLevelConfig(name, id, branch string) string
171117 org_id = harness_platform_organization.test.id
172118 project_id = harness_platform_project.test.id
173119 }
174- ` , name , id , branch , accountId )
120+ ` , name , id , branch , githubToken )
175121}
0 commit comments