Skip to content

Commit

Permalink
fixing hcl and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pacobart committed Nov 7, 2023
1 parent 935da84 commit d295afd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ jobs:
- name: check test coverage
uses: vladopajic/go-test-coverage@v2
with:
# Configure action using config file (option 1)
config: ./.testcoverage.yml

# Configure action by specifying input parameters individually (option 2).
# If you are using config file you shouldn't use these parameters.
profile: cover.out
local-prefix: github.com/Pacobart/terraform-cloud-workspace-collector
#threshold-file: 80 # The minimum coverage that each file should have
#threshold-package: 80 # The minimum coverage that each package should have
#threshold-total: 95 # The minimum total coverage project should have
#threshold-total: 95 # The minimum total coverage project should have
git-branch: badges
git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ build:
.PHONY: all $(OS_ARCH_PAIRS) clean build

test:
go test ./... -coverprofile cov.out
go test ./... -coverprofile=./cov.out -covermode=atomic -coverpkg=./...

run:
go run main.go
Expand Down
2 changes: 1 addition & 1 deletion internal/hcl/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func GenerateHCLTFVars(workspaces []tfworkspaces.Workspace) *hclwrite.File {
workspaceBody.SetAttributeValue("reponame", cty.StringVal(ws.Attributes.Name))
workspaceBody.SetAttributeValue("description", cty.StringVal(ws.Attributes.Description))
workspaceBody.SetAttributeValue("branchname", cty.StringVal(ws.Attributes.VcsRepo.Branch))
workspaceBody.SetAttributeValue("agent", cty.StringVal(ws.Relationships.AgentPool.Data.Id))
workspaceBody.SetAttributeValue("agent", cty.StringVal(ws.Relationships.AgentPool.Data.Name))
workspaceBody.SetAttributeValue("project_id", cty.StringVal(ws.Relationships.Project.Data.Name))
workspaceBody.SetAttributeValue("variableset_name", cty.StringVal(variableSetName)) // TODO: only supporting one for no)

Expand Down
6 changes: 4 additions & 2 deletions internal/hcl/hcl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ func TestGenerateHCLTFVars(t *testing.T) {
workspace.Attributes.VcsRepo.Branch = "main"
workspace.Attributes.VcsRepo.Identifier = "https://github.com/Pacobart/terraform-cloud-workspace-collector.git"
workspace.Relationships.Organization.Data.ID = "org-tv9993939393fupk"
workspace.Relationships.AgentPool.Data.Id = "pool10x"
workspace.Relationships.AgentPool.Data.Id = "agent-pool10x"
workspace.Relationships.AgentPool.Data.Name = "pool10x"
workspace.Relationships.Project.Data.Id = "proj-tv9993939393fupk"
workspace.Relationships.Project.Data.Name = "Default Project"
var variable1 tfvariables.Variable
variable1.ID = "var-tv9993939393fupk"
variable1.Attributes.Key = "my-var"
Expand All @@ -31,7 +33,7 @@ func TestGenerateHCLTFVars(t *testing.T) {
description = "My awesome workspace"
branchname = "main"
agent = "pool10x"
project_id = "proj-tv9993939393fupk"
project_id = "Default Project"
variableset_name = ""
teams = {
}
Expand Down
7 changes: 6 additions & 1 deletion internal/tfworkspaces/tfworkspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ func GetWorkspaces(baseUrl string, token string, organization string) []Workspac
if projectID != "" {
project := tfprojects.GetProject(baseUrl, token, projectID)
projectName := project.Data.Attributes.Name
ws.Relationships.Project.Data.Name = projectName
if projectName != "" {
ws.Relationships.Project.Data.Name = projectName
} else {
ws.Relationships.Project.Data.Name = projectID
fmt.Printf("Project name is empty for project %s. Setting Name to ID\n", projectID)
}
}

agentPoollID := ws.Relationships.AgentPool.Data.Id
Expand Down

0 comments on commit d295afd

Please sign in to comment.