mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Identify task (#1839)
* Add identify task * Change type naming * Debounce folder select text input * Add generic slice comparison function
This commit is contained in:
83
pkg/utils/reflect_test.go
Normal file
83
pkg/utils/reflect_test.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNotNilFields(t *testing.T) {
|
||||
v := "value"
|
||||
var zeroStr string
|
||||
|
||||
type testObject struct {
|
||||
ptrField *string `tag:"ptrField"`
|
||||
noTagField *string
|
||||
otherTagField *string `otherTag:"otherTagField"`
|
||||
sliceField []string `tag:"sliceField"`
|
||||
}
|
||||
|
||||
type args struct {
|
||||
subject interface{}
|
||||
tag string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
"basic",
|
||||
args{
|
||||
testObject{
|
||||
ptrField: &v,
|
||||
noTagField: &v,
|
||||
otherTagField: &v,
|
||||
sliceField: []string{v},
|
||||
},
|
||||
"tag",
|
||||
},
|
||||
[]string{"ptrField", "sliceField"},
|
||||
},
|
||||
{
|
||||
"empty",
|
||||
args{
|
||||
testObject{},
|
||||
"tag",
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"zero values",
|
||||
args{
|
||||
testObject{
|
||||
ptrField: &zeroStr,
|
||||
noTagField: &zeroStr,
|
||||
otherTagField: &zeroStr,
|
||||
sliceField: []string{},
|
||||
},
|
||||
"tag",
|
||||
},
|
||||
[]string{"ptrField", "sliceField"},
|
||||
},
|
||||
{
|
||||
"other tag",
|
||||
args{
|
||||
testObject{
|
||||
ptrField: &v,
|
||||
noTagField: &v,
|
||||
otherTagField: &v,
|
||||
sliceField: []string{v},
|
||||
},
|
||||
"otherTag",
|
||||
},
|
||||
[]string{"otherTagField"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := NotNilFields(tt.args.subject, tt.args.tag); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NotNilFields() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user