github.com/avvmoto/glide@v0.12.3/cfg/lock_test.go (about)

     1  package cfg
     2  
     3  import (
     4  	"sort"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  func TestSortLocks(t *testing.T) {
    10  	c, err := ConfigFromYaml([]byte(yml))
    11  	if err != nil {
    12  		t.Error("ConfigFromYaml failed to parse yaml for TestSortDependencies")
    13  	}
    14  
    15  	ls := make(Locks, len(c.Imports))
    16  	for i := 0; i < len(c.Imports); i++ {
    17  		ls[i] = &Lock{
    18  			Name:    c.Imports[i].Name,
    19  			Version: c.Imports[i].Reference,
    20  		}
    21  	}
    22  
    23  	if ls[2].Name != "github.com/Masterminds/structable" {
    24  		t.Error("Initial dependencies are out of order prior to sort")
    25  	}
    26  
    27  	sort.Sort(ls)
    28  
    29  	if ls[0].Name != "github.com/kylelemons/go-gypsy" ||
    30  		ls[1].Name != "github.com/Masterminds/convert" ||
    31  		ls[2].Name != "github.com/Masterminds/cookoo" ||
    32  		ls[3].Name != "github.com/Masterminds/structable" {
    33  		t.Error("Sorting of dependencies failed")
    34  	}
    35  }
    36  
    37  const inputSubpkgYaml = `
    38  imports:
    39  - name: github.com/gogo/protobuf
    40    version: 82d16f734d6d871204a3feb1a73cb220cc92574c
    41    subpackages:
    42    - plugin/equal
    43    - sortkeys
    44    - plugin/face
    45    - plugin/gostring
    46    - vanity
    47    - plugin/grpc
    48    - plugin/marshalto
    49    - plugin/populate
    50    - plugin/oneofcheck
    51    - plugin/size
    52    - plugin/stringer
    53    - plugin/defaultcheck
    54    - plugin/embedcheck
    55    - plugin/description
    56    - plugin/enumstringer
    57    - gogoproto
    58    - plugin/testgen
    59    - plugin/union
    60    - plugin/unmarshal
    61    - protoc-gen-gogo/generator
    62    - protoc-gen-gogo/plugin
    63    - vanity/command
    64    - protoc-gen-gogo/descriptor
    65    - proto
    66  `
    67  const expectSubpkgYaml = `
    68  imports:
    69  - name: github.com/gogo/protobuf
    70    version: 82d16f734d6d871204a3feb1a73cb220cc92574c
    71    subpackages:
    72    - gogoproto
    73    - plugin/defaultcheck
    74    - plugin/description
    75    - plugin/embedcheck
    76    - plugin/enumstringer
    77    - plugin/equal
    78    - plugin/face
    79    - plugin/gostring
    80    - plugin/grpc
    81    - plugin/marshalto
    82    - plugin/oneofcheck
    83    - plugin/populate
    84    - plugin/size
    85    - plugin/stringer
    86    - plugin/testgen
    87    - plugin/union
    88    - plugin/unmarshal
    89    - proto
    90    - protoc-gen-gogo/descriptor
    91    - protoc-gen-gogo/generator
    92    - protoc-gen-gogo/plugin
    93    - sortkeys
    94    - vanity
    95    - vanity/command
    96  `
    97  
    98  func TestSortSubpackages(t *testing.T) {
    99  	lf, err := LockfileFromYaml([]byte(inputSubpkgYaml))
   100  	if err != nil {
   101  		t.Fatal(err)
   102  	}
   103  
   104  	out, err := lf.Marshal()
   105  	if err != nil {
   106  		t.Fatal(err)
   107  	}
   108  
   109  	if !strings.Contains(string(out), expectSubpkgYaml) {
   110  		t.Errorf("Expected %q\n to contain\n%q", string(out), expectSubpkgYaml)
   111  	}
   112  }