-
-
Notifications
You must be signed in to change notification settings - Fork 98
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 vendor pull directory creation issue #782
Open
Cerebrovinny
wants to merge
12
commits into
main
Choose a base branch
from
fix-vendor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+144
−1
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cf24006
folder creation vendor fix
Cerebrovinny 1b5f112
display error logic
Cerebrovinny 3159dbd
Revert "display error logic"
Cerebrovinny 59a9602
restore condition to continue vendor process if not exists
Cerebrovinny 2f825be
Merge branch 'main' into fix-vendor
aknysh 945e8de
handle empty stack yaml file configuration (#791)
haitham911 50ff73e
Set Default Schema to Remote Schema (#777)
haitham911 0f9cead
added better error handling
Cerebrovinny bdf89a3
Merge branch 'main' into fix-vendor
Cerebrovinny be6a6d0
Merge branch 'main' into fix-vendor
Cerebrovinny 2b50764
Merge branch 'main' into fix-vendor
aknysh aa87519
added vendor config integration tests
Cerebrovinny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package vender | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
e "github.com/cloudposse/atmos/internal/exec" | ||
"github.com/cloudposse/atmos/pkg/schema" | ||
) | ||
aknysh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func TestVendorConfigScenarios(t *testing.T) { | ||
testDir := t.TempDir() | ||
|
||
// Initialize CLI config with required paths | ||
cliConfig := schema.CliConfiguration{ | ||
BasePath: testDir, | ||
Components: schema.Components{ | ||
Terraform: schema.Terraform{ | ||
BasePath: "components/terraform", | ||
}, | ||
}, | ||
} | ||
cliConfig.Logs.Level = "Trace" | ||
|
||
// Setup test component directory | ||
componentPath := path.Join(testDir, "components", "terraform", "myapp") | ||
err := os.MkdirAll(componentPath, 0755) | ||
assert.Nil(t, err) | ||
|
||
// Test Case 1: vendor.yaml exists and component is defined in it | ||
t.Run("vendor.yaml exists with defined component", func(t *testing.T) { | ||
// Create vendor.yaml | ||
vendorYaml := `apiVersion: atmos/v1 | ||
kind: AtmosVendorConfig | ||
metadata: | ||
name: test-vendor-config | ||
spec: | ||
sources: | ||
- component: myapp | ||
source: github.com/cloudposse/terraform-null-label.git//exports?ref={{.Version}} | ||
version: 0.25.0 | ||
included_paths: | ||
- "**/*.tf" | ||
` | ||
vendorYamlPath := path.Join(testDir, "vendor.yaml") | ||
err := os.WriteFile(vendorYamlPath, []byte(vendorYaml), 0644) | ||
assert.Nil(t, err) | ||
|
||
// Test vendoring with component flag | ||
vendorConfig, exists, configFile, err := e.ReadAndProcessVendorConfigFile(cliConfig, vendorYamlPath) | ||
assert.Nil(t, err) | ||
assert.True(t, exists) | ||
assert.NotEmpty(t, configFile) | ||
|
||
// Verify the component exists in vendor config | ||
var found bool | ||
for _, source := range vendorConfig.Spec.Sources { | ||
if source.Component == "myapp" { | ||
found = true | ||
break | ||
} | ||
} | ||
assert.True(t, found, "Component 'myapp' should be defined in vendor.yaml") | ||
|
||
// Clean up | ||
err = os.Remove(vendorYamlPath) | ||
assert.Nil(t, err) | ||
}) | ||
|
||
// Test Case 2: No vendor.yaml but component.yaml exists | ||
t.Run("component.yaml exists without vendor.yaml", func(t *testing.T) { | ||
// Create component.yaml | ||
componentYaml := `apiVersion: atmos/v1 | ||
kind: ComponentVendorConfig | ||
metadata: | ||
name: myapp-vendor-config | ||
spec: | ||
source: | ||
uri: github.com/cloudposse/terraform-null-label.git//exports?ref={{.Version}} | ||
version: 0.25.0 | ||
` | ||
componentYamlPath := path.Join(componentPath, "component.yaml") | ||
err := os.WriteFile(componentYamlPath, []byte(componentYaml), 0644) | ||
assert.Nil(t, err) | ||
|
||
// Test component vendoring | ||
componentConfig, compPath, err := e.ReadAndProcessComponentVendorConfigFile(cliConfig, "myapp", "terraform") | ||
assert.Nil(t, err) | ||
assert.NotNil(t, componentConfig) | ||
assert.Equal(t, componentPath, compPath) | ||
|
||
// Clean up | ||
err = os.Remove(componentYamlPath) | ||
assert.Nil(t, err) | ||
}) | ||
|
||
// Test Case 3: Neither vendor.yaml nor component.yaml exists | ||
t.Run("no vendor.yaml or component.yaml", func(t *testing.T) { | ||
// Test vendoring with component flag | ||
vendorYamlPath := path.Join(testDir, "vendor.yaml") | ||
_, exists, _, err := e.ReadAndProcessVendorConfigFile(cliConfig, vendorYamlPath) | ||
assert.Nil(t, err) | ||
assert.False(t, exists) | ||
|
||
// Test component vendoring | ||
_, _, err = e.ReadAndProcessComponentVendorConfigFile(cliConfig, "myapp", "terraform") | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "does not exist") | ||
}) | ||
|
||
// Test Case 4: No component specified with vendor.yaml | ||
t.Run("no component specified with vendor.yaml", func(t *testing.T) { | ||
// Create vendor.yaml | ||
vendorYaml := `apiVersion: atmos/v1 | ||
kind: AtmosVendorConfig | ||
metadata: | ||
name: test-vendor-config | ||
spec: | ||
sources: | ||
- component: myapp | ||
source: github.com/cloudposse/terraform-null-label.git//exports?ref={{.Version}} | ||
version: 0.25.0 | ||
` | ||
vendorYamlPath := path.Join(testDir, "vendor.yaml") | ||
err := os.WriteFile(vendorYamlPath, []byte(vendorYaml), 0644) | ||
assert.Nil(t, err) | ||
|
||
// Test vendoring without component flag | ||
vendorConfig, exists, configFile, err := e.ReadAndProcessVendorConfigFile(cliConfig, vendorYamlPath) | ||
assert.Nil(t, err) | ||
assert.True(t, exists) | ||
assert.NotEmpty(t, configFile) | ||
assert.NotNil(t, vendorConfig.Spec.Sources) | ||
|
||
// Clean up | ||
err = os.Remove(vendorYamlPath) | ||
assert.Nil(t, err) | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.