github.com/kngu9/glide@v0.0.0-20160505135211-e73500c73591/cfg/lock_test.go (about)

     1  package cfg
     2  
     3  import (
     4  	"sort"
     5  	"testing"
     6  )
     7  
     8  func TestSortLocks(t *testing.T) {
     9  	c, err := ConfigFromYaml([]byte(yml))
    10  	if err != nil {
    11  		t.Error("ConfigFromYaml failed to parse yaml for TestSortDependencies")
    12  	}
    13  
    14  	ls := make(Locks, len(c.Imports))
    15  	for i := 0; i < len(c.Imports); i++ {
    16  		ls[i] = &Lock{
    17  			Name:    c.Imports[i].Name,
    18  			Version: c.Imports[i].Reference,
    19  		}
    20  	}
    21  
    22  	if ls[2].Name != "github.com/Masterminds/structable" {
    23  		t.Error("Initial dependencies are out of order prior to sort")
    24  	}
    25  
    26  	sort.Sort(ls)
    27  
    28  	if ls[0].Name != "github.com/kylelemons/go-gypsy" ||
    29  		ls[1].Name != "github.com/Masterminds/convert" ||
    30  		ls[2].Name != "github.com/Masterminds/cookoo" ||
    31  		ls[3].Name != "github.com/Masterminds/structable" {
    32  		t.Error("Sorting of dependencies failed")
    33  	}
    34  }