You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
41
variables/variables_test.go
Normal file
41
variables/variables_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package variables
|
||||
|
||||
import "testing"
|
||||
|
||||
type testFieldInStructData struct {
|
||||
f1 string
|
||||
f2 bool
|
||||
f3 int
|
||||
f4 func()
|
||||
}
|
||||
|
||||
type testFieldInStruct struct {
|
||||
data interface{}
|
||||
field string
|
||||
result bool
|
||||
}
|
||||
|
||||
var testFieldInStructCases = []testFieldInStruct{
|
||||
{testFieldInStructData{}, "f1", true},
|
||||
{testFieldInStructData{}, "f2", true},
|
||||
{testFieldInStructData{}, "f3", true},
|
||||
{testFieldInStructData{}, "f4", true},
|
||||
{testFieldInStructData{}, "f5", false},
|
||||
{[]string{}, "", false},
|
||||
{map[string]int{"oi": 4}, "", false},
|
||||
{"asa", "", false},
|
||||
{"int", "", false},
|
||||
}
|
||||
|
||||
func TestFieldInStruct(t *testing.T) {
|
||||
for _, pair := range testFieldInStructCases {
|
||||
v := FieldInStruct(pair.data, pair.field)
|
||||
if v != pair.result {
|
||||
t.Error(
|
||||
"For", pair.data,
|
||||
"expected", pair.result,
|
||||
"got", v,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user