add dao testing cases
This commit is contained in:
11
utils/db.go
Normal file
11
utils/db.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TruncateTable(db *gorm.DB, table string) {
|
||||
db.Exec(fmt.Sprintf("TRUNCATE TABLE %s", table))
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"atom/providers/log"
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func PathExists(path string) (bool, error) {
|
||||
@@ -29,9 +26,7 @@ func CreateDir(dirs ...string) (err error) {
|
||||
return err
|
||||
}
|
||||
if !exist {
|
||||
log.Debug("create directory" + v)
|
||||
if err := os.MkdirAll(v, os.ModePerm); err != nil {
|
||||
log.Error("create directory"+v, zap.Any(" error:", err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,3 +63,12 @@ func FileExist(path string) bool {
|
||||
}
|
||||
return !os.IsNotExist(err)
|
||||
}
|
||||
|
||||
func FilePathInfo(file string) (path, name, ext string) {
|
||||
filename := filepath.Base(file)
|
||||
|
||||
path = filepath.Dir(file)
|
||||
ext = filepath.Ext(filename)
|
||||
name = strings.TrimSuffix(filename, ext)
|
||||
return
|
||||
}
|
||||
|
||||
49
utils/fs/file_test.go
Normal file
49
utils/fs/file_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package fs
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFilePathInfo(t *testing.T) {
|
||||
type args struct {
|
||||
file string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantPath string
|
||||
wantName string
|
||||
wantExt string
|
||||
}{
|
||||
{
|
||||
"1.",
|
||||
args{
|
||||
file: "/a/bc.ext",
|
||||
},
|
||||
"/a",
|
||||
"bc",
|
||||
".ext",
|
||||
},
|
||||
{
|
||||
"1.",
|
||||
args{
|
||||
file: "/a/c/c/c/bc.ext",
|
||||
},
|
||||
"/a/c/c/c",
|
||||
"bc",
|
||||
".ext",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotPath, gotName, gotExt := FilePathInfo(tt.args.file)
|
||||
if gotPath != tt.wantPath {
|
||||
t.Errorf("FilePathInfo() gotPath = %v, want %v", gotPath, tt.wantPath)
|
||||
}
|
||||
if gotName != tt.wantName {
|
||||
t.Errorf("FilePathInfo() gotName = %v, want %v", gotName, tt.wantName)
|
||||
}
|
||||
if gotExt != tt.wantExt {
|
||||
t.Errorf("FilePathInfo() gotExt = %v, want %v", gotExt, tt.wantExt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user