-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
216 additions
and
97 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
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
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,19 @@ | ||
package storage | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type GitStorage struct{} | ||
|
||
func NewGitStorage() (Storage, error) { | ||
return &GitStorage{}, nil | ||
} | ||
|
||
func (g *GitStorage) Write(ctx context.Context, key string, content []byte) error { | ||
return nil | ||
} | ||
|
||
func (g *GitStorage) Read(ctx context.Context, key string) ([]byte, error) { | ||
return nil, nil | ||
} |
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
package storage | ||
|
||
import "context" | ||
|
||
type S3Storage struct { | ||
credential string | ||
} | ||
|
||
func NewS3Storage(credential string) (Storage, error) { | ||
return &S3Storage{ | ||
credential: credential, | ||
}, nil | ||
} | ||
|
||
func (s *S3Storage) Write(ctx context.Context, key string, content []byte) error { | ||
return nil | ||
} | ||
|
||
func (s *S3Storage) Read(ctx context.Context, key string) ([]byte, error) { | ||
return nil, nil | ||
} |
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,65 @@ | ||
package storage_test | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/qiniu/reviewbot/internal/storage" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFileStorage(t *testing.T) { | ||
tempDir, err := os.MkdirTemp("", "file_storage_test") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tempDir) | ||
fs, err := storage.NewLocalStorage(tempDir) | ||
require.NoError(t, err) | ||
|
||
t.Run("Write and Read", func(t *testing.T) { | ||
ctx := context.Background() | ||
content := []byte("测试内容") | ||
path := "test.txt" | ||
err := fs.Write(ctx, path, content) | ||
require.NoError(t, err) | ||
readContent, err := fs.Read(ctx, path) | ||
require.NoError(t, err) | ||
assert.Equal(t, content, readContent) | ||
}) | ||
|
||
t.Run("Read Non-existent File", func(t *testing.T) { | ||
ctx := context.Background() | ||
_, err := fs.Read(ctx, "non_existent.txt") | ||
require.Error(t, err) | ||
}) | ||
|
||
t.Run("Write to Non-existent Directory", func(t *testing.T) { | ||
ctx := context.Background() | ||
content := []byte("测试内容") | ||
path := filepath.Join("non", "existent", "dir", "test.txt") | ||
|
||
err := fs.Write(ctx, path, content) | ||
require.NoError(t, err) | ||
|
||
readContent, err := fs.Read(ctx, path) | ||
require.NoError(t, err) | ||
require.Equal(t, content, readContent) | ||
}) | ||
|
||
t.Run("Overwrite Existing File", func(t *testing.T) { | ||
ctx := context.Background() | ||
path := "overwrite.txt" | ||
err := fs.Write(ctx, path, []byte("原始内容")) | ||
require.NoError(t, err) | ||
|
||
newContent := []byte("新内容") | ||
err = fs.Write(ctx, path, newContent) | ||
require.NoError(t, err) | ||
|
||
readContent, err := fs.Read(ctx, path) | ||
require.NoError(t, err) | ||
require.Equal(t, newContent, readContent) | ||
}) | ||
} |
Oops, something went wrong.