Skip to content

Commit

Permalink
Feat: gitlab_project_id always shows drift (#917)
Browse files Browse the repository at this point in the history
* Feat: gitlab_project_id always shows drift

* update harness test

* update harness test
  • Loading branch information
TomerHeber authored Jul 30, 2024
1 parent 2ab4d8a commit f1d24fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
1 change: 1 addition & 0 deletions client/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Template struct {
IsGitLab bool `json:"isGitLab" tfschema:"is_gitlab"`
TerragruntTfBinary string `json:"terragruntTfBinary" tfschema:",omitempty"`
TokenName string `json:"tokenName" tfschema:",omitempty"`
GitlabProjectId int `json:"gitlabProjectId" tfschema:",omitempty"`
}

type TemplateCreatePayload struct {
Expand Down
34 changes: 9 additions & 25 deletions env0/resource_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func TestUnitTemplateResource(t *testing.T) {
TokenId: "1",
TerraformVersion: "0.12.24",
TokenName: "token_name",
GitlabProjectId: 1234,
}
gitlabTemplateProjectId := 10
gitlabUpdatedTemplate := client.Template{
Id: gitlabTemplate.Id,
Name: "new-name",
Expand All @@ -109,8 +109,8 @@ func TestUnitTemplateResource(t *testing.T) {
TokenId: "2",
TerraformVersion: "0.15.1",
TokenName: "token_name2",
GitlabProjectId: 5678,
}
gitlabTemplateUpdatedProjectId := 15
githubTemplate := client.Template{
Id: "id0",
Name: "template0",
Expand Down Expand Up @@ -492,12 +492,8 @@ func TestUnitTemplateResource(t *testing.T) {
if template.TokenName != "" {
templateAsDictionary["token_name"] = template.TokenName
}
if template.Id == gitlabTemplate.Id {
if template.Name == gitlabUpdatedTemplate.Name {
templateAsDictionary["gitlab_project_id"] = gitlabTemplateUpdatedProjectId
} else {
templateAsDictionary["gitlab_project_id"] = gitlabTemplateProjectId
}
if template.GitlabProjectId != 0 {
templateAsDictionary["gitlab_project_id"] = template.GitlabProjectId
}
if template.GithubInstallationId != 0 {
templateAsDictionary["github_installation_id"] = template.GithubInstallationId
Expand Down Expand Up @@ -536,13 +532,9 @@ func TestUnitTemplateResource(t *testing.T) {
return resourceConfigCreate(resourceType, resourceName, templateAsDictionary)
}
fullTemplateResourceCheck := func(resourceFullName string, template client.Template) resource.TestCheckFunc {
gitlabProjectIdAssertion := resource.TestCheckNoResourceAttr(resourceFullName, "gitlab_project_id")
if template.Id == gitlabTemplate.Id {
if template.Name == gitlabUpdatedTemplate.Name {
gitlabProjectIdAssertion = resource.TestCheckResourceAttr(resourceFullName, "gitlab_project_id", strconv.Itoa(gitlabTemplateUpdatedProjectId))
} else {
gitlabProjectIdAssertion = resource.TestCheckResourceAttr(resourceFullName, "gitlab_project_id", strconv.Itoa(gitlabTemplateProjectId))
}
gitlabProjectIdAssertion := resource.TestCheckResourceAttr(resourceFullName, "gitlab_project_id", strconv.Itoa(template.GitlabProjectId))
if template.GitlabProjectId == 0 {
gitlabProjectIdAssertion = resource.TestCheckNoResourceAttr(resourceFullName, "gitlab_project_id")
}

tokenIdAssertion := resource.TestCheckResourceAttr(resourceFullName, "token_id", template.TokenId)
Expand Down Expand Up @@ -630,22 +622,14 @@ func TestUnitTemplateResource(t *testing.T) {
}
for _, templateUseCase := range templateUseCases {
t.Run("Full "+templateUseCase.vcs+" template (without SSH keys)", func(t *testing.T) {
gitlabProjectId := 0
gitlabUpdatedProjectId := 0

if templateUseCase.vcs == "GitLab" {
gitlabProjectId = gitlabTemplateProjectId
gitlabUpdatedProjectId = gitlabTemplateUpdatedProjectId
}

templateCreatePayload := client.TemplateCreatePayload{
Name: templateUseCase.template.Name,
Repository: templateUseCase.template.Repository,
Description: templateUseCase.template.Description,
GithubInstallationId: templateUseCase.template.GithubInstallationId,
IsGitlabEnterprise: templateUseCase.template.IsGitlabEnterprise,
IsGitLab: templateUseCase.template.TokenId != "" && !templateUseCase.template.IsAzureDevOps,
GitlabProjectId: gitlabProjectId,
GitlabProjectId: templateUseCase.template.GitlabProjectId,
TokenId: templateUseCase.template.TokenId,
Path: templateUseCase.template.Path,
Revision: templateUseCase.template.Revision,
Expand All @@ -672,7 +656,7 @@ func TestUnitTemplateResource(t *testing.T) {
GithubInstallationId: templateUseCase.updatedTemplate.GithubInstallationId,
IsGitlabEnterprise: templateUseCase.updatedTemplate.IsGitlabEnterprise,
IsGitLab: templateUseCase.updatedTemplate.TokenId != "" && !templateUseCase.updatedTemplate.IsAzureDevOps,
GitlabProjectId: gitlabUpdatedProjectId,
GitlabProjectId: templateUseCase.updatedTemplate.GitlabProjectId,
TokenId: templateUseCase.updatedTemplate.TokenId,
Path: templateUseCase.updatedTemplate.Path,
Revision: templateUseCase.updatedTemplate.Revision,
Expand Down

0 comments on commit f1d24fc

Please sign in to comment.