-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a basic test for
GetDatasetDetailsPublished
- Loading branch information
Showing
2 changed files
with
48 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package datasetUtils | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
// This test checks that the function correctly parses the response from the server. | ||
func TestGetDatasetDetailsPublished(t *testing.T) { | ||
// Create a mock HTTP server | ||
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { | ||
// Respond with a JSON representation of a list of datasets | ||
rw.Write([]byte(`[{"pid": "1", "sourceFolder": "/folder1", "size": 100, "ownerGroup": "group1", "numberOfFiles": 10}]`)) | ||
})) | ||
defer server.Close() | ||
|
||
// Create a new HTTP client | ||
client := &http.Client{} | ||
|
||
// Call the function with the mock server's URL and a list of dataset IDs | ||
datasets, urls := GetDatasetDetailsPublished(client, server.URL, []string{"1"}) | ||
|
||
// Test that the function returns the expected results | ||
if len(datasets) != 1 || datasets[0].Pid != "1" { | ||
t.Errorf("Unexpected datasets: %v", datasets) | ||
} | ||
if len(urls) != 1 || urls[0] != "https://doi2.psi.ch/datasets/folder1" { | ||
t.Errorf("Unexpected URLs: %v", urls) | ||
} | ||
} |