github.com/golang/dep@v0.5.4/gps/selection_test.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package gps
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  // Regression test for https://github.com/sdboyer/gps/issues/174
    13  func TestUnselectedRemoval(t *testing.T) {
    14  	// We don't need a comparison function for this test
    15  	bmi1 := bimodalIdentifier{
    16  		id: mkPI("foo"),
    17  		pl: []string{"foo", "bar"},
    18  	}
    19  	bmi2 := bimodalIdentifier{
    20  		id: mkPI("foo"),
    21  		pl: []string{"foo", "bar", "baz"},
    22  	}
    23  	bmi3 := bimodalIdentifier{
    24  		id: mkPI("foo"),
    25  		pl: []string{"foo"},
    26  	}
    27  
    28  	u := &unselected{
    29  		sl: []bimodalIdentifier{bmi1, bmi2, bmi3},
    30  	}
    31  
    32  	u.remove(bimodalIdentifier{
    33  		id: mkPI("other"),
    34  		pl: []string{"other"},
    35  	})
    36  
    37  	if len(u.sl) != 3 {
    38  		t.Fatalf("len of unselected slice should have been 2 after no-op removal, got %v", len(u.sl))
    39  	}
    40  
    41  	u.remove(bmi3)
    42  	want := []bimodalIdentifier{bmi1, bmi2}
    43  	if len(u.sl) != 2 {
    44  		t.Fatalf("removal of matching bmi did not work, slice should have 2 items but has %v", len(u.sl))
    45  	}
    46  	if !reflect.DeepEqual(u.sl, want) {
    47  		t.Fatalf("wrong item removed from slice:\n\t(GOT): %v\n\t(WNT): %v", u.sl, want)
    48  	}
    49  
    50  	u.remove(bmi3)
    51  	if len(u.sl) != 2 {
    52  		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))
    53  	}
    54  
    55  	u.remove(bmi2)
    56  	want = []bimodalIdentifier{bmi1}
    57  	if len(u.sl) != 1 {
    58  		t.Fatalf("removal of matching bmi did not work, slice should have 1 items but has %v", len(u.sl))
    59  	}
    60  	if !reflect.DeepEqual(u.sl, want) {
    61  		t.Fatalf("wrong item removed from slice:\n\t(GOT): %v\n\t(WNT): %v", u.sl, want)
    62  	}
    63  }