diff --git a/GNUmakefile b/GNUmakefile index ccd5a01e..fb9533b3 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -54,7 +54,7 @@ attach: acceptance: fmt export TF_ACC=true && \ - go test -cover -coverprofile=coverage.txt -ldflags="-X '${PKG_VERSION_PATH}/provider.Version=${NEXT_VERSION}-test'" -v -p 1 -parallel 20 -timeout 45m ./pkg/... + go test -cover -coverprofile=coverage.txt -ldflags="-X '${PKG_VERSION_PATH}/provider.Version=${NEXT_VERSION}-test'" -v -p 1 -parallel 20 -timeout 1h ./pkg/... # To generate coverage.txt run `make acceptance` first coverage: diff --git a/pkg/xray/resource/resource_xray_webhook.go b/pkg/xray/resource/resource_xray_webhook.go index d63f6cfd..7e5874f6 100644 --- a/pkg/xray/resource/resource_xray_webhook.go +++ b/pkg/xray/resource/resource_xray_webhook.go @@ -202,28 +202,31 @@ func (r *WebhookResource) Read(ctx context.Context, req resource.ReadRequest, re state.Name = types.StringValue(webhook.Name) - if state.Description.IsNull() { - state.Description = types.StringValue("") - } + description := types.StringNull() if len(webhook.Description) > 0 { - state.Description = types.StringValue(webhook.Description) + description = types.StringValue(webhook.Description) } + state.Description = description state.URL = types.StringValue(webhook.URL) state.UseProxy = types.BoolValue(webhook.UseProxy) - if !state.UserName.IsNull() { - state.UserName = types.StringValue(webhook.UserName) + username := types.StringNull() + if len(webhook.UserName) > 0 { + username = types.StringValue(webhook.UserName) } + state.UserName = username - if !state.Headers.IsNull() { - headers, ds := types.MapValueFrom(ctx, types.StringType, webhook.Headers) + headers := types.MapNull(types.StringType) + if len(webhook.Headers) > 0 { + hs, ds := types.MapValueFrom(ctx, types.StringType, webhook.Headers) if ds.HasError() { resp.Diagnostics.Append(ds...) return } - state.Headers = headers + headers = hs } + state.Headers = headers // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) diff --git a/pkg/xray/resource/resource_xray_webhook_test.go b/pkg/xray/resource/resource_xray_webhook_test.go index f373591f..6453dd91 100644 --- a/pkg/xray/resource/resource_xray_webhook_test.go +++ b/pkg/xray/resource/resource_xray_webhook_test.go @@ -82,6 +82,23 @@ func TestAccWebhook_full(t *testing.T) { url := fmt.Sprintf("https://tempurl%d.org", testutil.RandomInt()) const template = ` + resource "xray_webhook" "{{ .name }}" { + name = "{{ .name }}" + description = "{{ .description }}" + url = "{{ .url }}" + use_proxy = "{{ .use_proxy }}" + } + ` + testData := map[string]string{ + "name": resourceName, + "description": "test description 2", + "url": url, + "use_proxy": "false", + } + + config := util.ExecuteTemplate("TestAccWebhook_full", template, testData) + + const updateTemplate = ` resource "xray_webhook" "{{ .name }}" { name = "{{ .name }}" description = "{{ .description }}" @@ -96,7 +113,7 @@ func TestAccWebhook_full(t *testing.T) { } } ` - testData := map[string]string{ + updatedTestData := map[string]string{ "name": resourceName, "description": "test description", "url": url, @@ -108,23 +125,6 @@ func TestAccWebhook_full(t *testing.T) { "header2_name": "header2_name", "header2_value": "header2_value", } - - config := util.ExecuteTemplate("TestAccWebhook_full", template, testData) - - const updateTemplate = ` - resource "xray_webhook" "{{ .name }}" { - name = "{{ .name }}" - description = "{{ .description }}" - url = "{{ .url }}" - use_proxy = "{{ .use_proxy }}" - } - ` - updatedTestData := map[string]string{ - "name": resourceName, - "description": "test description 2", - "url": url, - "use_proxy": "false", - } updatedConfig := util.ExecuteTemplate("TestAccWebhook_full", updateTemplate, updatedTestData) resource.Test(t, resource.TestCase{ @@ -138,11 +138,9 @@ func TestAccWebhook_full(t *testing.T) { resource.TestCheckResourceAttr(fqrn, "description", testData["description"]), resource.TestCheckResourceAttr(fqrn, "url", testData["url"]), resource.TestCheckResourceAttr(fqrn, "use_proxy", testData["use_proxy"]), - resource.TestCheckResourceAttr(fqrn, "user_name", testData["user_name"]), - resource.TestCheckResourceAttr(fqrn, "password", testData["password"]), - resource.TestCheckResourceAttr(fqrn, "headers.%", "2"), - resource.TestCheckResourceAttr(fqrn, "headers.header1_name", testData["header1_value"]), - resource.TestCheckResourceAttr(fqrn, "headers.header2_name", testData["header2_value"]), + resource.TestCheckNoResourceAttr(fqrn, "user_name"), + resource.TestCheckNoResourceAttr(fqrn, "password"), + resource.TestCheckNoResourceAttr(fqrn, "headers.%"), ), }, { @@ -152,9 +150,11 @@ func TestAccWebhook_full(t *testing.T) { resource.TestCheckResourceAttr(fqrn, "description", updatedTestData["description"]), resource.TestCheckResourceAttr(fqrn, "url", updatedTestData["url"]), resource.TestCheckResourceAttr(fqrn, "use_proxy", updatedTestData["use_proxy"]), - resource.TestCheckNoResourceAttr(fqrn, "user_name"), - resource.TestCheckNoResourceAttr(fqrn, "password"), - resource.TestCheckNoResourceAttr(fqrn, "headers.%"), + resource.TestCheckResourceAttr(fqrn, "user_name", updatedTestData["user_name"]), + resource.TestCheckResourceAttr(fqrn, "password", updatedTestData["password"]), + resource.TestCheckResourceAttr(fqrn, "headers.%", "2"), + resource.TestCheckResourceAttr(fqrn, "headers.header1_name", updatedTestData["header1_value"]), + resource.TestCheckResourceAttr(fqrn, "headers.header2_name", updatedTestData["header2_value"]), ), ConfigPlanChecks: testutil.ConfigPlanChecks(""), },