-
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 unit test for `GetProposal` * Refactor GetProposal Changes: 1. Instead of using log.Fatal which will terminate the program, the function now returns an error if something goes wrong. q. Used fmt.Sprintf for string concatenation as this is more readable and efficient when concatenating multiple strings.
- Loading branch information
Showing
4 changed files
with
78 additions
and
34 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,32 @@ | ||
package datasetUtils | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestGetProposal(t *testing.T) { | ||
// Create a mock server | ||
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { | ||
// Send response to be tested | ||
rw.Write([]byte(`[{"proposal": "test proposal"}]`)) | ||
})) | ||
// Close the server when test finishes | ||
defer server.Close() | ||
|
||
// Create a client | ||
client := &http.Client{} | ||
|
||
// Create a user | ||
user := make(map[string]string) | ||
user["accessToken"] = "testToken" | ||
|
||
// Call GetProposal | ||
proposal, _ := GetProposal(client, server.URL, "testOwnerGroup", user, []string{"testAccessGroup"}) | ||
|
||
// Check the proposal | ||
if proposal["proposal"] != "test proposal" { | ||
t.Errorf("Expected proposal 'test proposal', got '%s'", proposal["proposal"]) | ||
} | ||
} |