Skip to content

Commit

Permalink
fix: crash when using provider headers (#178)
Browse files Browse the repository at this point in the history
* fix: crash when using provider headers

* fix(test): flaky TestAccArgoCDCluster_uniqueByServerTrimmed
  • Loading branch information
MrLuje authored Jun 30, 2022
1 parent 79342b9 commit 5de35cc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion argocd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ func initApiClient(d *schema.ResourceData) (
opts.PortForwardNamespace = v.(string)
}
if v, ok := d.GetOk("headers"); ok {
opts.Headers = v.([]string)
_headers := v.(*schema.Set).List()
var headers = make([]string, len(_headers))
for i, _header := range _headers {
headers[i] = _header.(string)
}
opts.Headers = headers
}
if _, ok := d.GetOk("kubernetes"); ok {
opts.KubeOverrides = &clientcmd.ConfigOverrides{}
Expand Down
19 changes: 19 additions & 0 deletions argocd/resource_argocd_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,25 @@ func TestAccArgoCDApplication_Info(t *testing.T) {
}})
}

func TestProvider_headers(t *testing.T) {
name := acctest.RandomWithPrefix("test-acc")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf("%s %s", `
provider "argocd" {
headers = [
"Hello: HiThere",
]
}`, testAccArgoCDApplicationSimple(name),
),
},
},
})
}

func testAccArgoCDApplicationSimple(name string) string {
return fmt.Sprintf(`
resource "argocd_application" "simple" {
Expand Down
2 changes: 2 additions & 0 deletions argocd/resource_argocd_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ resource "argocd_cluster" "cluster_two" {
func testAccArgoCDClusterTwiceWithSameServerNoNamesTrimmed(server, server2 string) string {
return fmt.Sprintf(`
resource "argocd_cluster" "cluster_one" {
name = "server"
server = "%s"
config {
# Uses Kind's bootstrap token whose ttl is 24 hours after cluster bootstrap.
Expand All @@ -516,6 +517,7 @@ resource "argocd_cluster" "cluster_one" {
}
}
resource "argocd_cluster" "cluster_two" {
name = "server"
server = "%s"
config {
# Uses Kind's bootstrap token whose ttl is 24 hours after cluster bootstrap.
Expand Down

0 comments on commit 5de35cc

Please sign in to comment.