-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: missing path segments for git file generator (#9839)
* fix: missing path segments for git file generator given the path: /one/two/file.yaml This change adds the params: path[1]=two path.filename=file.yaml path.filenameNormalized The use case is for symmetry with other generators (e.g., merge with a directory generator using the key path[1]). As no existing parameter values are changed it should be non-breaking. Signed-off-by: Noah Perks Sloan <[email protected]> * fix: expose all path elements for directory generator This makes it consistent with the files generator and removes un-intuitive behavior without any breaking change. docs: clarify - can use either baseName or nth path element docs: use "directory", like the name of the generator, where "folder" was mentioned Signed-off-by: Noah Perks Sloan <[email protected]>
- Loading branch information
Showing
3 changed files
with
71 additions
and
20 deletions.
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 |
---|---|---|
|
@@ -47,6 +47,28 @@ func (a argoCDServiceMock) GetDirectories(ctx context.Context, repoURL string, r | |
return args.Get(0).([]string), args.Error(1) | ||
} | ||
|
||
func Test_generateParamsFromGitFile(t *testing.T) { | ||
params, err := (*GitGenerator)(nil).generateParamsFromGitFile("path/dir/file_name.yaml", []byte(` | ||
foo: | ||
bar: baz | ||
`)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, []map[string]string{ | ||
{ | ||
"foo.bar": "baz", | ||
"path": "path/dir", | ||
"path.basename": "dir", | ||
"path.filename": "file_name.yaml", | ||
"path.basenameNormalized": "dir", | ||
"path.filenameNormalized": "file-name.yaml", | ||
"path[0]": "path", | ||
"path[1]": "dir", | ||
}, | ||
}, params) | ||
} | ||
|
||
func TestGitGenerateParamsFromDirectories(t *testing.T) { | ||
|
||
cases := []struct { | ||
|
@@ -68,9 +90,9 @@ func TestGitGenerateParamsFromDirectories(t *testing.T) { | |
}, | ||
repoError: nil, | ||
expected: []map[string]string{ | ||
{"path": "app1", "path.basename": "app1", "path.basenameNormalized": "app1"}, | ||
{"path": "app2", "path.basename": "app2", "path.basenameNormalized": "app2"}, | ||
{"path": "app_3", "path.basename": "app_3", "path.basenameNormalized": "app-3"}, | ||
{"path": "app1", "path.basename": "app1", "path.basenameNormalized": "app1", "path[0]": "app1"}, | ||
{"path": "app2", "path.basename": "app2", "path.basenameNormalized": "app2", "path[0]": "app2"}, | ||
{"path": "app_3", "path.basename": "app_3", "path.basenameNormalized": "app-3", "path[0]": "app_3"}, | ||
}, | ||
expectedError: nil, | ||
}, | ||
|
@@ -85,8 +107,8 @@ func TestGitGenerateParamsFromDirectories(t *testing.T) { | |
}, | ||
repoError: nil, | ||
expected: []map[string]string{ | ||
{"path": "p1/app2", "path.basename": "app2", "path[0]": "p1", "path.basenameNormalized": "app2"}, | ||
{"path": "p1/p2/app3", "path.basename": "app3", "path[0]": "p1", "path[1]": "p2", "path.basenameNormalized": "app3"}, | ||
{"path": "p1/app2", "path.basename": "app2", "path[0]": "p1", "path[1]": "app2", "path.basenameNormalized": "app2"}, | ||
{"path": "p1/p2/app3", "path.basename": "app3", "path[0]": "p1", "path[1]": "p2", "path[2]": "app3", "path.basenameNormalized": "app3"}, | ||
}, | ||
expectedError: nil, | ||
}, | ||
|
@@ -102,9 +124,9 @@ func TestGitGenerateParamsFromDirectories(t *testing.T) { | |
}, | ||
repoError: nil, | ||
expected: []map[string]string{ | ||
{"path": "app1", "path.basename": "app1", "path.basenameNormalized": "app1"}, | ||
{"path": "app2", "path.basename": "app2", "path.basenameNormalized": "app2"}, | ||
{"path": "p2/app3", "path.basename": "app3", "path[0]": "p2", "path.basenameNormalized": "app3"}, | ||
{"path": "app1", "path.basename": "app1", "path[0]": "app1", "path.basenameNormalized": "app1"}, | ||
{"path": "app2", "path.basename": "app2", "path[0]": "app2", "path.basenameNormalized": "app2"}, | ||
{"path": "p2/app3", "path.basename": "app3", "path[0]": "p2", "path[1]": "app3", "path.basenameNormalized": "app3"}, | ||
}, | ||
expectedError: nil, | ||
}, | ||
|
@@ -120,9 +142,9 @@ func TestGitGenerateParamsFromDirectories(t *testing.T) { | |
}, | ||
repoError: nil, | ||
expected: []map[string]string{ | ||
{"path": "app1", "path.basename": "app1", "path.basenameNormalized": "app1"}, | ||
{"path": "app2", "path.basename": "app2", "path.basenameNormalized": "app2"}, | ||
{"path": "p2/app3", "path.basename": "app3", "path[0]": "p2", "path.basenameNormalized": "app3"}, | ||
{"path": "app1", "path.basename": "app1", "path[0]": "app1", "path.basenameNormalized": "app1"}, | ||
{"path": "app2", "path.basename": "app2", "path[0]": "app2", "path.basenameNormalized": "app2"}, | ||
{"path": "p2/app3", "path.basename": "app3", "path[0]": "p2", "path[1]": "app3", "path.basenameNormalized": "app3"}, | ||
}, | ||
expectedError: nil, | ||
}, | ||
|
@@ -238,7 +260,10 @@ func TestGitGenerateParamsFromFiles(t *testing.T) { | |
"path": "cluster-config/production", | ||
"path.basename": "production", | ||
"path[0]": "cluster-config", | ||
"path[1]": "production", | ||
"path.basenameNormalized": "production", | ||
"path.filename": "config.json", | ||
"path.filenameNormalized": "config.json", | ||
}, | ||
{ | ||
"cluster.owner": "[email protected]", | ||
|
@@ -247,7 +272,10 @@ func TestGitGenerateParamsFromFiles(t *testing.T) { | |
"path": "cluster-config/staging", | ||
"path.basename": "staging", | ||
"path[0]": "cluster-config", | ||
"path[1]": "staging", | ||
"path.basenameNormalized": "staging", | ||
"path.filename": "config.json", | ||
"path.filenameNormalized": "config.json", | ||
}, | ||
}, | ||
expectedError: nil, | ||
|
@@ -305,7 +333,10 @@ func TestGitGenerateParamsFromFiles(t *testing.T) { | |
"path": "cluster-config/production", | ||
"path.basename": "production", | ||
"path[0]": "cluster-config", | ||
"path[1]": "production", | ||
"path.basenameNormalized": "production", | ||
"path.filename": "config.json", | ||
"path.filenameNormalized": "config.json", | ||
}, | ||
{ | ||
"cluster.owner": "[email protected]", | ||
|
@@ -314,7 +345,10 @@ func TestGitGenerateParamsFromFiles(t *testing.T) { | |
"path": "cluster-config/production", | ||
"path.basename": "production", | ||
"path[0]": "cluster-config", | ||
"path[1]": "production", | ||
"path.basenameNormalized": "production", | ||
"path.filename": "config.json", | ||
"path.filenameNormalized": "config.json", | ||
}, | ||
}, | ||
expectedError: nil, | ||
|
@@ -353,7 +387,10 @@ cluster: | |
"path": "cluster-config/production", | ||
"path.basename": "production", | ||
"path[0]": "cluster-config", | ||
"path[1]": "production", | ||
"path.basenameNormalized": "production", | ||
"path.filename": "config.yaml", | ||
"path.filenameNormalized": "config.yaml", | ||
}, | ||
{ | ||
"cluster.owner": "[email protected]", | ||
|
@@ -362,7 +399,10 @@ cluster: | |
"path": "cluster-config/staging", | ||
"path.basename": "staging", | ||
"path[0]": "cluster-config", | ||
"path[1]": "staging", | ||
"path.basenameNormalized": "staging", | ||
"path.filename": "config.yaml", | ||
"path.filenameNormalized": "config.yaml", | ||
}, | ||
}, | ||
expectedError: nil, | ||
|
@@ -393,7 +433,10 @@ cluster: | |
"path": "cluster-config/production", | ||
"path.basename": "production", | ||
"path[0]": "cluster-config", | ||
"path[1]": "production", | ||
"path.basenameNormalized": "production", | ||
"path.filename": "config.yaml", | ||
"path.filenameNormalized": "config.yaml", | ||
}, | ||
{ | ||
"cluster.owner": "[email protected]", | ||
|
@@ -402,7 +445,10 @@ cluster: | |
"path": "cluster-config/production", | ||
"path.basename": "production", | ||
"path[0]": "cluster-config", | ||
"path[1]": "production", | ||
"path.basenameNormalized": "production", | ||
"path.filename": "config.yaml", | ||
"path.filenameNormalized": "config.yaml", | ||
}, | ||
}, | ||
expectedError: nil, | ||
|
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