42 lines
979 B
Go
42 lines
979 B
Go
package utils
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
type II interface {
|
|
foo()
|
|
}
|
|
|
|
type TT struct {
|
|
}
|
|
|
|
func (t TT) foo() {
|
|
|
|
}
|
|
func TestDictKeysMan(t *testing.T) {
|
|
testData := map[string]interface{}{"k1": "v1", "k2": "v2"}
|
|
result1 := DictKeysMan(testData, []string{"k1"}, nil).(map[string]interface{})
|
|
if _, ok := result1["k1"]; ok {
|
|
t.Error("Params keysToRemove can not remove key!")
|
|
}
|
|
if k2Value, ok := result1["k2"]; !ok {
|
|
t.Error("Params keysToRemove removed wrong key!")
|
|
} else {
|
|
k2ValueStr, _ := k2Value.(string)
|
|
if k2ValueStr != "v2" {
|
|
t.Logf("k2Value:%s", k2ValueStr)
|
|
t.Error("wrong data when removeKeys")
|
|
}
|
|
}
|
|
|
|
result2 := DictKeysMan([]interface{}{testData, map[string]string{"k1": "v11", "k2": "v22"}}, nil, []string{"k1"}).([]interface{})
|
|
result20 := result2[0].(map[string]interface{})
|
|
if _, ok := result20["k1"]; !ok {
|
|
t.Error("Params keysToKeep can not keep key!")
|
|
}
|
|
if _, ok := result20["k2"]; ok {
|
|
t.Error("Params keysToKeep keep wrong key!")
|
|
}
|
|
}
|