From 16698cfc47e419d23be0a2a329661f13c0b900d1 Mon Sep 17 00:00:00 2001 From: "avner.sorek" Date: Mon, 31 May 2021 14:52:13 +0300 Subject: [PATCH 1/2] fix template creation model to omit empty github installation id --- client/model.go | 6 +++--- client/model_test.go | 21 +++++++++++++++++++++ tests/integration/005_ssh_key/main.tf | 10 +++++----- 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 client/model_test.go diff --git a/client/model.go b/client/model.go index a53701a6..3adc04c1 100644 --- a/client/model.go +++ b/client/model.go @@ -34,8 +34,8 @@ type Project struct { } type UpdateProjectPayload struct { - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` } type ConfigurationVariableSchema struct { @@ -107,7 +107,7 @@ type TemplateCreatePayload struct { IsGitLab bool `json:"isGitLab"` TokenName string `json:"tokenName"` TokenId string `json:"tokenId"` - GithubInstallationId int `json:"githubInstallationId"` + GithubInstallationId int `json:"githubInstallationId,omitempty"` Revision string `json:"revision"` ProjectIds []string `json:"projectIds,omitempty"` OrganizationId string `json:"organizationId"` diff --git a/client/model_test.go b/client/model_test.go new file mode 100644 index 00000000..1436a60c --- /dev/null +++ b/client/model_test.go @@ -0,0 +1,21 @@ +package client_test + +import ( + "encoding/json" + + . "github.com/env0/terraform-provider-env0/client" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Models", func() { + Describe("TemplateCreatePayload", func() { + It("Should omit Github Installation Id when it's not there", func() { + payload := TemplateCreatePayload{} + jsonPayload, _ := json.Marshal(payload) + var parsedPayload map[string]interface{} + json.Unmarshal(jsonPayload, &parsedPayload) + Expect(parsedPayload["githubInstallationId"]).To(BeNil()) + }) + }) +}) diff --git a/tests/integration/005_ssh_key/main.tf b/tests/integration/005_ssh_key/main.tf index b4c62e53..27232567 100644 --- a/tests/integration/005_ssh_key/main.tf +++ b/tests/integration/005_ssh_key/main.tf @@ -24,9 +24,9 @@ output "name" { } resource "env0_template" "usage" { - name = "use a ssh key" - description = "use a ssh key" - type = "terraform" - repository = "https://github.com/shlomimatichin/env0-template-jupyter-gpu" - ssh_keys = [env0_ssh_key.tested] + name = "use a ssh key" + description = "use a ssh key" + type = "terraform" + repository = "https://github.com/shlomimatichin/env0-template-jupyter-gpu" + ssh_keys = [env0_ssh_key.tested] } From 4f8e41a00788f47f1ee22b5197e17666b8806019 Mon Sep 17 00:00:00 2001 From: "avner.sorek" Date: Mon, 31 May 2021 15:07:01 +0300 Subject: [PATCH 2/2] better test --- client/model_test.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/client/model_test.go b/client/model_test.go index 1436a60c..54d8ae3a 100644 --- a/client/model_test.go +++ b/client/model_test.go @@ -5,17 +5,25 @@ import ( . "github.com/env0/terraform-provider-env0/client" . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" + "github.com/onsi/gomega/types" ) var _ = Describe("Models", func() { Describe("TemplateCreatePayload", func() { - It("Should omit Github Installation Id when it's not there", func() { - payload := TemplateCreatePayload{} - jsonPayload, _ := json.Marshal(payload) - var parsedPayload map[string]interface{} - json.Unmarshal(jsonPayload, &parsedPayload) - Expect(parsedPayload["githubInstallationId"]).To(BeNil()) - }) + DescribeTable("Github Installation Id", + func(value int, expected types.GomegaMatcher) { + payload := TemplateCreatePayload{ + GithubInstallationId: value, + } + jsonPayload, _ := json.Marshal(payload) + var parsedPayload map[string]interface{} + json.Unmarshal(jsonPayload, &parsedPayload) + Expect(parsedPayload["githubInstallationId"]).To(expected) + }, + Entry("Has value", 123, BeEquivalentTo(123)), + Entry("No value", nil, BeNil()), + ) }) })