Skip to content

Commit

Permalink
PCI-1828 Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aliculPix4D committed Jul 23, 2021
1 parent d67a002 commit 9faec0b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
12 changes: 3 additions & 9 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,18 @@ tasks:
default:
deps: [test]

clean:
desc: Delete build artifacts
cmds: [rm -rf bin/*]

terravalet:
build:
desc: Build the terravalet executable
deps: [clean]
cmds:
- mkdir -p bin
- cd bin && go build -v -ldflags="{{.LDFLAGS}}" ..
- go build -o bin/terravalet -v -ldflags="{{.LDFLAGS}}" .
vars: &build-vars
FULL_VERSION:
sh: git describe --long --dirty --always
LDFLAGS: -w -s -X main.fullVersion={{.FULL_VERSION}}

test:
desc: Run the integration tests
deps: [terravalet]
deps: [build]
cmds:
- "{{.TESTRUNNER}} ./..."
vars:
Expand Down
24 changes: 11 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,26 +370,24 @@ func matchFuzzy(create, destroy *strset.Set) (map[string]string, map[string]stri

for len(candidates) > 0 {
bestCandidate := candidates[0]
tmpCandidates := []candidate{}

for _, c := range candidates[1:] {
if bestCandidate.distance < c.distance {
break
}
if (bestCandidate.create == c.create) || (bestCandidate.destroy == c.destroy) {
return map[string]string{},
map[string]string{},
fmt.Errorf("ambiguous migration: {%s} -> {%s} or {%s} -> {%s}",
bestCandidate.create, bestCandidate.destroy,
c.create, c.destroy,
)
if bestCandidate.distance == c.distance {
if (bestCandidate.create == c.create) || (bestCandidate.destroy == c.destroy) {
return map[string]string{}, map[string]string{},
fmt.Errorf("ambiguous migration: {%s} -> {%s} or {%s} -> {%s}",
bestCandidate.create, bestCandidate.destroy,
c.create, c.destroy,
)
}
}
}
tmpCandidates := []candidate{}
for _, c := range candidates[1:] {
if (bestCandidate.create != c.create) && (bestCandidate.destroy != c.destroy) {
tmpCandidates = append(tmpCandidates, candidate{c.distance, c.create, c.destroy})
}

}

candidates = tmpCandidates
upMatches[bestCandidate.destroy] = bestCandidate.create
downMatches[bestCandidate.create] = bestCandidate.destroy
Expand Down
13 changes: 8 additions & 5 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ func TestMatchFuzzyZeroUnmatched(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {

gotUpMatches, gotDownMatches, _ := matchFuzzy(tc.create, tc.destroy)
gotUpMatches, gotDownMatches, err := matchFuzzy(tc.create, tc.destroy)
if err != nil {
t.Fatalf("got: %s; want: no error", err)
}

if diff := cmp.Diff(tc.wantUpMatches, gotUpMatches); diff != "" {
t.Errorf("\nupMatches: mismatch (-want +got):\n%s", diff)
Expand All @@ -463,16 +466,16 @@ func TestMatchFuzzyZeroUnmatched(t *testing.T) {
}

func TestMatchFuzzyError(t *testing.T) {
t.Run("ambiguous migration: two differnt items have the same match", func(t *testing.T) {
t.Run("ambiguous migration: two different items have the same match", func(t *testing.T) {
create := set.NewStringSet(`abcde`, `abdecde`)
destroy := set.NewStringSet(`abdcde`, `hfjabd`)
expectedError := "ambiguous migration: {abcde} -> {abdcde} or {abdecde} -> {abdcde}"
wantError := "ambiguous migration: {abcde} -> {abdcde} or {abdecde} -> {abdcde}"
_, _, err := matchFuzzy(create, destroy)
if err == nil {
t.Fatalf("got: no error; want: an ambiguous migration error")
}
if err.Error() != expectedError {
t.Fatalf("got: %s; want: %s", err.Error(), expectedError)
if err.Error() != wantError {
t.Fatalf("got: %s; want: %s", err.Error(), wantError)
}
})
}

0 comments on commit 9faec0b

Please sign in to comment.