Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Jan 10, 2024
1 parent c560fa9 commit b8abd72
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
3 changes: 2 additions & 1 deletion pkg/storage/fs/nextcloud/nextcloud_server_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ var responses = map[string]Response{

`POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/GetMD {"ref":{"path":"/file"},"mdKeys":null}`: {404, ``, serverStateEmpty},
`POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/InitiateUpload {"ref":{"path":"/file"},"uploadLength":0,"metadata":{"providerID":""}}`: {200, `{"simple": "yes","tus": "yes"}`, serverStateEmpty},
`POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/InitiateUpload {"ref":{"resource_id":{"storage_id":"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"},"path":"/versionedFile"},"uploadLength":0,"metadata":{}}`: {200, `{"simple": "yes","tus": "yes"}`, serverStateEmpty},
`POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/InitiateUpload {"ref":{"resource_id":{"storage_id":"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"},"path":"/versionedFile"},"uploadLength":1,"metadata":{}}`: {200, `{"simple": "yes","tus": "yes"}`, serverStateEmpty},
`POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/InitiateUpload {"ref":{"resource_id":{"storage_id":"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"},"path":"/versionedFile"},"uploadLength":2,"metadata":{}}`: {200, `{"simple": "yes","tus": "yes"}`, serverStateEmpty},

`POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/GetMD {"ref":{"path":"/yes"},"mdKeys":[]}`: {200, `{"opaque":{},"type":1,"id":{"opaque_id":"fileid-/yes"},"checksum":{},"etag":"deadbeef","mime_type":"text/plain","mtime":{"seconds":1234567890},"path":"/yes","permission_set":{},"size":1,"canonical_metadata":{},"arbitrary_metadata":{}}`, serverStateEmpty},

Expand Down
47 changes: 29 additions & 18 deletions tests/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"

"github.com/owncloud/ocis/v2/services/webdav/pkg/net"
"github.com/pkg/errors"
"github.com/studio-b12/gowebdav"

gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/v2/internal/http/services/datagateway"
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/cs3org/reva/v2/pkg/rhttp"
"github.com/cs3org/reva/v2/pkg/storage"
"github.com/cs3org/reva/v2/pkg/utils"
)

// TempDir creates a temporary directory in tmp/ and returns its path
Expand Down Expand Up @@ -238,31 +242,38 @@ func CreateStructure(ctx context.Context, gw gatewayv1beta1.GatewayAPIClient, ro

// CreateFile creates a file in the given path with an initial content.
func CreateFile(ctx context.Context, gw gatewayv1beta1.GatewayAPIClient, ref *provider.Reference, content []byte) error {
initRes, err := gw.InitiateFileUpload(ctx, &provider.InitiateFileUploadRequest{Ref: ref})
length := int64(len(content))
initRes, err := gw.InitiateFileUpload(ctx, &provider.InitiateFileUploadRequest{
Opaque: utils.AppendPlainToOpaque(&typespb.Opaque{}, net.HeaderUploadLength, strconv.FormatInt(length, 10)),
Ref: ref,
})
if err != nil {
return err
}
var token, endpoint string
for _, p := range initRes.Protocols {
if p.Protocol == "simple" {
token, endpoint = p.Token, p.UploadEndpoint

if length > 0 {
var token, endpoint string
for _, p := range initRes.Protocols {
if p.Protocol == "simple" {
token, endpoint = p.Token, p.UploadEndpoint
}
}
httpReq, err := rhttp.NewRequest(ctx, http.MethodPut, endpoint, bytes.NewReader(content))
if err != nil {
return err
}
}
httpReq, err := rhttp.NewRequest(ctx, http.MethodPut, endpoint, bytes.NewReader(content))
if err != nil {
return err
}

httpReq.Header.Set(datagateway.TokenTransportHeader, token)
httpReq.Header.Set(datagateway.TokenTransportHeader, token)

httpRes, err := http.DefaultClient.Do(httpReq)
if err != nil {
return err
}
if httpRes.StatusCode != http.StatusOK {
return errors.New(httpRes.Status)
httpRes, err := http.DefaultClient.Do(httpReq)
if err != nil {
return err
}
if httpRes.StatusCode != http.StatusOK {
return errors.New(httpRes.Status)
}
defer httpRes.Body.Close()
}
defer httpRes.Body.Close()
return nil
}

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ID":"cdd6db6c-331b-470e-8984-ea17caf555a4","Size":0,"SizeIsDeferred":false,"Offset":0,"MetaData":{"dir":"/","filename":"6b8f7ecf-e0c2-4ce5-9f7d-3f074aec8a8a","idp":"cesnet.cz","user":"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"},"IsPartial":false,"IsFinal":false,"PartialUploads":null,"Storage":{"Path":"uploads","Type":"OCM"}}

0 comments on commit b8abd72

Please sign in to comment.