github.com/liuweiccy/glide@v0.12.3/dependency/resolver_test.go (about)

     1  package dependency
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/Masterminds/glide/cfg"
    10  )
    11  
    12  func TestResolveLocalShallow(t *testing.T) {
    13  	r, err := NewResolver("../")
    14  	if err != nil {
    15  		t.Fatal(err)
    16  	}
    17  
    18  	l, _, err := r.ResolveLocal(false)
    19  	if err != nil {
    20  		t.Fatalf("Failed to resolve: %s", err)
    21  	}
    22  
    23  	expect := []string{
    24  		"github.com/Masterminds/semver",
    25  		"github.com/Masterminds/vcs",
    26  		"gopkg.in/yaml.v2",
    27  		"github.com/codegangsta/cli",
    28  	}
    29  
    30  	for _, p := range expect {
    31  		found := false
    32  		for _, li := range l {
    33  			if strings.HasSuffix(li, p) {
    34  				found = true
    35  				break
    36  			}
    37  		}
    38  		if !found {
    39  			t.Errorf("Could not find %s in resolved list.", p)
    40  		}
    41  	}
    42  }
    43  
    44  func TestResolveLocalDeep(t *testing.T) {
    45  	r, err := NewResolver("../")
    46  	if err != nil {
    47  		t.Fatal(err)
    48  	}
    49  	h := &DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}, Prefix: "../vendor"}
    50  	r.Handler = h
    51  
    52  	l, _, err := r.ResolveLocal(true)
    53  	if err != nil {
    54  		t.Fatalf("Failed to resolve: %s", err)
    55  	}
    56  
    57  	if len(l) < 4 {
    58  		t.Errorf("Expected at least 4 deps, got %d", len(l))
    59  	}
    60  }
    61  
    62  func TestResolve(t *testing.T) {
    63  	r, err := NewResolver("../")
    64  	if err != nil {
    65  		t.Fatal(err)
    66  	}
    67  	h := &DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}, Prefix: "../vendor"}
    68  	r.Handler = h
    69  
    70  	base := filepath.Join(os.Getenv("GOPATH"), "src/github.com/Masterminds/glide/vendor")
    71  	l, err := r.Resolve("github.com/codegangsta/cli", base)
    72  	if err != nil {
    73  		t.Fatalf("Failed to resolve: %s", err)
    74  	}
    75  
    76  	if len(l) != 1 {
    77  		t.Errorf("Expected 1 dep, got %d: %s", len(l), l[0])
    78  	}
    79  
    80  	if !strings.HasSuffix("github.com/codegangsta/cli", l[0]) {
    81  		t.Errorf("Unexpected package name: %s", l[0])
    82  	}
    83  }
    84  
    85  func TestResolveAll(t *testing.T) {
    86  	// These are build dependencies of Glide, so we know they are here.
    87  	deps := []*cfg.Dependency{
    88  		{Name: "github.com/codegangsta/cli"},
    89  		{Name: "github.com/Masterminds/semver"},
    90  		{Name: "github.com/Masterminds/vcs"},
    91  		{Name: "gopkg.in/yaml.v2"},
    92  	}
    93  
    94  	r, err := NewResolver("../")
    95  	if err != nil {
    96  		t.Fatalf("No new resolver: %s", err)
    97  	}
    98  	h := &DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}, Prefix: "../vendor"}
    99  	r.Handler = h
   100  	l, err := r.ResolveAll(deps, false)
   101  	if err != nil {
   102  		t.Fatalf("Failed to resolve: %s", err)
   103  	}
   104  
   105  	if len(l) < len(deps) {
   106  		t.Errorf("Expected at least %d deps, got %d", len(deps), len(l))
   107  	}
   108  }