Skip to content

Commit

Permalink
chore: more refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
marcportabellaclotet-mt committed Aug 15, 2023
1 parent 6d1949d commit a603c6c
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 9 deletions.
Binary file added atlantis-yaml-generator
Binary file not shown.
3 changes: 1 addition & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ Alternatively, you can set this parameter using GH_TOKEN environment variable.`)
os.Exit(1)
}
os.Exit(0)

}

func genAtlantisYaml(ccmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -109,7 +108,7 @@ func genAtlantisYaml(ccmd *cobra.Command, args []string) error {
// Define the WhenModified list
atlantisWhenModifiedList := defineWhenModifiedList(atlantisWhenModified)

// Define pattern detector
// Define pattern detector. Its value depends on workflow type
atlantisProjectsPatternDetector = defineProjectPatternDetector(atlantisProjectsPatternDetector, atlantisWorkflow)

// Create GitHub and Atlantis parameters
Expand Down
55 changes: 48 additions & 7 deletions pkg/atlantis/atlantis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestMultiWorkspaceDetectProjectWorkspaces(t *testing.T) {
},
}

changedFiles := []string{"mockproject/workspace_vars/test1.tfvars", "project2/file2.tfvars"}
changedFiles := []string{"mockproject/multiworkspace/workspace_vars/test1.tfvars", "project2/file2.tfvars"}

foldersList, err := detectProjectWorkspaces(foldersList, "multi-workspace", "workspace_vars", changedFiles)

Expand All @@ -277,23 +277,23 @@ func TestMultiWorkspaceDetectProjectWorkspaces(t *testing.T) {
}

func TestMultiWorkspaceGetProjectScope(t *testing.T) {
changedFiles := []string{"mockproject/worksspace_vars/file1.tfvars"}
changedFiles := []string{"mockproject/multiworkspace/workspace_vars/file1.tfvars"}

scope := multiWorkspaceGetProjectScope("project1", "workspace_vars", changedFiles)
scope := multiWorkspaceGetProjectScope("mockproject/multiworkspace", "workspace_vars", changedFiles)
assert.Equal(t, "workspace", scope)

scope = multiWorkspaceGetProjectScope("project2", "workspace_vars", changedFiles)
assert.Equal(t, "workspace", scope)

changedFiles = append(changedFiles, "project1/some_file.txt")
scope = multiWorkspaceGetProjectScope("project1", "workspace_vars", changedFiles)
changedFiles = append(changedFiles, "mockproject/multiworkspace/main.tf")
scope = multiWorkspaceGetProjectScope("mockproject/multiworkspace", "workspace_vars", changedFiles)
assert.Equal(t, "crossWorkspace", scope)
}

func TestMultiWorkspaceGenWorkspaceList(t *testing.T) {
changedFiles := []string{"mockproject/workspace_vars/test1.tfvars"}
changedFiles := []string{"mockproject/multiworkspace/workspace_vars/test1.tfvars"}

workspaceList, err := multiWorkspaceGenWorkspaceList("mockproject", changedFiles, "workspace")
workspaceList, err := multiWorkspaceGenWorkspaceList("mockproject/multiworkspace", changedFiles, "workspace")
assert.NoError(t, err)
assert.Equal(t, []string{"test1"}, workspaceList)

Expand All @@ -315,3 +315,44 @@ func TestPrFilter(t *testing.T) {
result = prFilter(relPath, changedFiles)
assert.False(t, result, "Expected false, but got true")
}

func TestScanProjectFolders(t *testing.T) {
tests := []struct {
basePath string
workflow string
patternDetector string
changedFiles []string
expectedProjectFolder []ProjectFolder
}{
{
basePath: "mockproject",
workflow: "multi-workspace",
patternDetector: "workspace_vars",
changedFiles: []string{
"multiworkspace/workspace_vars/test1.tfvars",
"multiworkspace2/workspace_vars/test1.tfvars"},
expectedProjectFolder: []ProjectFolder{
{Path: "multiworkspace"},
{Path: "multiworkspace2"},
},
},
{
basePath: "mockproject",
workflow: "single-workspace",
patternDetector: "main.tf",
changedFiles: []string{"singleworkspace/main.tf", "file2"},
expectedProjectFolder: []ProjectFolder{
{Path: "singleworkspace"},
},
},
}

for _, test := range tests {
t.Run(test.workflow, func(t *testing.T) {
projectFolders, err := scanProjectFolders(test.basePath, test.workflow, test.patternDetector, test.changedFiles)
assert.NoError(t, err)
assert.NotEmpty(t, projectFolders) // Assuming there are valid project folders
assert.Equal(t, test.expectedProjectFolder, projectFolders)
})
}
}
File renamed without changes.
Empty file.
Empty file.
Empty file.

0 comments on commit a603c6c

Please sign in to comment.