forked from golang/dep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check pl len during bmi removal from unsel queue
Fixes golang#174.
- Loading branch information
Showing
2 changed files
with
75 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package gps | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
// Regression test for https://github.com/sdboyer/gps/issues/174 | ||
func TestUnselectedRemoval(t *testing.T) { | ||
// We don't need a comparison function for this test | ||
bmi1 := bimodalIdentifier{ | ||
id: mkPI("foo"), | ||
pl: []string{"foo", "bar"}, | ||
} | ||
bmi2 := bimodalIdentifier{ | ||
id: mkPI("foo"), | ||
pl: []string{"foo", "bar", "baz"}, | ||
} | ||
bmi3 := bimodalIdentifier{ | ||
id: mkPI("foo"), | ||
pl: []string{"foo"}, | ||
} | ||
|
||
u := &unselected{ | ||
sl: []bimodalIdentifier{bmi1, bmi2, bmi3}, | ||
} | ||
|
||
u.remove(bimodalIdentifier{ | ||
id: mkPI("other"), | ||
pl: []string{"other"}, | ||
}) | ||
|
||
if len(u.sl) != 3 { | ||
t.Fatalf("len of unselected slice should have been 2 after no-op removal, got %v", len(u.sl)) | ||
} | ||
|
||
u.remove(bmi3) | ||
want := []bimodalIdentifier{bmi1, bmi2} | ||
if len(u.sl) != 2 { | ||
t.Fatalf("removal of matching bmi did not work, slice should have 2 items but has %v", len(u.sl)) | ||
} | ||
if !reflect.DeepEqual(u.sl, want) { | ||
t.Fatalf("wrong item removed from slice:\n\t(GOT): %v\n\t(WNT): %v", u.sl, want) | ||
} | ||
|
||
u.remove(bmi3) | ||
if len(u.sl) != 2 { | ||
t.Fatalf("removal of bmi w/non-matching packages should be a no-op but wasn't; slice should have 2 items but has %v", len(u.sl)) | ||
} | ||
|
||
u.remove(bmi2) | ||
want = []bimodalIdentifier{bmi1} | ||
if len(u.sl) != 1 { | ||
t.Fatalf("removal of matching bmi did not work, slice should have 1 items but has %v", len(u.sl)) | ||
} | ||
if !reflect.DeepEqual(u.sl, want) { | ||
t.Fatalf("wrong item removed from slice:\n\t(GOT): %v\n\t(WNT): %v", u.sl, want) | ||
} | ||
} |