-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemtented TestDisableVersioningLeadsToCorrectQueryParams test for …
…EOS HTTP / GRPC client
- Loading branch information
Jesse Geens
committed
Sep 30, 2024
1 parent
85e05c8
commit a1186bd
Showing
3 changed files
with
64 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
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,59 @@ | ||
package eosgrpc | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cs3org/reva/pkg/eosclient" | ||
) | ||
|
||
// Test that, when the PUTFile method is called with disableVersioning | ||
// set to true, the url for the EOS endpoint contains the right query param | ||
func TestDisableVersioningLeadsToCorrectQueryParams(t *testing.T) { | ||
|
||
stream := io.NopCloser(strings.NewReader("Hello world!")) | ||
length := int64(12) | ||
app := "my-app" | ||
urlpath := "/my-file.txt" | ||
token := "my-secret-token" | ||
|
||
// Create fake HTTP server that acts as the EOS endpoint | ||
calls := 0 | ||
mockServerUpload := httptest.NewServer( | ||
http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
calls++ | ||
queryValues := r.URL.Query() | ||
if queryValues.Get("eos.versioning") == "" { | ||
t.Errorf("Query parameter eos.versioning not set") | ||
} | ||
if q := queryValues.Get("eos.versioning"); q != strconv.Itoa(0) { | ||
t.Errorf("Query parameter eos.versioning set to wrong value; got %s, expected 0", q) | ||
} | ||
}, | ||
), | ||
) | ||
|
||
// Create EOS HTTP Client | ||
// TODO: right now, expects files to be on the FS | ||
client, err := NewEOSHTTPClient(&HTTPOptions{ | ||
BaseURL: mockServerUpload.URL, | ||
}) | ||
if err != nil { | ||
t.Errorf("Failed to construct client: %s", err.Error()) | ||
} | ||
|
||
// Test actual PUTFile call | ||
client.PUTFile(context.Background(), "remote-user", eosclient.Authorization{ | ||
Token: token}, urlpath, stream, length, app, true) | ||
|
||
// If no connection was made to the EOS endpoint, something is wrong | ||
if calls == 0 { | ||
t.Errorf("EOS endpoint was not called. ") | ||
} | ||
} |