github.com/sfdevops1/terrra4orm@v0.11.12-beta1/config/module/versions_test.go (about) 1 package module 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/terraform/registry/response" 7 ) 8 9 func TestNewestModuleVersion(t *testing.T) { 10 mpv := &response.ModuleProviderVersions{ 11 Source: "registry/test/module", 12 Versions: []*response.ModuleVersion{ 13 {Version: "0.0.4"}, 14 {Version: "0.3.1"}, 15 {Version: "2.0.1"}, 16 {Version: "1.2.0"}, 17 }, 18 } 19 20 m, err := newestVersion(mpv.Versions, "") 21 if err != nil { 22 t.Fatal(err) 23 } 24 25 expected := "2.0.1" 26 if m.Version != expected { 27 t.Fatalf("expected version %q, got %q", expected, m.Version) 28 } 29 30 // now with a constraint 31 m, err = newestVersion(mpv.Versions, "~>1.0") 32 if err != nil { 33 t.Fatal(err) 34 } 35 36 expected = "1.2.0" 37 if m.Version != expected { 38 t.Fatalf("expected version %q, got %q", expected, m.Version) 39 } 40 } 41 42 func TestNewestInvalidModuleVersion(t *testing.T) { 43 mpv := &response.ModuleProviderVersions{ 44 Source: "registry/test/module", 45 Versions: []*response.ModuleVersion{ 46 {Version: "WTF"}, 47 {Version: "2.0.1"}, 48 }, 49 } 50 51 m, err := newestVersion(mpv.Versions, "") 52 if err != nil { 53 t.Fatal(err) 54 } 55 56 expected := "2.0.1" 57 if m.Version != expected { 58 t.Fatalf("expected version %q, got %q", expected, m.Version) 59 } 60 }