|
| 1 | +// Copyright (c) 2025 - Stacklet, Inc. |
| 2 | + |
| 3 | +package acceptance_tests |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 10 | +) |
| 11 | + |
| 12 | +func TestAccConfigurationProfileJiraResource(t *testing.T) { |
| 13 | + steps := []resource.TestStep{ |
| 14 | + // Create and Read testing |
| 15 | + { |
| 16 | + Config: ` |
| 17 | + resource "stacklet_configuration_profile_jira" "test" { |
| 18 | + url = "https://example.atlassian.net" |
| 19 | + |
| 20 | + api_key_wo = "initial-api-key" |
| 21 | + api_key_wo_version = "1" |
| 22 | +
|
| 23 | + project { |
| 24 | + name = "Test Project" |
| 25 | + project = "TEST" |
| 26 | + issue_type = "Task" |
| 27 | + closed_status = "Done" |
| 28 | + } |
| 29 | + } |
| 30 | + `, |
| 31 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 32 | + resource.TestCheckResourceAttrSet("stacklet_configuration_profile_jira.test", "id"), |
| 33 | + resource.TestCheckResourceAttrSet("stacklet_configuration_profile_jira.test", "profile"), |
| 34 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "url", "https://example.atlassian.net"), |
| 35 | + resource. TestCheckResourceAttr( "stacklet_configuration_profile_jira.test", "user", "[email protected]"), |
| 36 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "api_key_wo_version", "1"), |
| 37 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "project.#", "1"), |
| 38 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "project.0.name", "Test Project"), |
| 39 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "project.0.project", "TEST"), |
| 40 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "project.0.issue_type", "Task"), |
| 41 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "project.0.closed_status", "Done"), |
| 42 | + ), |
| 43 | + }, |
| 44 | + // ImportState testing |
| 45 | + { |
| 46 | + ResourceName: "stacklet_configuration_profile_jira.test", |
| 47 | + ImportState: true, |
| 48 | + ImportStateVerify: true, |
| 49 | + ImportStateVerifyIgnore: []string{"api_key_wo", "api_key_wo_version"}, |
| 50 | + }, |
| 51 | + // Update and Read testing |
| 52 | + { |
| 53 | + Config: ` |
| 54 | + resource "stacklet_configuration_profile_jira" "test" { |
| 55 | + url = "https://updated.atlassian.net" |
| 56 | + |
| 57 | + api_key_wo = "updated-api-key" |
| 58 | + api_key_wo_version = "1" |
| 59 | +
|
| 60 | + project { |
| 61 | + name = "Updated Project" |
| 62 | + project = "UPD" |
| 63 | + issue_type = "Bug" |
| 64 | + closed_status = "Closed" |
| 65 | + } |
| 66 | + } |
| 67 | + `, |
| 68 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 69 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "url", "https://updated.atlassian.net"), |
| 70 | + resource. TestCheckResourceAttr( "stacklet_configuration_profile_jira.test", "user", "[email protected]"), |
| 71 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "api_key_wo_version", "1"), |
| 72 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "project.#", "1"), |
| 73 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "project.0.name", "Updated Project"), |
| 74 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "project.0.project", "UPD"), |
| 75 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "project.0.issue_type", "Bug"), |
| 76 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "project.0.closed_status", "Closed"), |
| 77 | + ), |
| 78 | + }, |
| 79 | + } |
| 80 | + runRecordedAccTest(t, "TestAccConfigurationProfileJiraResource", steps) |
| 81 | +} |
| 82 | + |
| 83 | +func TestAccConfigurationProfileJiraResource_APIKeyChange(t *testing.T) { |
| 84 | + var returnedAPIKey string |
| 85 | + |
| 86 | + steps := []resource.TestStep{ |
| 87 | + // Initial API key setup |
| 88 | + { |
| 89 | + Config: ` |
| 90 | + resource "stacklet_configuration_profile_jira" "test" { |
| 91 | + url = "https://example.atlassian.net" |
| 92 | + |
| 93 | + api_key_wo = "initial-api-key" |
| 94 | + api_key_wo_version = "1" |
| 95 | +
|
| 96 | + project { |
| 97 | + name = "Test Project" |
| 98 | + project = "TEST" |
| 99 | + issue_type = "Task" |
| 100 | + closed_status = "Done" |
| 101 | + } |
| 102 | + } |
| 103 | + `, |
| 104 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 105 | + resource.TestCheckResourceAttrSet("stacklet_configuration_profile_jira.test", "id"), |
| 106 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "api_key_wo_version", "1"), |
| 107 | + resource.TestCheckResourceAttrSet("stacklet_configuration_profile_jira.test", "api_key"), |
| 108 | + resource.TestCheckResourceAttrWith("stacklet_configuration_profile_jira.test", "api_key", func(value string) error { |
| 109 | + returnedAPIKey = value |
| 110 | + return nil |
| 111 | + }), |
| 112 | + ), |
| 113 | + }, |
| 114 | + // Same version, API key should remain the same |
| 115 | + { |
| 116 | + Config: ` |
| 117 | + resource "stacklet_configuration_profile_jira" "test" { |
| 118 | + url = "https://example.atlassian.net" |
| 119 | + |
| 120 | + api_key_wo = "changed-api-key-but-same-version" |
| 121 | + api_key_wo_version = "1" |
| 122 | +
|
| 123 | + project { |
| 124 | + name = "Test Project" |
| 125 | + project = "TEST" |
| 126 | + issue_type = "Task" |
| 127 | + closed_status = "Done" |
| 128 | + } |
| 129 | + } |
| 130 | + `, |
| 131 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 132 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "api_key_wo_version", "1"), |
| 133 | + resource.TestCheckResourceAttrWith("stacklet_configuration_profile_jira.test", "api_key", func(value string) error { |
| 134 | + if value != returnedAPIKey { |
| 135 | + return fmt.Errorf("api_key should not have changed, was %s, now: %s", returnedAPIKey, value) |
| 136 | + } |
| 137 | + returnedAPIKey = value |
| 138 | + return nil |
| 139 | + }), |
| 140 | + ), |
| 141 | + }, |
| 142 | + // Version changed, API key should change |
| 143 | + { |
| 144 | + Config: ` |
| 145 | + resource "stacklet_configuration_profile_jira" "test" { |
| 146 | + url = "https://example.atlassian.net" |
| 147 | + |
| 148 | + api_key_wo = "updated-api-key" |
| 149 | + api_key_wo_version = "2" |
| 150 | +
|
| 151 | + project { |
| 152 | + name = "Test Project" |
| 153 | + project = "TEST" |
| 154 | + issue_type = "Task" |
| 155 | + closed_status = "Done" |
| 156 | + } |
| 157 | + } |
| 158 | + `, |
| 159 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 160 | + resource.TestCheckResourceAttr("stacklet_configuration_profile_jira.test", "api_key_wo_version", "2"), |
| 161 | + resource.TestCheckResourceAttrWith("stacklet_configuration_profile_jira.test", "api_key", func(value string) error { |
| 162 | + if value == returnedAPIKey { |
| 163 | + return fmt.Errorf("api_key should have changed") |
| 164 | + } |
| 165 | + return nil |
| 166 | + }), |
| 167 | + ), |
| 168 | + }, |
| 169 | + } |
| 170 | + runRecordedAccTest(t, "TestAccConfigurationProfileJiraResource_APIKeyChange", steps) |
| 171 | +} |
0 commit comments