Skip to content

Commit

Permalink
try to fix vendor test for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
osterman committed Dec 23, 2024
1 parent 1bceaa9 commit ac1a504
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions pkg/vender/component_vendor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,64 @@ func TestVendorComponentPullCommand(t *testing.T) {

componentType := "terraform"

// Helper function to ensure all paths are absolute
ensureAbsPath := func(path string) string {
absPath, err := filepath.Abs(path)
assert.Nil(t, err)
return absPath
}

// Test 'infra/vpc-flow-logs-bucket' component
component := "infra/vpc-flow-logs-bucket"
componentConfig, componentPath, err := e.ReadAndProcessComponentVendorConfigFile(atmosConfig, component, componentType)
assert.Nil(t, err)

componentPath = ensureAbsPath(componentPath)

err = e.ExecuteComponentVendorInternal(atmosConfig, componentConfig.Spec, component, componentPath, false)
assert.Nil(t, err)

// Check if the correct files were pulled and written to the correct folder
assert.FileExists(t, filepath.Join(componentPath, "context.tf"))
assert.FileExists(t, filepath.Join(componentPath, "main.tf"))
assert.FileExists(t, filepath.Join(componentPath, "outputs.tf"))
assert.FileExists(t, filepath.Join(componentPath, "providers.tf"))
assert.FileExists(t, filepath.Join(componentPath, "variables.tf"))
assert.FileExists(t, filepath.Join(componentPath, "versions.tf"))
filesToCheck := []string{
"context.tf", "main.tf", "outputs.tf",
"providers.tf", "variables.tf", "versions.tf",
}

for _, file := range filesToCheck {
assert.FileExists(t, filepath.Join(componentPath, file))
}

// Test 'infra/account-map' component
component = "infra/account-map"
componentConfig, componentPath, err = e.ReadAndProcessComponentVendorConfigFile(atmosConfig, component, componentType)
assert.Nil(t, err)

componentPath = ensureAbsPath(componentPath)

err = e.ExecuteComponentVendorInternal(atmosConfig, componentConfig.Spec, component, componentPath, false)
assert.Nil(t, err)

// Check if the correct files were pulled and written to the correct folder
assert.FileExists(t, filepath.Join(componentPath, "context.tf"))
assert.FileExists(t, filepath.Join(componentPath, "dynamic-roles.tf"))
assert.FileExists(t, filepath.Join(componentPath, "main.tf"))
assert.FileExists(t, filepath.Join(componentPath, "outputs.tf"))
assert.FileExists(t, filepath.Join(componentPath, "providers.tf"))
assert.FileExists(t, filepath.Join(componentPath, "README.md"))
assert.FileExists(t, filepath.Join(componentPath, "remote-state.tf"))
assert.FileExists(t, filepath.Join(componentPath, "variables.tf"))
assert.FileExists(t, filepath.Join(componentPath, "versions.tf"))
assert.FileExists(t, filepath.Join(componentPath, "modules", "iam-roles", "context.tf"))
assert.FileExists(t, filepath.Join(componentPath, "modules", "iam-roles", "main.tf"))
assert.FileExists(t, filepath.Join(componentPath, "modules", "iam-roles", "outputs.tf"))
assert.FileExists(t, filepath.Join(componentPath, "modules", "iam-roles", "variables.tf"))
assert.FileExists(t, filepath.Join(componentPath, "modules", "roles-to-principals", "context.tf"))
assert.FileExists(t, filepath.Join(componentPath, "modules", "roles-to-principals", "main.tf"))
assert.FileExists(t, filepath.Join(componentPath, "modules", "roles-to-principals", "outputs.tf"))
assert.FileExists(t, filepath.Join(componentPath, "modules", "roles-to-principals", "variables.tf"))
// Additional files to check
filesToCheck = append(filesToCheck,
"dynamic-roles.tf", "README.md", "remote-state.tf",
"modules/iam-roles/context.tf", "modules/iam-roles/main.tf",
"modules/iam-roles/outputs.tf", "modules/iam-roles/variables.tf",
"modules/roles-to-principals/context.tf", "modules/roles-to-principals/main.tf",
"modules/roles-to-principals/outputs.tf", "modules/roles-to-principals/variables.tf",
)

for _, file := range filesToCheck {
assert.FileExists(t, filepath.Join(componentPath, file))
}

// Delete the files and folders
assert.Nil(t, os.Remove(filepath.Join(componentPath, "context.tf")))
assert.Nil(t, os.Remove(filepath.Join(componentPath, "dynamic-roles.tf")))
assert.Nil(t, os.Remove(filepath.Join(componentPath, "main.tf")))
assert.Nil(t, os.Remove(filepath.Join(componentPath, "outputs.tf")))
assert.Nil(t, os.Remove(filepath.Join(componentPath, "providers.tf")))
assert.Nil(t, os.Remove(filepath.Join(componentPath, "README.md")))
assert.Nil(t, os.Remove(filepath.Join(componentPath, "remote-state.tf")))
assert.Nil(t, os.Remove(filepath.Join(componentPath, "variables.tf")))
assert.Nil(t, os.Remove(filepath.Join(componentPath, "versions.tf")))
assert.Nil(t, os.RemoveAll(filepath.Join(componentPath, "modules")))
for _, file := range filesToCheck {
err := os.Remove(filepath.Join(componentPath, file))
if err != nil && !os.IsNotExist(err) {
assert.Failf(t, "Failed to delete file", "Error: %v", err)
}
}

err = os.RemoveAll(filepath.Join(componentPath, "modules"))
assert.Nil(t, err)
}

0 comments on commit ac1a504

Please sign in to comment.