github.com/johandry/terraform@v0.11.12-beta1/plugin/discovery/version_test.go (about)

     1  package discovery
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestSortVersions(t *testing.T) {
     9  	versions := Versions{
    10  		VersionStr("4").MustParse(),
    11  		VersionStr("3.1").MustParse(),
    12  		VersionStr("1.2").MustParse(),
    13  		VersionStr("1.2.3").MustParse(),
    14  		VersionStr("2.2.3").MustParse(),
    15  		VersionStr("3.2.1").MustParse(),
    16  		VersionStr("2.3.2").MustParse(),
    17  	}
    18  
    19  	expected := []string{
    20  		"4.0.0",
    21  		"3.2.1",
    22  		"3.1.0",
    23  		"2.3.2",
    24  		"2.2.3",
    25  		"1.2.3",
    26  		"1.2.0",
    27  	}
    28  
    29  	versions.Sort()
    30  
    31  	var sorted []string
    32  	for _, v := range versions {
    33  		sorted = append(sorted, v.String())
    34  	}
    35  
    36  	if !reflect.DeepEqual(sorted, expected) {
    37  		t.Fatal("versions aren't sorted:", sorted)
    38  	}
    39  }