Skip to content

Commit 8a15127

Browse files
authored
Revert "Log when no files match alias file pattern (launchdarkly#271)" (launchdarkly#276)
This reverts commit b30b5ed.
1 parent b30b5ed commit 8a15127

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

aliases/alias.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/iancoleman/strcase"
1616
"github.com/launchdarkly/ld-find-code-refs/internal/helpers"
17-
"github.com/launchdarkly/ld-find-code-refs/internal/log"
1817
"github.com/launchdarkly/ld-find-code-refs/internal/validation"
1918
"github.com/launchdarkly/ld-find-code-refs/options"
2019
)
@@ -28,10 +27,7 @@ func GenerateAliases(flags []string, aliases []options.Alias, dir string) (map[s
2827

2928
ret := make(map[string][]string, len(flags))
3029
for _, flag := range flags {
31-
for i, a := range aliases {
32-
if a.Name == "" {
33-
a.Name = strconv.Itoa(i)
34-
}
30+
for _, a := range aliases {
3531
flagAliases, err := generateAlias(a, flag, dir, allFileContents)
3632
if err != nil {
3733
return nil, err
@@ -45,7 +41,6 @@ func GenerateAliases(flags []string, aliases []options.Alias, dir string) (map[s
4541

4642
func generateAlias(a options.Alias, flag, dir string, allFileContents map[string][]byte) ([]string, error) {
4743
ret := []string{}
48-
aliasId := a.Name
4944
switch a.Type.Canonical() {
5045
case options.Literal:
5146
ret = a.Flags[flag]
@@ -68,7 +63,7 @@ func generateAlias(a options.Alias, flag, dir string, allFileContents map[string
6863
absGlob := filepath.Join(dir, path)
6964
matches, err := filepath.Glob(absGlob)
7065
if err != nil {
71-
return nil, fmt.Errorf("filepattern '%s': could not process path glob '%s'", aliasId, absGlob)
66+
return nil, fmt.Errorf("could not process path glob '%s'", absGlob)
7267
}
7368
for _, match := range matches {
7469
pathFileContents := allFileContents[match]
@@ -106,11 +101,11 @@ func generateAlias(a options.Alias, flag, dir string, allFileContents map[string
106101
cmd.Dir = dir
107102
stdout, err := cmd.Output()
108103
if err != nil {
109-
return nil, fmt.Errorf("filepattern '%s': failed to execute alias command: %w", aliasId, err)
104+
return nil, fmt.Errorf("failed to execute alias command: %w", err)
110105
}
111106
err = json.Unmarshal(stdout, &ret)
112107
if err != nil {
113-
return nil, fmt.Errorf("filepattern '%s': could not unmarshal json output of alias command: %w", aliasId, err)
108+
return nil, fmt.Errorf("could not unmarshal json output of alias command: %w", err)
114109
}
115110
}
116111

@@ -134,12 +129,9 @@ func processFileContent(aliases []options.Alias, dir string) (map[string][]byte,
134129
for _, glob := range a.Paths {
135130
absGlob := filepath.Join(dir, glob)
136131
matches, err := filepath.Glob(absGlob)
137-
if err != nil {
132+
if matches == nil || err != nil {
138133
return nil, fmt.Errorf("filepattern '%s': could not process path glob '%s'", aliasId, absGlob)
139134
}
140-
if matches == nil {
141-
log.Info.Printf("filepattern '%s': no matching files found for alias path glob '%s'", aliasId, absGlob)
142-
}
143135
paths = append(paths, matches...)
144136
}
145137
paths = helpers.Dedupe(paths)

aliases/alias_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import (
55
"os"
66
"testing"
77

8-
"github.com/stretchr/testify/assert"
9-
10-
"github.com/launchdarkly/ld-find-code-refs/internal/log"
118
o "github.com/launchdarkly/ld-find-code-refs/options"
9+
"github.com/stretchr/testify/assert"
1210
)
1311

1412
var allNamingConventions = []o.Alias{
@@ -29,11 +27,6 @@ const (
2927
testWildFlagKey = "wildFlag"
3028
)
3129

32-
func TestMain(m *testing.M) {
33-
log.Init(true)
34-
os.Exit(m.Run())
35-
}
36-
3730
func Test_GenerateAliases(t *testing.T) {
3831
specs := []struct {
3932
name string
@@ -145,8 +138,8 @@ func Test_processFileContent(t *testing.T) {
145138
},
146139
},
147140
dir: "dirDoesNotExist",
148-
want: emptyMap,
149-
wantErr: false,
141+
want: nil,
142+
wantErr: true,
150143
},
151144
{
152145
name: "Non-existent file",
@@ -157,8 +150,8 @@ func Test_processFileContent(t *testing.T) {
157150
},
158151
},
159152
dir: tmpDir,
160-
want: emptyMap,
161-
wantErr: false,
153+
want: nil,
154+
wantErr: true,
162155
},
163156
}
164157
for _, tt := range tests {

search/matcher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func Test_buildFlagPatterns(t *testing.T) {
1111
testFlagKey := "testflag"
1212
patterns := buildElementPatterns([]string{testFlagKey}, defaultDelims)
13-
want := map[string][]string{"testflag": {"\"testflag\"", "\"testflag'", "\"testflag`", "'testflag\"", "'testflag'", "'testflag`", "`testflag\"", "`testflag'", "`testflag`"}}
13+
want := map[string][]string{"testflag": []string{"\"testflag\"", "\"testflag'", "\"testflag`", "'testflag\"", "'testflag'", "'testflag`", "`testflag\"", "`testflag'", "`testflag`"}}
1414
require.Equal(t, want, patterns)
1515
}
1616

0 commit comments

Comments
 (0)