package discovery import ( "net/http" "net/http/httptest" "testing" ) func TestVersionListing(t *testing.T) { handler := http.NewServeMux() handler.HandleFunc("/terraform-providers/terraform-provider-test/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(versionList)) }) server := httptest.NewServer(handler) defer server.Close() providersURL.releases = server.URL + "/" versions, err := listProviderVersions("test") if err != nil { t.Fatal(err) } expectedSet := map[string]bool{ "1.2.4": true, "1.2.3": true, "1.2.1": true, } for _, v := range versions { if !expectedSet[v.String()] { t.Fatalf("didn't get version %s in listing", v) } delete(expectedSet, v.String()) } } const versionList = `
`