From 6f0816ebd42efde52127bd9998492fb56b502ede Mon Sep 17 00:00:00 2001 From: Ramon Snir Date: Mon, 2 Sep 2024 12:33:45 -0400 Subject: [PATCH] site settings test updates --- GNUmakefile | 2 +- UPDATING_OPENAPI_JSON.md | 3 +- internal/netlifyapi/api/openapi.yaml | 5 +++ internal/netlifyapi/model_repo.go | 37 +++++++++++++++++++ .../provider/site_build_settings_resource.go | 2 +- .../site_build_settings_resource_test.go | 17 +++++++++ ...te_collaboration_settings_resource_test.go | 14 +++++++ .../site_domain_settings_resource_test.go | 18 +++++++++ openapi.json | 3 ++ 9 files changed, 98 insertions(+), 3 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index d714176..364ffde 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -25,7 +25,7 @@ openapi_generate: ## Generate the go code from the OpenAPI spec. -o /local/internal/netlifyapi ; \ sed -i '' 's/int32/int64/g' internal/netlifyapi/model_*.go ; \ sed -i '' 's/int32/int64/g' internal/netlifyapi/api_*.go ; \ - sed -i '' 's/return e.error/return fmt.Sprintf("%s: %q", e.error, e.body)/g' internal/netlifyapi/client.go + sed -i '' 's/return e.error/return fmt.Sprintf("%s: %s", e.error, e.body)/g' internal/netlifyapi/client.go test: ## Test the go code. go test -v ./... diff --git a/UPDATING_OPENAPI_JSON.md b/UPDATING_OPENAPI_JSON.md index c25f3e5..5a21272 100644 --- a/UPDATING_OPENAPI_JSON.md +++ b/UPDATING_OPENAPI_JSON.md @@ -12,6 +12,7 @@ This project uses a modified `openapi.json`. Please maintain these instructions 1. Remove the `values`, `scopes` and `is_secret` parameters from the `updateEnvVar` operation. 1. Add a request body schema to the `updateEnvVar` operation, by copying it from an earlier version of the `openapi.json`. 1. Add a `package_path` property of type `string` to the `Repo` object. +1. Add a `branch` property of type `string` to the `Repo` object. 1. Add a `functions_region` property of type `string` to the `Site` object. 1. Add a `cdp_enabled_contexts` property of type `array` of `string`s to the `Site` object. 1. Add a `hud_enabled` property of type `boolean` to the `Site` object. @@ -25,4 +26,4 @@ This project uses a modified `openapi.json`. Please maintain these instructions 1. Add the various `firewall_rule_set` paths from `bitballoon-openapi`'s `openapi.json` file (NOTE: both site and account level). 1. Replace the response body of the `getAccountFirewallRuleSet` operation to use the `SiteFirewallConfig` object. 1. Replace the request body of the `updateAccountFirewallRuleSet` operation to use the `SiteFirewallConfig` object. -1. Renamed the `unpublished_rules` and `published_rules` properties to `unpublished` and `published` in the `SiteFirewallConfig` object, also in the required properties array. \ No newline at end of file +1. Renamed the `unpublished_rules` and `published_rules` properties to `unpublished` and `published` in the `SiteFirewallConfig` object, also in the required properties array. diff --git a/internal/netlifyapi/api/openapi.yaml b/internal/netlifyapi/api/openapi.yaml index eb6b8b3..ddc75e3 100644 --- a/internal/netlifyapi/api/openapi.yaml +++ b/internal/netlifyapi/api/openapi.yaml @@ -10297,6 +10297,7 @@ components: repo_branch: repo_branch base_rel_dir: true private_logs: true + branch: branch allowed_branches: - allowed_branches - allowed_branches @@ -10351,6 +10352,8 @@ components: type: string public_repo: type: boolean + branch: + type: string repo_branch: type: string repo_owner_type: @@ -10701,6 +10704,7 @@ components: repo_branch: repo_branch base_rel_dir: true private_logs: true + branch: branch allowed_branches: - allowed_branches - allowed_branches @@ -10911,6 +10915,7 @@ components: repo_branch: repo_branch base_rel_dir: true private_logs: true + branch: branch allowed_branches: - allowed_branches - allowed_branches diff --git a/internal/netlifyapi/model_repo.go b/internal/netlifyapi/model_repo.go index 8758709..d7aded9 100644 --- a/internal/netlifyapi/model_repo.go +++ b/internal/netlifyapi/model_repo.go @@ -35,6 +35,7 @@ type Repo struct { PrivateLogs *bool `json:"private_logs,omitempty"` Provider *string `json:"provider,omitempty"` PublicRepo *bool `json:"public_repo,omitempty"` + Branch *string `json:"branch,omitempty"` RepoBranch *string `json:"repo_branch,omitempty"` RepoOwnerType *string `json:"repo_owner_type,omitempty"` RepoPath *string `json:"repo_path,omitempty"` @@ -548,6 +549,38 @@ func (o *Repo) SetPublicRepo(v bool) { o.PublicRepo = &v } +// GetBranch returns the Branch field value if set, zero value otherwise. +func (o *Repo) GetBranch() string { + if o == nil || IsNil(o.Branch) { + var ret string + return ret + } + return *o.Branch +} + +// GetBranchOk returns a tuple with the Branch field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Repo) GetBranchOk() (*string, bool) { + if o == nil || IsNil(o.Branch) { + return nil, false + } + return o.Branch, true +} + +// HasBranch returns a boolean if a field has been set. +func (o *Repo) HasBranch() bool { + if o != nil && !IsNil(o.Branch) { + return true + } + + return false +} + +// SetBranch gets a reference to the given string and assigns it to the Branch field. +func (o *Repo) SetBranch(v string) { + o.Branch = &v +} + // GetRepoBranch returns the RepoBranch field value if set, zero value otherwise. func (o *Repo) GetRepoBranch() string { if o == nil || IsNil(o.RepoBranch) { @@ -923,6 +956,9 @@ func (o Repo) ToMap() (map[string]interface{}, error) { if !IsNil(o.PublicRepo) { toSerialize["public_repo"] = o.PublicRepo } + if !IsNil(o.Branch) { + toSerialize["branch"] = o.Branch + } if !IsNil(o.RepoBranch) { toSerialize["repo_branch"] = o.RepoBranch } @@ -990,6 +1026,7 @@ func (o *Repo) UnmarshalJSON(data []byte) (err error) { delete(additionalProperties, "private_logs") delete(additionalProperties, "provider") delete(additionalProperties, "public_repo") + delete(additionalProperties, "branch") delete(additionalProperties, "repo_branch") delete(additionalProperties, "repo_owner_type") delete(additionalProperties, "repo_path") diff --git a/internal/provider/site_build_settings_resource.go b/internal/provider/site_build_settings_resource.go index b651595..e3b1145 100644 --- a/internal/provider/site_build_settings_resource.go +++ b/internal/provider/site_build_settings_resource.go @@ -311,7 +311,7 @@ func (r *siteBuildSettingsResource) write(ctx context.Context, plan *siteBuildSe Dir: plan.PublishDirectory.ValueStringPointer(), FunctionsDir: plan.FunctionsDirectory.ValueStringPointer(), StopBuilds: plan.StopBuilds.ValueBoolPointer(), - RepoBranch: plan.ProductionBranch.ValueStringPointer(), + Branch: plan.ProductionBranch.ValueStringPointer(), AllowedBranches: allowedBranches, SkipPrs: &skipPrs, }, diff --git a/internal/provider/site_build_settings_resource_test.go b/internal/provider/site_build_settings_resource_test.go index 11ed18c..3344e54 100644 --- a/internal/provider/site_build_settings_resource_test.go +++ b/internal/provider/site_build_settings_resource_test.go @@ -12,6 +12,23 @@ func TestAccSiteBuildSettings(t *testing.T) { { Config: `resource "netlify_site_build_settings" "example" { site_id = "49137d35-1470-4db1-810f-c185b8381cd3" + build_command = "npm run build && true" + publish_directory = "dist/dist" + production_branch = "preview" + branch_deploy_branches = ["staging"] +}`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("netlify_site_build_settings.example", "site_id", "49137d35-1470-4db1-810f-c185b8381cd3"), + resource.TestCheckResourceAttr("netlify_site_build_settings.example", "build_command", "npm run build && true"), + resource.TestCheckResourceAttr("netlify_site_build_settings.example", "publish_directory", "dist/dist"), + resource.TestCheckResourceAttr("netlify_site_build_settings.example", "production_branch", "preview"), + resource.TestCheckResourceAttr("netlify_site_build_settings.example", "branch_deploy_branches.#", "1"), + resource.TestCheckResourceAttr("netlify_site_build_settings.example", "branch_deploy_branches.0", "staging"), + ), + }, + { + Config: `resource "netlify_site_build_settings" "example" { + site_id = "49137d35-1470-4db1-810f-c185b8381cd3" build_command = "npm run build" publish_directory = "dist" production_branch = "main" diff --git a/internal/provider/site_collaboration_settings_resource_test.go b/internal/provider/site_collaboration_settings_resource_test.go index 98ecf57..89b9223 100644 --- a/internal/provider/site_collaboration_settings_resource_test.go +++ b/internal/provider/site_collaboration_settings_resource_test.go @@ -12,6 +12,20 @@ func TestAccSiteCollaborationSettings(t *testing.T) { { Config: `resource "netlify_site_collaboration_settings" "example" { site_id = "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26" + netlify_drawer_in_deploy_previews = false + netlify_drawer_in_branch_deploys = false + netlify_heads_up_display = false +}`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("netlify_site_collaboration_settings.example", "site_id", "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26"), + resource.TestCheckResourceAttr("netlify_site_collaboration_settings.example", "netlify_drawer_in_deploy_previews", "false"), + resource.TestCheckResourceAttr("netlify_site_collaboration_settings.example", "netlify_drawer_in_branch_deploys", "false"), + resource.TestCheckResourceAttr("netlify_site_collaboration_settings.example", "netlify_heads_up_display", "false"), + ), + }, + { + Config: `resource "netlify_site_collaboration_settings" "example" { + site_id = "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26" netlify_drawer_in_deploy_previews = true netlify_drawer_in_branch_deploys = true netlify_heads_up_display = true diff --git a/internal/provider/site_domain_settings_resource_test.go b/internal/provider/site_domain_settings_resource_test.go index 39f0941..d005aaf 100644 --- a/internal/provider/site_domain_settings_resource_test.go +++ b/internal/provider/site_domain_settings_resource_test.go @@ -8,12 +8,30 @@ import ( ) func TestAccSiteDomainSettings(t *testing.T) { + // TODO: change domain and domain aliases, and wait for the certificate to update accTest(t, []resource.TestStep{ { Config: `resource "netlify_site_domain_settings" "example" { site_id = "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26" custom_domain = "tf-test-1.examplepetstore.com" domain_aliases = ["tf-test-1-alias.examplepetstore.com"] + branch_deploy_custom_domain = "tf-test-12-branch.examplepetstore.com" + deploy_preview_custom_domain = "tf-test-12-dp.examplepetstore.com" +}`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("netlify_site_domain_settings.example", "site_id", "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26"), + resource.TestCheckResourceAttr("netlify_site_domain_settings.example", "custom_domain", "tf-test-1.examplepetstore.com"), + resource.TestCheckResourceAttr("netlify_site_domain_settings.example", "domain_aliases.#", "1"), + resource.TestCheckResourceAttr("netlify_site_domain_settings.example", "domain_aliases.0", "tf-test-1-alias.examplepetstore.com"), + resource.TestCheckResourceAttr("netlify_site_domain_settings.example", "branch_deploy_custom_domain", "tf-test-12-branch.examplepetstore.com"), + resource.TestCheckResourceAttr("netlify_site_domain_settings.example", "deploy_preview_custom_domain", "tf-test-12-dp.examplepetstore.com"), + ), + }, + { + Config: `resource "netlify_site_domain_settings" "example" { + site_id = "5b407d6d-9385-4e7a-a4c4-8efc11ea3c26" + custom_domain = "tf-test-1.examplepetstore.com" + domain_aliases = ["tf-test-1-alias.examplepetstore.com"] branch_deploy_custom_domain = "tf-test-1-branch.examplepetstore.com" deploy_preview_custom_domain = "tf-test-1-dp.examplepetstore.com" }`, diff --git a/openapi.json b/openapi.json index ee38d0d..d5f1050 100644 --- a/openapi.json +++ b/openapi.json @@ -13141,6 +13141,9 @@ "public_repo": { "type": "boolean" }, + "branch": { + "type": "string" + }, "repo_branch": { "type": "string" },