forked from akash-network/terraform-provider-akash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Progress on tracing and profiling enablement
- Loading branch information
1 parent
183de94
commit 8bfe639
Showing
9 changed files
with
883 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package providers_api | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestGetAllProviders(t *testing.T) { | ||
handler := http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { | ||
file, err := os.Open("../../../testdata/providers.json") | ||
if err != nil { | ||
t.Fatalf("Could not open file: %s", err) | ||
} | ||
if _, err = io.Copy(writer, file); err != nil { | ||
t.Fatalf("Could not copy file content: %s", err) | ||
} | ||
}) | ||
|
||
t.Run("should return all providers", func(t *testing.T) { | ||
server := httptest.NewServer(handler) | ||
expectedProviders := 51 | ||
mockClient := New(server.URL) | ||
providers, _ := mockClient.GetAllProviders() | ||
|
||
if len(providers) != expectedProviders { | ||
t.Fatalf("Expected %d providers, got %d", expectedProviders, len(providers)) | ||
} | ||
}) | ||
} | ||
|
||
func TestGetActiveProviders(t *testing.T) { | ||
handler := http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { | ||
file, err := os.Open("../../../testdata/providers.json") | ||
if err != nil { | ||
t.Fatalf("Could not open file: %s", err) | ||
} | ||
if _, err = io.Copy(writer, file); err != nil { | ||
t.Fatalf("Could not copy file content: %s", err) | ||
} | ||
}) | ||
|
||
t.Run("should return active providers", func(t *testing.T) { | ||
server := httptest.NewServer(handler) | ||
expectedProviders := 41 | ||
mockClient := New(server.URL) | ||
providers, _ := mockClient.GetActiveProviders() | ||
|
||
if len(providers) != expectedProviders { | ||
t.Fatalf("Expected %d providers, got %d", expectedProviders, len(providers)) | ||
} | ||
}) | ||
|
||
t.Run("should break if its not 200 OK", func(t *testing.T) { | ||
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { | ||
writer.WriteHeader(500) | ||
})) | ||
|
||
mockClient := New(server.URL) | ||
|
||
if _, err := mockClient.GetActiveProviders(); err == nil { | ||
t.Fatalf("Expected an error") | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.