mirror of
https://github.com/elyby/chrly.git
synced 2024-11-27 01:01:59 +05:30
Add tests for filesystem driver
This commit is contained in:
parent
6c59ecbe2e
commit
803f3f406b
1
Gopkg.lock
generated
1
Gopkg.lock
generated
@ -350,6 +350,7 @@
|
|||||||
"github.com/spf13/viper",
|
"github.com/spf13/viper",
|
||||||
"github.com/stretchr/testify/assert",
|
"github.com/stretchr/testify/assert",
|
||||||
"github.com/stretchr/testify/mock",
|
"github.com/stretchr/testify/mock",
|
||||||
|
"github.com/stretchr/testify/require",
|
||||||
"github.com/stretchr/testify/suite",
|
"github.com/stretchr/testify/suite",
|
||||||
"github.com/tevino/abool",
|
"github.com/tevino/abool",
|
||||||
"github.com/thedevsaddam/govalidator",
|
"github.com/thedevsaddam/govalidator",
|
||||||
|
@ -17,10 +17,6 @@ type Filesystem struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Filesystem) FindCapeByUsername(username string) (*model.Cape, error) {
|
func (f *Filesystem) FindCapeByUsername(username string) (*model.Cape, error) {
|
||||||
if username == "" {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
capePath := path.Join(f.path, strings.ToLower(username)+".png")
|
capePath := path.Join(f.path, strings.ToLower(username)+".png")
|
||||||
file, err := os.Open(capePath)
|
file, err := os.Open(capePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
56
db/fs/fs_integration_test.go
Normal file
56
db/fs/fs_integration_test.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package fs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNew(t *testing.T) {
|
||||||
|
fs, err := New("base/path")
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.Equal(t, "base/path", fs.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFilesystem(t *testing.T) {
|
||||||
|
t.Run("FindCapeByUsername", func(t *testing.T) {
|
||||||
|
dir, err := ioutil.TempDir("", "capes")
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot crete temp directory for tests: %w", err))
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
t.Run("exists cape", func(t *testing.T) {
|
||||||
|
file, err := os.Create(path.Join(dir, "username.png"))
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot create temp skin for tests: %w", err))
|
||||||
|
}
|
||||||
|
defer os.Remove(file.Name())
|
||||||
|
|
||||||
|
fs, _ := New(dir)
|
||||||
|
cape, err := fs.FindCapeByUsername("username")
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.NotNil(t, cape)
|
||||||
|
capeFile, _ := cape.File.(*os.File)
|
||||||
|
require.Equal(t, file.Name(), capeFile.Name())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("not exists cape", func(t *testing.T) {
|
||||||
|
fs, _ := New(dir)
|
||||||
|
cape, err := fs.FindCapeByUsername("username")
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.Nil(t, cape)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("empty username", func(t *testing.T) {
|
||||||
|
fs, _ := New(dir)
|
||||||
|
cape, err := fs.FindCapeByUsername("")
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.Nil(t, cape)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user