Skip to content

Commit cca04b7

Browse files
committed
address review comments
1 parent 0b8a482 commit cca04b7

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ github.com/scylladb/go-set v1.0.3-0.20200225121959-cc7b2070d91e h1:7q6NSFZDeGfvv
1616
github.com/scylladb/go-set v1.0.3-0.20200225121959-cc7b2070d91e/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs=
1717
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
1818
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
19+
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
1920
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2021
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
2122
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=

main.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626

2727
func main() {
2828
if err := run(os.Args[1:]); err != nil {
29-
fmt.Fprintf(os.Stderr, "%v\n", err)
29+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
3030
os.Exit(1)
3131
}
3232
}
@@ -83,21 +83,21 @@ func run(args []string) error {
8383
return fmt.Errorf("parse: %v", err)
8484
}
8585

86-
upMatches, downMatches := match_exact(create, destroy)
86+
upMatches, downMatches := matchExact(create, destroy)
8787

8888
msg := collectErrors(create, destroy)
8989
if msg != "" && !fuzzyMatch {
90-
return fmt.Errorf("match_exact:%v", msg)
90+
return fmt.Errorf("matchExact:%v", msg)
9191
}
9292

9393
if fuzzyMatch && create.Size() == 0 && destroy.Size() == 0 {
94-
return fmt.Errorf("required fuzzy-match but there is nothing to fuzzy")
94+
return fmt.Errorf("required fuzzy-match but there is nothing left to match")
9595
}
9696
if fuzzyMatch {
97-
upMatches, downMatches = match_fuzzy(create, destroy)
97+
upMatches, downMatches = matchFuzzy(create, destroy)
9898
msg := collectErrors(create, destroy)
9999
if msg != "" {
100-
return fmt.Errorf("match_fuzzy:%v", msg)
100+
return fmt.Errorf("matchFuzzy: %v", msg)
101101
}
102102
}
103103

@@ -179,10 +179,10 @@ func parse(rd io.Reader) (*strset.Set, *strset.Set, error) {
179179
//
180180
// Modify the two input sets so that they contain only the remaining (if any) unmatched elements.
181181
//
182-
// The criterium used to perform a match_exact is that one of the two elements must be a
182+
// The criterium used to perform a matchExact is that one of the two elements must be a
183183
// prefix of the other.
184184
// Note that the longest element could be the old or the new one, it depends on the inputs.
185-
func match_exact(create, destroy *strset.Set) (map[string]string, map[string]string) {
185+
func matchExact(create, destroy *strset.Set) (map[string]string, map[string]string) {
186186
// old -> new (or equvalenty: destroy -> create)
187187
upMatches := map[string]string{}
188188
downMatches := map[string]string{}
@@ -211,18 +211,18 @@ func match_exact(create, destroy *strset.Set) (map[string]string, map[string]str
211211
}
212212

213213
// Given two unordered sets create and destroy, that have already been processed by
214-
// match_exact(), perform a fuzzy match from destroy to create.
214+
// matchExact(), perform a fuzzy match from destroy to create.
215215
//
216216
// Return two maps, the first that fuzzy matches each old element in destroy to the
217217
// corresponding new element in create (up), the second that matches in the opposite
218218
// direction (down).
219219
//
220220
// Modify the two input sets so that they contain only the remaining (if any) unmatched elements.
221221
//
222-
// The criterium used to perform a match_fuzzy is that one of the two elements must be a
222+
// The criterium used to perform a matchFuzzy is that one of the two elements must be a
223223
// fuzzy match of the other, according to some definition of fuzzy.
224224
// Note that the longest element could be the old or the new one, it depends on the inputs.
225-
func match_fuzzy(create, destroy *strset.Set) (map[string]string, map[string]string) {
225+
func matchFuzzy(create, destroy *strset.Set) (map[string]string, map[string]string) {
226226
// old -> new (or equvalenty: destroy -> create)
227227
upMatches := map[string]string{}
228228
downMatches := map[string]string{}

main_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestFailure(t *testing.T) {
111111
},
112112
{
113113
"testdata/02_fuzzy-match.plan.txt",
114-
fmt.Errorf(`match_exact:
114+
fmt.Errorf(`matchExact:
115115
unmatched create:
116116
aws_route53_record.localhostnames_public["artifactory"]
117117
aws_route53_record.loopback["artifactory"]
@@ -252,7 +252,7 @@ func TestMatchExactZeroUnmatched(t *testing.T) {
252252

253253
for _, tc := range testCases {
254254
t.Run(tc.description, func(t *testing.T) {
255-
gotUpMatches, gotDownMatches := match_exact(tc.create, tc.destroy)
255+
gotUpMatches, gotDownMatches := matchExact(tc.create, tc.destroy)
256256

257257
if diff := cmp.Diff(tc.wantUpMatches, gotUpMatches); diff != "" {
258258
t.Errorf("\nupMatches: mismatch (-want +got):\n%s", diff)
@@ -300,7 +300,7 @@ func TestMatchExactSomeUnmatched(t *testing.T) {
300300

301301
for _, tc := range testCases {
302302
t.Run(tc.description, func(t *testing.T) {
303-
match_exact(tc.create, tc.destroy)
303+
matchExact(tc.create, tc.destroy)
304304

305305
if diff := cmp.Diff(tc.wantCreate, tc.create, cmpOpt); diff != "" {
306306
t.Errorf("\nUnmatched create: (-want +got):\n%s", diff)
@@ -330,26 +330,26 @@ func TestMatchFuzzyZeroUnmatched(t *testing.T) {
330330
set.NewStringSet(
331331
`foo.loopback["bar"]`,
332332
`foo.private["bar"]`,
333-
`foo.localhostnames_public["bar"]`),
333+
`foo.public["bar"]`),
334334
set.NewStringSet(
335335
`foo.bar_loopback`,
336336
`foo.bar_private`,
337337
`foo.bar`),
338338
map[string]string{
339339
`foo.bar_loopback`: `foo.loopback["bar"]`,
340340
`foo.bar_private`: `foo.private["bar"]`,
341-
`foo.bar`: `foo.localhostnames_public["bar"]`},
341+
`foo.bar`: `foo.public["bar"]`},
342342
map[string]string{
343-
`foo.loopback["bar"]`: `foo.bar_loopback`,
344-
`foo.private["bar"]`: `foo.bar_private`,
345-
`foo.localhostnames_public["bar"]`: `foo.bar`},
343+
`foo.loopback["bar"]`: `foo.bar_loopback`,
344+
`foo.private["bar"]`: `foo.bar_private`,
345+
`foo.public["bar"]`: `foo.bar`},
346346
},
347347
}
348348

349349
for _, tc := range testCases {
350350
t.Run(tc.description, func(t *testing.T) {
351351

352-
gotUpMatches, gotDownMatches := match_fuzzy(tc.create, tc.destroy)
352+
gotUpMatches, gotDownMatches := matchFuzzy(tc.create, tc.destroy)
353353

354354
if diff := cmp.Diff(tc.wantUpMatches, gotUpMatches); diff != "" {
355355
t.Errorf("\nupMatches: mismatch (-want +got):\n%s", diff)

testdata/03_fuzzy-match.plan.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@
1919
# aws_route53_record.localhostnames_public["anka"] will be created
2020
# aws_route53_record.localhostnames_public["anka-api"] will be created
2121
# aws_route53_record.localhostnames_public["anka-test"] will be created
22-

0 commit comments

Comments
 (0)