github.com/blend/go-sdk@v1.20220411.3/validate/map_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package validate 9 10 import ( 11 "testing" 12 13 "github.com/blend/go-sdk/assert" 14 "github.com/blend/go-sdk/ex" 15 ) 16 17 func TestMapKeys(t *testing.T) { 18 assert := assert.New(t) 19 20 err := Map("foo").Keys("a", "b", "c")() 21 assert.NotNil(err) 22 assert.Equal(ErrInstanceNotMap, ex.ErrClass(err)) 23 24 bag := map[string]int{"foo": 1, "bar": 2, "baz": 3} 25 var verr error 26 verr = Map(bag).Keys("foo", "baz")() 27 assert.Nil(verr) 28 29 verr = Map(bag).Keys("foo", "buzz")() 30 assert.NotNil(verr) 31 assert.Equal(ErrMapKeys, ErrCause(verr)) 32 }