Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix windows paths #878

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 52 additions & 51 deletions pkg/component/component_processor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package component

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -28,21 +29,21 @@ func TestComponentProcessor(t *testing.T) {
tenant1Ue2DevTestTestComponentBackendWorkspaceKeyPrefix := tenant1Ue2DevTestTestComponentBackend["workspace_key_prefix"].(string)
tenant1Ue2DevTestTestComponentRemoteStateBackendWorkspaceKeyPrefix := tenant1Ue2DevTestTestComponentRemoteStateBackend["workspace_key_prefix"].(string)
tenant1Ue2DevTestTestComponentDeps := tenant1Ue2DevTestTestComponent["deps"].([]any)
assert.Equal(t, "test-test-component", tenant1Ue2DevTestTestComponentBackendWorkspaceKeyPrefix)
assert.Equal(t, "test-test-component", tenant1Ue2DevTestTestComponentRemoteStateBackendWorkspaceKeyPrefix)
assert.Equal(t, "test/test-component", tenant1Ue2DevTestTestComponentBaseComponent)
assert.Equal(t, "tenant1-ue2-dev", tenant1Ue2DevTestTestComponentWorkspace)
assert.Equal(t, filepath.FromSlash("test-test-component"), tenant1Ue2DevTestTestComponentBackendWorkspaceKeyPrefix)
assert.Equal(t, filepath.FromSlash("test-test-component"), tenant1Ue2DevTestTestComponentRemoteStateBackendWorkspaceKeyPrefix)
assert.Equal(t, filepath.FromSlash("test/test-component"), tenant1Ue2DevTestTestComponentBaseComponent)
assert.Equal(t, filepath.FromSlash("tenant1-ue2-dev"), tenant1Ue2DevTestTestComponentWorkspace)
assert.Equal(t, 9, len(tenant1Ue2DevTestTestComponentDeps))
assert.Equal(t, "catalog/terraform/services/service-1", tenant1Ue2DevTestTestComponentDeps[0])
assert.Equal(t, "catalog/terraform/services/service-2", tenant1Ue2DevTestTestComponentDeps[1])
assert.Equal(t, "catalog/terraform/spacelift-and-backend-override-1", tenant1Ue2DevTestTestComponentDeps[2])
assert.Equal(t, "catalog/terraform/test-component", tenant1Ue2DevTestTestComponentDeps[3])
assert.Equal(t, "mixins/region/us-east-2", tenant1Ue2DevTestTestComponentDeps[4])
assert.Equal(t, "mixins/stage/dev", tenant1Ue2DevTestTestComponentDeps[5])
assert.Equal(t, "orgs/cp/_defaults", tenant1Ue2DevTestTestComponentDeps[6])
assert.Equal(t, "orgs/cp/tenant1/_defaults", tenant1Ue2DevTestTestComponentDeps[7])
assert.Equal(t, "orgs/cp/tenant1/dev/us-east-2", tenant1Ue2DevTestTestComponentDeps[8])
assert.Equal(t, "tenant1-ue2-dev", tenant1Ue2DevTestTestComponentTerraformWorkspace)
assert.Equal(t, filepath.FromSlash("catalog/terraform/services/service-1"), tenant1Ue2DevTestTestComponentDeps[0])
assert.Equal(t, filepath.FromSlash("catalog/terraform/services/service-2"), tenant1Ue2DevTestTestComponentDeps[1])
assert.Equal(t, filepath.FromSlash("catalog/terraform/spacelift-and-backend-override-1"), tenant1Ue2DevTestTestComponentDeps[2])
assert.Equal(t, filepath.FromSlash("catalog/terraform/test-component"), tenant1Ue2DevTestTestComponentDeps[3])
assert.Equal(t, filepath.FromSlash("mixins/region/us-east-2"), tenant1Ue2DevTestTestComponentDeps[4])
assert.Equal(t, filepath.FromSlash("mixins/stage/dev"), tenant1Ue2DevTestTestComponentDeps[5])
assert.Equal(t, filepath.FromSlash("orgs/cp/_defaults"), tenant1Ue2DevTestTestComponentDeps[6])
assert.Equal(t, filepath.FromSlash("orgs/cp/tenant1/_defaults"), tenant1Ue2DevTestTestComponentDeps[7])
assert.Equal(t, filepath.FromSlash("orgs/cp/tenant1/dev/us-east-2"), tenant1Ue2DevTestTestComponentDeps[8])
assert.Equal(t, filepath.FromSlash("tenant1-ue2-dev"), tenant1Ue2DevTestTestComponentTerraformWorkspace)

var tenant1Ue2DevTestTestComponent2 map[string]any
component = "test/test-component"
Expand All @@ -59,21 +60,21 @@ func TestComponentProcessor(t *testing.T) {
tenant1Ue2DevTestTestComponentBackendWorkspaceKeyPrefix2 := tenant1Ue2DevTestTestComponentBackend2["workspace_key_prefix"].(string)
tenant1Ue2DevTestTestComponentRemoteStateBackendWorkspaceKeyPrefix2 := tenant1Ue2DevTestTestComponentRemoteStateBackend2["workspace_key_prefix"].(string)
tenant1Ue2DevTestTestComponentDeps2 := tenant1Ue2DevTestTestComponent2["deps"].([]any)
assert.Equal(t, "test-test-component", tenant1Ue2DevTestTestComponentBackendWorkspaceKeyPrefix2)
assert.Equal(t, "test-test-component", tenant1Ue2DevTestTestComponentRemoteStateBackendWorkspaceKeyPrefix2)
assert.Equal(t, "test/test-component", tenant1Ue2DevTestTestComponentBaseComponent2)
assert.Equal(t, "tenant1-ue2-dev", tenant1Ue2DevTestTestComponentWorkspace2)
assert.Equal(t, filepath.FromSlash("test-test-component"), tenant1Ue2DevTestTestComponentBackendWorkspaceKeyPrefix2)
assert.Equal(t, filepath.FromSlash("test-test-component"), tenant1Ue2DevTestTestComponentRemoteStateBackendWorkspaceKeyPrefix2)
assert.Equal(t, filepath.FromSlash("test/test-component"), tenant1Ue2DevTestTestComponentBaseComponent2)
assert.Equal(t, filepath.FromSlash("tenant1-ue2-dev"), tenant1Ue2DevTestTestComponentWorkspace2)
assert.Equal(t, 9, len(tenant1Ue2DevTestTestComponentDeps2))
assert.Equal(t, "catalog/terraform/services/service-1", tenant1Ue2DevTestTestComponentDeps2[0])
assert.Equal(t, "catalog/terraform/services/service-2", tenant1Ue2DevTestTestComponentDeps2[1])
assert.Equal(t, "catalog/terraform/spacelift-and-backend-override-1", tenant1Ue2DevTestTestComponentDeps2[2])
assert.Equal(t, "catalog/terraform/test-component", tenant1Ue2DevTestTestComponentDeps2[3])
assert.Equal(t, filepath.FromSlash("catalog/terraform/services/service-1"), tenant1Ue2DevTestTestComponentDeps2[0])
assert.Equal(t, filepath.FromSlash("catalog/terraform/services/service-2"), tenant1Ue2DevTestTestComponentDeps2[1])
assert.Equal(t, filepath.FromSlash("catalog/terraform/spacelift-and-backend-override-1"), tenant1Ue2DevTestTestComponentDeps2[2])
assert.Equal(t, filepath.FromSlash("catalog/terraform/test-component"), tenant1Ue2DevTestTestComponentDeps2[3])
assert.Equal(t, "mixins/region/us-east-2", tenant1Ue2DevTestTestComponentDeps2[4])
assert.Equal(t, "mixins/stage/dev", tenant1Ue2DevTestTestComponentDeps2[5])
assert.Equal(t, "orgs/cp/_defaults", tenant1Ue2DevTestTestComponentDeps2[6])
assert.Equal(t, "orgs/cp/tenant1/_defaults", tenant1Ue2DevTestTestComponentDeps2[7])
assert.Equal(t, "orgs/cp/tenant1/dev/us-east-2", tenant1Ue2DevTestTestComponentDeps2[8])
assert.Equal(t, "tenant1-ue2-dev", tenant1Ue2DevTestTestComponentTerraformWorkspace2)
assert.Equal(t, filepath.FromSlash("mixins/stage/dev"), tenant1Ue2DevTestTestComponentDeps2[5])
assert.Equal(t, filepath.FromSlash("orgs/cp/_defaults"), tenant1Ue2DevTestTestComponentDeps2[6])
assert.Equal(t, filepath.FromSlash("orgs/cp/tenant1/_defaults"), tenant1Ue2DevTestTestComponentDeps2[7])
assert.Equal(t, filepath.FromSlash("orgs/cp/tenant1/dev/us-east-2"), tenant1Ue2DevTestTestComponentDeps2[8])
assert.Equal(t, filepath.FromSlash("tenant1-ue2-dev"), tenant1Ue2DevTestTestComponentTerraformWorkspace2)

yamlConfig, err = u.ConvertToYAML(tenant1Ue2DevTestTestComponent)
assert.Nil(t, err)
Expand All @@ -91,21 +92,21 @@ func TestComponentProcessor(t *testing.T) {
tenant1Ue2DevTestTestComponentOverrideComponentDeps := tenant1Ue2DevTestTestComponentOverrideComponent["deps"].([]any)
tenant1Ue2DevTestTestComponentOverrideComponentRemoteStateBackend := tenant1Ue2DevTestTestComponentOverrideComponent["remote_state_backend"].(map[string]any)
tenant1Ue2DevTestTestComponentOverrideComponentRemoteStateBackendVal2 := tenant1Ue2DevTestTestComponentOverrideComponentRemoteStateBackend["val2"].(string)
assert.Equal(t, "test-test-component", tenant1Ue2DevTestTestComponentOverrideComponentBackendWorkspaceKeyPrefix)
assert.Equal(t, "test/test-component", tenant1Ue2DevTestTestComponentOverrideComponentBaseComponent)
assert.Equal(t, "test-component-override-workspace-override", tenant1Ue2DevTestTestComponentOverrideComponentWorkspace)
assert.Equal(t, filepath.FromSlash("test-test-component"), tenant1Ue2DevTestTestComponentOverrideComponentBackendWorkspaceKeyPrefix)
assert.Equal(t, filepath.FromSlash("test/test-component"), tenant1Ue2DevTestTestComponentOverrideComponentBaseComponent)
assert.Equal(t, filepath.FromSlash("test-component-override-workspace-override"), tenant1Ue2DevTestTestComponentOverrideComponentWorkspace)

assert.Equal(t, 10, len(tenant1Ue2DevTestTestComponentOverrideComponentDeps))
assert.Equal(t, "catalog/terraform/services/service-1-override", tenant1Ue2DevTestTestComponentOverrideComponentDeps[0])
assert.Equal(t, "catalog/terraform/services/service-2-override", tenant1Ue2DevTestTestComponentOverrideComponentDeps[1])
assert.Equal(t, "catalog/terraform/spacelift-and-backend-override-1", tenant1Ue2DevTestTestComponentOverrideComponentDeps[2])
assert.Equal(t, "catalog/terraform/test-component", tenant1Ue2DevTestTestComponentOverrideComponentDeps[3])
assert.Equal(t, "catalog/terraform/test-component-override", tenant1Ue2DevTestTestComponentOverrideComponentDeps[4])
assert.Equal(t, "mixins/region/us-east-2", tenant1Ue2DevTestTestComponentOverrideComponentDeps[5])
assert.Equal(t, "mixins/stage/dev", tenant1Ue2DevTestTestComponentOverrideComponentDeps[6])
assert.Equal(t, "orgs/cp/_defaults", tenant1Ue2DevTestTestComponentOverrideComponentDeps[7])
assert.Equal(t, "orgs/cp/tenant1/_defaults", tenant1Ue2DevTestTestComponentOverrideComponentDeps[8])
assert.Equal(t, "orgs/cp/tenant1/dev/us-east-2", tenant1Ue2DevTestTestComponentOverrideComponentDeps[9])
assert.Equal(t, filepath.FromSlash("catalog/terraform/services/service-1-override"), tenant1Ue2DevTestTestComponentOverrideComponentDeps[0])
assert.Equal(t, filepath.FromSlash("catalog/terraform/services/service-2-override"), tenant1Ue2DevTestTestComponentOverrideComponentDeps[1])
assert.Equal(t, filepath.FromSlash("catalog/terraform/spacelift-and-backend-override-1"), tenant1Ue2DevTestTestComponentOverrideComponentDeps[2])
assert.Equal(t, filepath.FromSlash("catalog/terraform/test-component"), tenant1Ue2DevTestTestComponentOverrideComponentDeps[3])
assert.Equal(t, filepath.FromSlash("catalog/terraform/test-component-override"), tenant1Ue2DevTestTestComponentOverrideComponentDeps[4])
assert.Equal(t, filepath.FromSlash("mixins/region/us-east-2"), tenant1Ue2DevTestTestComponentOverrideComponentDeps[5])
assert.Equal(t, filepath.FromSlash("mixins/stage/dev"), tenant1Ue2DevTestTestComponentOverrideComponentDeps[6])
assert.Equal(t, filepath.FromSlash("orgs/cp/_defaults"), tenant1Ue2DevTestTestComponentOverrideComponentDeps[7])
assert.Equal(t, filepath.FromSlash("orgs/cp/tenant1/_defaults"), tenant1Ue2DevTestTestComponentOverrideComponentDeps[8])
assert.Equal(t, filepath.FromSlash("orgs/cp/tenant1/dev/us-east-2"), tenant1Ue2DevTestTestComponentOverrideComponentDeps[9])

assert.Equal(t, "2", tenant1Ue2DevTestTestComponentOverrideComponentRemoteStateBackendVal2)

Expand Down Expand Up @@ -149,17 +150,17 @@ func TestComponentProcessor(t *testing.T) {
tenant1Ue2DevTestTestComponentOverrideComponent3Deps := tenant1Ue2DevTestTestComponentOverrideComponent3["deps"].([]any)

assert.Equal(t, 11, len(tenant1Ue2DevTestTestComponentOverrideComponent3Deps))
assert.Equal(t, "catalog/terraform/mixins/test-2", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[0])
assert.Equal(t, "catalog/terraform/services/service-1-override-2", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[1])
assert.Equal(t, "catalog/terraform/services/service-2-override-2", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[2])
assert.Equal(t, "catalog/terraform/spacelift-and-backend-override-1", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[3])
assert.Equal(t, "catalog/terraform/test-component", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[4])
assert.Equal(t, "catalog/terraform/test-component-override-3", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[5])
assert.Equal(t, "mixins/region/us-east-2", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[6])
assert.Equal(t, "mixins/stage/dev", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[7])
assert.Equal(t, "orgs/cp/_defaults", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[8])
assert.Equal(t, "orgs/cp/tenant1/_defaults", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[9])
assert.Equal(t, "orgs/cp/tenant1/dev/us-east-2", tenant1Ue2DevTestTestComponentOverrideComponent3Deps[10])
assert.Equal(t, filepath.FromSlash("catalog/terraform/mixins/test-2"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[0])
assert.Equal(t, filepath.FromSlash("catalog/terraform/services/service-1-override-2"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[1])
assert.Equal(t, filepath.FromSlash("catalog/terraform/services/service-2-override-2"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[2])
assert.Equal(t, filepath.FromSlash("catalog/terraform/spacelift-and-backend-override-1"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[3])
assert.Equal(t, filepath.FromSlash("catalog/terraform/test-component"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[4])
assert.Equal(t, filepath.FromSlash("catalog/terraform/test-component-override-3"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[5])
assert.Equal(t, filepath.FromSlash("mixins/region/us-east-2"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[6])
assert.Equal(t, filepath.FromSlash("mixins/stage/dev"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[7])
assert.Equal(t, filepath.FromSlash("orgs/cp/_defaults"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[8])
assert.Equal(t, filepath.FromSlash("orgs/cp/tenant1/_defaults"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[9])
assert.Equal(t, filepath.FromSlash("orgs/cp/tenant1/dev/us-east-2"), tenant1Ue2DevTestTestComponentOverrideComponent3Deps[10])
}

func TestComponentProcessorHierarchicalInheritance(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"testing"

"github.com/fatih/color"
Expand Down Expand Up @@ -147,7 +148,9 @@ func TestLogger_Error(t *testing.T) {
}

func TestLogger_FileLogging(t *testing.T) {
tempFile := "/tmp/test.log"
tempDir := t.TempDir()
tempFile := filepath.Join(tempDir, "test.log")

defer os.Remove(tempFile)

logger, _ := NewLogger(LogLevelInfo, tempFile)
Expand Down
5 changes: 4 additions & 1 deletion pkg/utils/glob_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func GetGlobMatches(pattern string) ([]string, error) {
return strings.Split(existingMatches.(string), ","), nil
}

base, cleanPattern := doublestar.SplitPattern(pattern)
// Convert the pattern to use / as the separator regardless of platform
allOsSafePattern := filepath.ToSlash(pattern)

base, cleanPattern := doublestar.SplitPattern(allOsSafePattern)
f := os.DirFS(base)

matches, err := doublestar.Glob(f, cleanPattern)
Expand Down
Loading