Skip to content

Commit

Permalink
Merge branch 'main' into tenantIdFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
Vidya2606 committed Apr 11, 2024
2 parents 9240ed1 + 38990ef commit d1660f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/languages/defaults/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ func TestPythonExtractor_ReadDefaults(t *testing.T) {
{
name: "extract first python file as entrypoint",
args: args{
r: reporeader.FakeRepoReader{
r: reporeader.FakeRepoReader{ // maps order isn't defined but FakeRepoReader sorts the keys
Files: map[string][]byte{
"foo.py": []byte("print('hello world')"),
"bar.py": []byte("print('hello world')"),
"foo.py": []byte("print('hello world')"),
},
},
},
want: map[string]string{
"ENTRYPOINT": "foo.py",
"ENTRYPOINT": "bar.py",
},
wantErr: false,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (sc *SetUpCmd) getTenantId(ctx context.Context) error {
if len(tenants) > 1 {
return errors.New("multiple tenants found")
}
sc.tenantId = fmt.Sprint(&tenants[0])
sc.tenantId = *tenants[0].TenantID

return nil
}
Expand Down
15 changes: 12 additions & 3 deletions pkg/reporeader/reporeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package reporeader

import (
"path/filepath"
"sort"
"strings"
)

Expand Down Expand Up @@ -55,15 +56,23 @@ func (r FakeRepoReader) FindFiles(path string, patterns []string, maxDepth int)
if r.Files == nil {
return files, nil
}

// sort files because map iteration order is undefined. lets us control test behavior
sortedFiles := make([]string, 0, len(r.Files))
for k := range r.Files {
sortedFiles = append(sortedFiles, k)
}
sort.Strings(sortedFiles)

for _, file := range sortedFiles {
for _, pattern := range patterns {
if matched, err := filepath.Match(pattern, filepath.Base(k)); err != nil {
if matched, err := filepath.Match(pattern, filepath.Base(file)); err != nil {
return nil, err
} else if matched {
splitPath := strings.Split(k, string(filepath.Separator))
splitPath := strings.Split(file, string(filepath.Separator))
fileDepth := len(splitPath) - 1
if fileDepth <= maxDepth {
files = append(files, k)
files = append(files, file)
}
}
}
Expand Down

0 comments on commit d1660f4

Please sign in to comment.