Skip to content

Commit

Permalink
update integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Jun 7, 2022
1 parent fbaa332 commit 9bf84cf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
8 changes: 1 addition & 7 deletions client/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package client
//only use "template", no mention of blueprint

import (
"encoding/json"
"errors"
"strconv"
"strings"
Expand Down Expand Up @@ -203,16 +202,11 @@ func (client *ApiClient) RemoveTemplateFromProject(templateId string, projectId
}

func (client *ApiClient) VariablesFromRepository(payload *VariablesFromRepositoryPayload) ([]ConfigurationVariable, error) {
b, err := json.Marshal(payload)
paramsInterface, err := toParamsInterface(payload)
if err != nil {
return nil, err
}

var paramsInterface map[string]interface{}
if err := json.Unmarshal(b, &paramsInterface); err != nil {
return nil, err
}

params := map[string]string{}
for key, value := range paramsInterface {
if key == "githubInstallationId" {
Expand Down
17 changes: 17 additions & 0 deletions client/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package client

import "encoding/json"

func toParamsInterface(i interface{}) (map[string]interface{}, error) {
b, err := json.Marshal(i)
if err != nil {
return nil, err
}

var paramsInterface map[string]interface{}
if err := json.Unmarshal(b, &paramsInterface); err != nil {
return nil, err
}

return paramsInterface, nil
}
4 changes: 3 additions & 1 deletion tests/integration/004_template/expected_outputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"gitlab_template_repository": "https://gitlab.com/env0/gitlab-vcs-integration-tests.git",
"github_template_path": "second",
"tg_tg_version" : "0.35.0",
"data_github_template_type": "terraform"
"data_github_template_type": "terraform",
"github_variables_name": "email",
"github_variables_value": "default@domain.com"
}
29 changes: 25 additions & 4 deletions tests/integration/004_template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ resource "env0_template" "github_template" {
terraform_version = "0.15.1"
}

data "env0_source_code_variables" "variables" {
template_id = data.env0_template.github_template.id
}

resource "env0_template" "gitlab_template" {
name = "GitLab Test-${random_string.random.result}"
description = "Template description - Gitlab"
Expand Down Expand Up @@ -71,6 +67,31 @@ resource "env0_configuration_variable" "in_a_template2" {
type = "terraform"
}

resource "env0_template" "github_template_source_code" {
name = "Github Test Source Code-${random_string.random.result}"
description = "Template description - GitHub"
type = "terraform"
repository = data.env0_template.github_template.repository
github_installation_id = data.env0_template.github_template.github_installation_id
path = "misc/custom-flow-tf-vars"
retries_on_deploy = 3
retry_on_deploy_only_when_matches_regex = "abc"
retries_on_destroy = 1
terraform_version = "0.15.1"
}

data "env0_source_code_variables" "variables" {
template_id = env0_template.github_template_source_code.id
}

output "github_variables_name" {
value = data.env0_source_code_variables.variables.variables.0.name
}

output "github_variables_value" {
value = data.env0_source_code_variables.variables.variables.0.value
}

output "github_template_id" {
value = env0_template.github_template.id
}
Expand Down

0 comments on commit 9bf84cf

Please sign in to comment.