Skip to content

Commit 5c0c94e

Browse files
wip
Signed-off-by: Blake Pettersson <[email protected]>
1 parent e32d84d commit 5c0c94e

File tree

5 files changed

+53
-22
lines changed

5 files changed

+53
-22
lines changed

util/app/discovery/discovery.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func cmpSupports(ctx context.Context, pluginSockFilePath string, appPath string,
189189
log.WithFields(log.Fields{
190190
common.SecurityField: common.SecurityMedium,
191191
common.SecurityCWEField: common.SecurityCWEMissingReleaseOfFileDescriptor,
192-
}).Errorf("repository %s is not the match because %v", repoPath, err)
192+
}).Errorf("repository %s is not the match because %v", repoPath.Name(), err)
193193
utilio.Close(conn)
194194
return nil, nil, false
195195
}
@@ -202,7 +202,7 @@ func cmpSupports(ctx context.Context, pluginSockFilePath string, appPath string,
202202
log.WithFields(log.Fields{
203203
common.SecurityField: common.SecurityLow,
204204
common.SecurityCWEField: common.SecurityCWEMissingReleaseOfFileDescriptor,
205-
}).Debugf("Response from socket file %s does not support %v", fileName, repoPath)
205+
}).Debugf("Response from socket file %s does not support %v", fileName, repoPath.Name())
206206
utilio.Close(conn)
207207
return nil, nil, false
208208
}

util/app/discovery/discovery_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package discovery
22

