Skip to content

Commit

Permalink
fix crud for empty object
Browse files Browse the repository at this point in the history
  • Loading branch information
arttor committed Jan 18, 2024
1 parent dd65652 commit c09d18c
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
- name: Vet
run: go vet ./...

# - name: Test
# run: go test ./...
- name: Test
run: go test ./...

# - name: golangci-lint
# uses: golangci/golangci-lint-action@v3
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release Docker images

on:
push:
tags:
- '*'

jobs:
kaniko:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: build proxy
uses: aevea/[email protected]
with:
registry: harbor.clyso.com
username: "${{ secrets.DOCKER_USER }}"
password: ${{ secrets.DOCKER_PASSWORD }}
image: chorus/proxy
build_file: Dockerfile.proxy
tag: ${{ github.ref_name }}
strip_tag_prefix: v
tag_with_latest: true
extra_args: "--build-arg GIT_TAG=${{ github.ref_name }} --build-arg GIT_COMMIT=${{ github.sha }}"
- name: build worker
uses: aevea/[email protected]
with:
registry: harbor.clyso.com
username: "${{ secrets.DOCKER_USER }}"
password: ${{ secrets.DOCKER_PASSWORD }}
image: chorus/worker
build_file: Dockerfile.worker
tag: ${{ github.ref_name }}
strip_tag_prefix: v
tag_with_latest: true
extra_args: "--build-arg GIT_TAG=${{ github.ref_name }} --build-arg GIT_COMMIT=${{ github.sha }}"
10 changes: 7 additions & 3 deletions pkg/s3client/http_client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2023 Clyso GmbH
* Copyright © 2024 Clyso GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -202,7 +202,7 @@ func (c *client) Do(req *http.Request) (resp *http.Response, isApiErr bool, err
}
url := *req.URL
//todo: support virtual host
// see: /Users/atorubar/go/pkg/mod/github.com/minio/minio-go/[email protected]/api.go:890
// see: github.com/minio/minio-go/[email protected]/api.go:890
host := strings.TrimPrefix(c.conf.Address, "http://")
host = strings.TrimPrefix(host, "https://")
url.Host = host
Expand All @@ -214,7 +214,11 @@ func (c *client) Do(req *http.Request) (resp *http.Response, isApiErr bool, err
url.ForceQuery = false

_, copyReqSpan := otel.Tracer("").Start(ctx, fmt.Sprintf("clientDo.%s.CopyReq", xctx.GetMethod(req.Context()).String()))
newReq, err = http.NewRequest(req.Method, url.String(), io.NopCloser(req.Body))
var body io.Reader = http.NoBody
if req.ContentLength != 0 {
body = io.NopCloser(req.Body)
}
newReq, err = http.NewRequest(req.Method, url.String(), body)
if err != nil {
copyReqSpan.End()
return nil, false, err
Expand Down
92 changes: 92 additions & 0 deletions test/object_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright © 2024 Clyso GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package test

import (
Expand Down Expand Up @@ -186,3 +202,79 @@ func TestApi_Object_CRUD(t *testing.T) {
}, time.Second*3, time.Millisecond*100)

}

func TestApi_Object_Folder(t *testing.T) {
t.Parallel()
bucket := "object-folder"
r := require.New(t)

err := proxyClient.MakeBucket(tstCtx, bucket, mclient.MakeBucketOptions{Region: "us-east"})
r.NoError(err)
t.Cleanup(func() {
cleanup(t, false, bucket)
})
ok, err := proxyClient.BucketExists(tstCtx, bucket)
r.NoError(err)
r.True(ok)

r.Eventually(func() bool {
ok, err = mainClient.BucketExists(tstCtx, bucket)
if err != nil || !ok {
return false
}
ok, err = f1Client.BucketExists(tstCtx, bucket)
if err != nil || !ok {
return false
}
ok, err = f2Client.BucketExists(tstCtx, bucket)
if err != nil || !ok {
return false
}
return true
}, time.Second*3, time.Millisecond*100)

objName := "folder/"
_, err = mainClient.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
r.Error(err)
_, err = f1Client.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
r.Error(err)
_, err = f2Client.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
r.Error(err)
_, err = proxyClient.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
r.Error(err)

source := []byte{}

putInfo, err := proxyClient.PutObject(tstCtx, bucket, objName, bytes.NewReader(source), int64(len(source)), mclient.PutObjectOptions{
ContentType: "binary/octet-stream", DisableContentSha256: true,
})
r.NoError(err)
r.EqualValues(objName, putInfo.Key)
r.EqualValues(bucket, putInfo.Bucket)

obj, err := proxyClient.GetObject(tstCtx, bucket, objName, mclient.GetObjectOptions{})
r.NoError(err)

objBytes, err := io.ReadAll(obj)
r.NoError(err)
r.EqualValues(source, objBytes)

_, err = proxyClient.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
r.NoError(err)

r.Eventually(func() bool {
_, err = mainClient.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
if err != nil {
return false
}
_, err = f1Client.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
if err != nil {
return false
}
_, err = f2Client.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
if err != nil {
return false
}
return true
}, time.Second*3, time.Millisecond*100)
}

0 comments on commit c09d18c

Please sign in to comment.