github.com/opentofu/opentofu@v1.7.1/internal/plugin/discovery/version_test.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package discovery 7 8 import ( 9 "reflect" 10 "testing" 11 ) 12 13 func TestSortVersions(t *testing.T) { 14 versions := Versions{ 15 VersionStr("4").MustParse(), 16 VersionStr("3.1").MustParse(), 17 VersionStr("1.2").MustParse(), 18 VersionStr("1.2.3").MustParse(), 19 VersionStr("2.2.3").MustParse(), 20 VersionStr("3.2.1").MustParse(), 21 VersionStr("2.3.2").MustParse(), 22 } 23 24 expected := []string{ 25 "4.0.0", 26 "3.2.1", 27 "3.1.0", 28 "2.3.2", 29 "2.2.3", 30 "1.2.3", 31 "1.2.0", 32 } 33 34 versions.Sort() 35 36 var sorted []string 37 for _, v := range versions { 38 sorted = append(sorted, v.String()) 39 } 40 41 if !reflect.DeepEqual(sorted, expected) { 42 t.Fatal("versions aren't sorted:", sorted) 43 } 44 }