33
import (
4+
"os"
45
"testing"
56

67
"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
@@ -10,7 +11,9 @@ import (
1011
)
1112

1213
func TestDiscover(t *testing.T) {
13-
apps, err := Discover(t.Context(), "./testdata", "./testdata", map[string]bool{}, []string{}, []string{})
14+
repoRoot, err := os.OpenRoot("./testdata")
15+
require.NoError(t, err)
16+
apps, err := Discover(t.Context(), "./testdata", repoRoot, map[string]bool{}, []string{}, []string{})
1417
require.NoError(t, err)
1518
assert.Equal(t, map[string]string{
1619
"foo": "Kustomize",
@@ -19,15 +22,17 @@ func TestDiscover(t *testing.T) {
1922
}
2023

2124
func TestAppType(t *testing.T) {
22-
appType, err := AppType(t.Context(), "./testdata/foo", "./testdata", map[string]bool{}, []string{}, []string{})
25+
repoRoot, err := os.OpenRoot("./testdata")
26+
require.NoError(t, err)
27+
appType, err := AppType(t.Context(), "./testdata/foo", repoRoot, map[string]bool{}, []string{}, []string{})
2328
require.NoError(t, err)
2429
assert.Equal(t, "Kustomize", appType)
2530

26-
appType, err = AppType(t.Context(), "./testdata/baz", "./testdata", map[string]bool{}, []string{}, []string{})
31+
appType, err = AppType(t.Context(), "./testdata/baz", repoRoot, map[string]bool{}, []string{}, []string{})
2732
require.NoError(t, err)
2833
assert.Equal(t, "Helm", appType)
2934

30-
appType, err = AppType(t.Context(), "./testdata", "./testdata", map[string]bool{}, []string{}, []string{})
35+
appType, err = AppType(t.Context(), "./testdata", repoRoot, map[string]bool{}, []string{}, []string{})
3136
require.NoError(t, err)
3237
assert.Equal(t, "Directory", appType)
3338
}
@@ -37,15 +42,17 @@ func TestAppType_Disabled(t *testing.T) {
3742
string(v1alpha1.ApplicationSourceTypeKustomize): false,
3843
string(v1alpha1.ApplicationSourceTypeHelm): false,
3944
}
40-
appType, err := AppType(t.Context(), "./testdata/foo", "./testdata", enableManifestGeneration, []string{}, []string{})
45+
repoRoot, err := os.OpenRoot("./testdata")
46+
require.NoError(t, err)
47+
appType, err := AppType(t.Context(), "./testdata/foo", repoRoot, enableManifestGeneration, []string{}, []string{})
4148
require.NoError(t, err)
4249
assert.Equal(t, "Directory", appType)
4350

44-
appType, err = AppType(t.Context(), "./testdata/baz", "./testdata", enableManifestGeneration, []string{}, []string{})
51+
appType, err = AppType(t.Context(), "./testdata/baz", repoRoot, enableManifestGeneration, []string{}, []string{})
4552
require.NoError(t, err)
4653
assert.Equal(t, "Directory", appType)
4754

48-
appType, err = AppType(t.Context(), "./testdata", "./testdata", enableManifestGeneration, []string{}, []string{})
55+
appType, err = AppType(t.Context(), "./testdata", repoRoot, enableManifestGeneration, []string{}, []string{})
4956
require.NoError(t, err)
5057
assert.Equal(t, "Directory", appType)
5158
}

util/cmp/stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func GetCompressedRepoAndMetadata(rootPath *os.Root, appPath string, env []strin
114114
return nil, nil, fmt.Errorf("error compressing repo files: %w", err)
115115
}
116116
if filesWritten == 0 {
117-
return nil, nil, fmt.Errorf("no files to send(%s)", rootPath)
117+
return nil, nil, fmt.Errorf("no files to send(%s)", rootPath.Name())
118118
}
119119
if opt != nil && opt.tarDoneChan != nil {
120120
opt.tarDoneChan <- true

util/cmp/stream_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ func (m *streamMock) sendFile(ctx context.Context, t *testing.T, basedir string,
8787
defer func() {
8888
m.done <- true
8989
}()
90-
err := cmp.SendRepoStream(ctx, basedir, basedir, sender, env, excludedGlobs)
90+
rootPath, err := os.OpenRoot(basedir)
91+
require.NoError(t, err)
92+
err = cmp.SendRepoStream(ctx, basedir, rootPath, sender, env, excludedGlobs)
9193
require.NoError(t, err)
9294
}
9395

util/kustomize/kustomize_test.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ func TestKustomizeBuild(t *testing.T) {
4444
namePrefix := "namePrefix-"
4545
nameSuffix := "-nameSuffix"
4646
namespace := "custom-namespace"
47-
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "", "", "")
47+
repoRoot, err := os.OpenRoot(appPath)
48+
require.NoError(t, err)
49+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", "", "", "")
4850
env := &v1alpha1.Env{
4951
&v1alpha1.EnvEntry{Name: "ARGOCD_APP_NAME", Value: "argo-cd-tests"},
5052
}
@@ -128,7 +130,9 @@ func TestKustomizeBuild(t *testing.T) {
128130
func TestFailKustomizeBuild(t *testing.T) {
129131
appPath, err := testDataDir(t, kustomization1)
130132
require.NoError(t, err)
131-
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "", "", "")
133+
repoRoot, err := os.OpenRoot(appPath)
134+
require.NoError(t, err)
135+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", "", "", "")
132136
kustomizeSource := v1alpha1.ApplicationSourceKustomize{
133137
Replicas: []v1alpha1.KustomizeReplica{
134138
{
@@ -237,7 +241,9 @@ func TestKustomizeBuildForceCommonLabels(t *testing.T) {
237241
for _, tc := range testCases {
238242
appPath, err := testDataDir(t, tc.TestData)
239243
require.NoError(t, err)
240-
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "", "", "")
244+
repoRoot, err := os.OpenRoot(appPath)
245+
require.NoError(t, err)
246+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", "", "", "")
241247
objs, _, _, err := kustomize.Build(&tc.KustomizeSource, nil, tc.Env, nil)
242248
switch tc.ExpectErr {
243249
case true:
@@ -329,7 +335,9 @@ func TestKustomizeBuildForceCommonAnnotations(t *testing.T) {
329335
for _, tc := range testCases {
330336
appPath, err := testDataDir(t, tc.TestData)
331337
require.NoError(t, err)
332-
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "", "", "")
338+
repoRoot, err := os.OpenRoot(appPath)
339+
require.NoError(t, err)
340+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", "", "", "")
333341
objs, _, _, err := kustomize.Build(&tc.KustomizeSource, nil, tc.Env, nil)
334342
switch tc.ExpectErr {
335343
case true:
@@ -435,7 +443,9 @@ func TestKustomizeLabelWithoutSelector(t *testing.T) {
435443
for _, tc := range testCases {
436444
appPath, err := testDataDir(t, tc.TestData)
437445
require.NoError(t, err)
438-
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "", "", "")
446+
repoRoot, err := os.OpenRoot(appPath)
447+
require.NoError(t, err)
448+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", "", "", "")
439449
objs, _, _, err := kustomize.Build(&tc.KustomizeSource, nil, tc.Env, nil)
440450

441451
switch tc.ExpectErr {
@@ -465,7 +475,9 @@ func TestKustomizeCustomVersion(t *testing.T) {
465475
kustomizePath, err := testDataDir(t, kustomization4)
466476
require.NoError(t, err)
467477
envOutputFile := kustomizePath + "/env_output"
468-
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", kustomizePath+"/kustomize.special", "", "")
478+
repoRoot, err := os.OpenRoot(appPath)
479+
require.NoError(t, err)
480+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", kustomizePath+"/kustomize.special", "", "")
469481
kustomizeSource := v1alpha1.ApplicationSourceKustomize{
470482
Version: "special",
471483
}
@@ -487,7 +499,9 @@ func TestKustomizeCustomVersion(t *testing.T) {
487499
func TestKustomizeBuildComponents(t *testing.T) {
488500
appPath, err := testDataDir(t, kustomization6)
489501
require.NoError(t, err)
490-
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "", "", "")
502+
repoRoot, err := os.OpenRoot(appPath)
503+
require.NoError(t, err)
504+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", "", "", "")
491505

492506
kustomizeSource := v1alpha1.ApplicationSourceKustomize{
493507
Components: []string{"./components", "./missing-components"},
@@ -517,7 +531,9 @@ func TestKustomizeBuildComponentsMonoRepo(t *testing.T) {
517531
rootPath, err := testDataDir(t, kustomization9)
518532
require.NoError(t, err)
519533
appPath := path.Join(rootPath, "envs/inseng-pdx-egert-sandbox/namespaces/inst-system/apps/hello-world")
520-
kustomize := NewKustomizeApp(rootPath, appPath, git.NopCreds{}, "", "", "", "")
534+
repoRoot, err := os.OpenRoot(rootPath)
535+
require.NoError(t, err)
536+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", "", "", "")
521537
kustomizeSource := v1alpha1.ApplicationSourceKustomize{
522538
Components: []string{"../../../../../../kustomize/components/all"},
523539
IgnoreMissingComponents: true,
@@ -541,7 +557,9 @@ func TestKustomizeBuildComponentsMonoRepo(t *testing.T) {
541557
func TestKustomizeBuildPatches(t *testing.T) {
542558
appPath, err := testDataDir(t, kustomization5)
543559
require.NoError(t, err)
544-
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "", "", "")
560+
repoRoot, err := os.OpenRoot(appPath)
561+
require.NoError(t, err)
562+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", "", "", "")
545563

546564
kustomizeSource := v1alpha1.ApplicationSourceKustomize{
547565
Patches: []v1alpha1.KustomizePatch{
@@ -593,7 +611,9 @@ func TestKustomizeBuildPatches(t *testing.T) {
593611
func TestFailKustomizeBuildPatches(t *testing.T) {
594612
appPath, err := testDataDir(t, kustomization8)
595613
require.NoError(t, err)
596-
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "", "", "")
614+
repoRoot, err := os.OpenRoot(appPath)
615+
require.NoError(t, err)
616+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", "", "", "")
597617

598618
kustomizeSource := v1alpha1.ApplicationSourceKustomize{
599619
Patches: []v1alpha1.KustomizePatch{
@@ -618,7 +638,9 @@ func TestFailKustomizeBuildPatches(t *testing.T) {
618638
func TestKustomizeBuildComponentsNoFoundComponents(t *testing.T) {
619639
appPath, err := testDataDir(t, kustomization6)
620640
require.NoError(t, err)
621-
kustomize := NewKustomizeApp(appPath, appPath, git.NopCreds{}, "", "", "", "")
641+
repoRoot, err := os.OpenRoot(appPath)
642+
require.NoError(t, err)
643+
kustomize := NewKustomizeApp(repoRoot, appPath, git.NopCreds{}, "", "", "", "")
622644

623645
// Test with non-existent components and IgnoreMissingComponents = true
624646
// This should result in foundComponents being empty, so no "edit add component" command should be executed

0 commit comments

Comments
 (0)