Skip to content

Commit

Permalink
Add test and import testify.assert tool (#146)
Browse files Browse the repository at this point in the history
* optimaze switch code

Signed-off-by: jyz0309 <45495947@qq.com>

* add test

Signed-off-by: jyz0309 <45495947@qq.com>

* remove useless test

Signed-off-by: jyz0309 <45495947@qq.com>

* remove go mod

Signed-off-by: jyz0309 <45495947@qq.com>

* revert go check

Signed-off-by: jyz0309 <45495947@qq.com>
  • Loading branch information
jyz0309 authored Jun 24, 2021
1 parent 4767de5 commit cfb25f1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
8 changes: 2 additions & 6 deletions pkg/base/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ func FileExists(filename string) bool {

func IsValidType(t string) bool {
switch strings.ToLower(t) {
case "string":
case "int":
case "float":
case "double":
case "bool":
case "timestamp":
case "string", "int", "float", "double", "bool", "timestamp":
break
default:
return false
}
Expand Down
31 changes: 31 additions & 0 deletions pkg/base/tools_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package base

import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)

func TestFileExists(t *testing.T) {
fileName := "test.csv"
var isExist bool
isExist = FileExists(fileName)
assert.False(t, isExist)
file := MustCreateFile(fileName)
isExist = FileExists(fileName)
assert.True(t, isExist)
file.Close()
os.Remove(fileName)
}

func TestIsValidType(t *testing.T) {
assert.True(t, IsValidType("string"))
assert.True(t, IsValidType("int"))
assert.True(t, IsValidType("float"))
assert.False(t, IsValidType("date"))
assert.False(t, IsValidType("byte"))
assert.False(t, IsValidType("datetime"))
assert.True(t, IsValidType("bool"))
assert.True(t, IsValidType("timestamp"))
assert.True(t, IsValidType("double"))
}

0 comments on commit cfb25f1

Please sign in to comment.