|
| 1 | +package eosgrpc |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "io" |
| 6 | + "net/http" |
| 7 | + "net/http/httptest" |
| 8 | + "strconv" |
| 9 | + "strings" |
| 10 | + "testing" |
| 11 | + |
| 12 | + "github.com/cs3org/reva/pkg/eosclient" |
| 13 | +) |
| 14 | + |
| 15 | +// Test that, when the PUTFile method is called with disableVersioning |
| 16 | +// set to true, the url for the EOS endpoint contains the right query param |
| 17 | +func TestDisableVersioningLeadsToCorrectQueryParams(t *testing.T) { |
| 18 | + |
| 19 | + stream := io.NopCloser(strings.NewReader("Hello world!")) |
| 20 | + length := int64(12) |
| 21 | + app := "my-app" |
| 22 | + urlpath := "/my-file.txt" |
| 23 | + token := "my-secret-token" |
| 24 | + |
| 25 | + // Create fake HTTP server that acts as the EOS endpoint |
| 26 | + calls := 0 |
| 27 | + mockServerUpload := httptest.NewServer( |
| 28 | + http.HandlerFunc( |
| 29 | + func(w http.ResponseWriter, r *http.Request) { |
| 30 | + calls++ |
| 31 | + queryValues := r.URL.Query() |
| 32 | + if queryValues.Get("eos.versioning") == "" { |
| 33 | + t.Errorf("Query parameter eos.versioning not set") |
| 34 | + } |
| 35 | + if q := queryValues.Get("eos.versioning"); q != strconv.Itoa(0) { |
| 36 | + t.Errorf("Query parameter eos.versioning set to wrong value; got %s, expected 0", q) |
| 37 | + } |
| 38 | + }, |
| 39 | + ), |
| 40 | + ) |
| 41 | + |
| 42 | + // Create EOS HTTP Client |
| 43 | + // TODO: right now, expects files to be on the FS |
| 44 | + client, err := NewEOSHTTPClient(&HTTPOptions{ |
| 45 | + BaseURL: mockServerUpload.URL, |
| 46 | + }) |
| 47 | + if err != nil { |
| 48 | + t.Errorf("Failed to construct client: %s", err.Error()) |
| 49 | + } |
| 50 | + |
| 51 | + // Test actual PUTFile call |
| 52 | + client.PUTFile(context.Background(), "remote-user", eosclient.Authorization{ |
| 53 | + Token: token}, urlpath, stream, length, app, true) |
| 54 | + |
| 55 | + // If no connection was made to the EOS endpoint, something is wrong |
| 56 | + if calls == 0 { |
| 57 | + t.Errorf("EOS endpoint was not called. ") |
| 58 | + } |
| 59 | +} |
0 commit comments