Skip to content

Commit

Permalink
fix: test (#36)
Browse files Browse the repository at this point in the history
* fix: test

* remove codecov
  • Loading branch information
hwbrzzl authored Dec 31, 2024
1 parent 0c3e891 commit 45dc81d
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 160 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/codecov.yml

This file was deleted.

20 changes: 17 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ on:
branches:
- master
pull_request:
env:
ALIYUN_ACCESS_KEY_ID: ${{ secrets.ALIYUN_ACCESS_KEY_ID }}
ALIYUN_ACCESS_KEY_SECRET: ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }}
ALIYUN_BUCKET: ${{ secrets.ALIYUN_BUCKET }}
ALIYUN_URL: ${{ secrets.ALIYUN_URL }}
ALIYUN_ENDPOINT: ${{ secrets.ALIYUN_ENDPOINT }}
jobs:
test:
uses: goravel/.github/.github/workflows/test.yml@master
secrets: inherit
ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Install dependencies
run: go mod tidy
- name: Run tests
run: go test -timeout 1h ./...
36 changes: 33 additions & 3 deletions oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ func (r *Oss) Directories(path string) ([]string, error) {
return nil, err
}

for _, directory := range lsRes.CommonPrefixes {
directories = append(directories, strings.ReplaceAll(directory, validPath, ""))
for _, commonPrefix := range lsRes.CommonPrefixes {
directory := strings.ReplaceAll(commonPrefix, validPath, "")
if directory != "" {
directories = append(directories, directory)
}
}

return directories, nil
Expand All @@ -191,7 +194,10 @@ func (r *Oss) Files(path string) ([]string, error) {
return nil, err
}
for _, object := range lsRes.Objects {
files = append(files, strings.ReplaceAll(object.Key, validPath, ""))
file := strings.ReplaceAll(object.Key, validPath, "")
if file != "" {
files = append(files, file)
}
}

return files, nil
Expand Down Expand Up @@ -271,6 +277,18 @@ func (r *Oss) Path(file string) string {
}

func (r *Oss) Put(file string, content string) error {
// If the file is created in a folder directly, we can't check if the folder exists.
// So we need to create the top folder first.
if !strings.HasSuffix(file, "/") {
index := strings.Index(file, "/")
if index != -1 {
folder := file[:index+1]
if err := r.MakeDirectory(folder); err != nil {
return err
}
}
}

tempFile, err := r.tempFile(content)
defer os.Remove(tempFile.Name())
if err != nil {
Expand All @@ -290,6 +308,18 @@ func (r *Oss) PutFileAs(filePath string, source filesystem.File, name string) (s
return "", err
}

// If the file is created in a folder directly, we can't check if the folder exists.
// So we need to create the top folder first.
if !strings.HasSuffix(fullPath, "/") {
index := strings.Index(fullPath, "/")
if index != -1 {
folder := fullPath[:index+1]
if err := r.MakeDirectory(folder); err != nil {
return "", err
}
}
}

if err := r.bucketInstance.PutObjectFromFile(fullPath, source.File()); err != nil {
return "", err
}
Expand Down
Loading

0 comments on commit 45dc81d

Please sign in to comment.