github.com/sdboyer/gps@v0.16.3/version_unifier_test.go (about)

     1  package gps
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/sdboyer/gps/pkgtree"
     7  )
     8  
     9  type lvFixBridge []Version
    10  
    11  var lvfb1 lvFixBridge
    12  
    13  func init() {
    14  	rev1 := Revision("revision-one")
    15  	rev2 := Revision("revision-two")
    16  	rev3 := Revision("revision-three")
    17  
    18  	lvfb1 = lvFixBridge{
    19  		NewBranch("master").Is(rev1),
    20  		NewBranch("test").Is(rev2),
    21  		NewVersion("1.0.0").Is(rev1),
    22  		NewVersion("1.0.1").Is("other1"),
    23  		NewVersion("v2.0.5").Is(rev3),
    24  		NewVersion("2.0.5.2").Is(rev3),
    25  		newDefaultBranch("unwrapped").Is(rev3),
    26  		NewVersion("20.0.5.2").Is(rev1),
    27  		NewVersion("v1.5.5-beta.4").Is("other2"),
    28  		NewVersion("v3.0.1-alpha.1").Is(rev2),
    29  	}
    30  }
    31  
    32  func (lb lvFixBridge) listVersions(ProjectIdentifier) ([]Version, error) {
    33  	return lb, nil
    34  }
    35  
    36  func TestCreateTyepUnion(t *testing.T) {
    37  	vu := versionUnifier{
    38  		b:   lvfb1,
    39  		mtr: newMetrics(),
    40  	}
    41  
    42  	rev1 := Revision("revision-one")
    43  	rev2 := Revision("revision-two")
    44  	id := mkPI("irrelevant")
    45  
    46  	vtu := vu.createTypeUnion(id, rev1)
    47  	if len(vtu) != 4 {
    48  		t.Fatalf("wanted a type union with four elements, got %v: \n%#v", len(vtu), vtu)
    49  	}
    50  
    51  	vtu = vu.createTypeUnion(id, NewBranch("master"))
    52  	if len(vtu) != 4 {
    53  		t.Fatalf("wanted a type union with four elements, got %v: \n%#v", len(vtu), vtu)
    54  	}
    55  
    56  	vtu = vu.createTypeUnion(id, Revision("notexist"))
    57  	if len(vtu) != 1 {
    58  		t.Fatalf("wanted a type union with one elements, got %v: \n%#v", len(vtu), vtu)
    59  	}
    60  
    61  	vtu = vu.createTypeUnion(id, rev2)
    62  	if len(vtu) != 3 {
    63  		t.Fatalf("wanted a type union with three elements, got %v: \n%#v", len(vtu), vtu)
    64  	}
    65  
    66  	vtu = vu.createTypeUnion(id, nil)
    67  	if vtu != nil {
    68  		t.Fatalf("wanted a nil return on nil input, got %#v", vtu)
    69  	}
    70  }
    71  
    72  func TestTypeUnionIntersect(t *testing.T) {
    73  	vu := versionUnifier{
    74  		b:   lvfb1,
    75  		mtr: newMetrics(),
    76  	}
    77  
    78  	rev1 := Revision("revision-one")
    79  	rev2 := Revision("revision-two")
    80  	rev3 := Revision("revision-three")
    81  	id := mkPI("irrelevant")
    82  
    83  	c, _ := NewSemverConstraint("^2.0.0")
    84  	gotc := vu.intersect(id, rev2, c)
    85  	if gotc != none {
    86  		t.Fatalf("wanted empty set from intersect, got %#v", gotc)
    87  	}
    88  
    89  	gotc = vu.intersect(id, c, rev1)
    90  	if gotc != none {
    91  		t.Fatalf("wanted empty set from intersect, got %#v", gotc)
    92  	}
    93  
    94  	gotc = vu.intersect(id, c, rev3)
    95  	if gotc != NewVersion("v2.0.5").Is(rev3) {
    96  		t.Fatalf("wanted v2.0.5, got %s from intersect", gotc.typedString())
    97  	}
    98  }
    99  
   100  func (lb lvFixBridge) SourceExists(ProjectIdentifier) (bool, error) {
   101  	panic("not implemented")
   102  }
   103  
   104  func (lb lvFixBridge) SyncSourceFor(ProjectIdentifier) error {
   105  	panic("not implemented")
   106  }
   107  
   108  func (lb lvFixBridge) RevisionPresentIn(ProjectIdentifier, Revision) (bool, error) {
   109  	panic("not implemented")
   110  }
   111  
   112  func (lb lvFixBridge) ListPackages(ProjectIdentifier, Version) (pkgtree.PackageTree, error) {
   113  	panic("not implemented")
   114  }
   115  
   116  func (lb lvFixBridge) GetManifestAndLock(ProjectIdentifier, Version, ProjectAnalyzer) (Manifest, Lock, error) {
   117  	panic("not implemented")
   118  }
   119  
   120  func (lb lvFixBridge) ExportProject(ProjectIdentifier, Version, string) error {
   121  	panic("not implemented")
   122  }
   123  
   124  func (lb lvFixBridge) DeduceProjectRoot(ip string) (ProjectRoot, error) {
   125  	panic("not implemented")
   126  }
   127  
   128  func (lb lvFixBridge) verifyRootDir(path string) error {
   129  	panic("not implemented")
   130  }
   131  
   132  func (lb lvFixBridge) vendorCodeExists(ProjectIdentifier) (bool, error) {
   133  	panic("not implemented")
   134  }
   135  
   136  func (lb lvFixBridge) breakLock() {
   137  	panic("not implemented")
   138  }