mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 10:37:56 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			83 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package backend
 | |
| 
 | |
| import (
 | |
| 	"reflect"
 | |
| 	"testing"
 | |
| )
 | |
| 
 | |
| func TestFieldDataGet(t *testing.T) {
 | |
| 	cases := map[string]struct {
 | |
| 		Schema map[string]*FieldSchema
 | |
| 		Raw    map[string]interface{}
 | |
| 		Key    string
 | |
| 		Value  interface{}
 | |
| 	}{
 | |
| 		"string type, string value": {
 | |
| 			map[string]*FieldSchema{
 | |
| 				"foo": &FieldSchema{Type: TypeString},
 | |
| 			},
 | |
| 			map[string]interface{}{
 | |
| 				"foo": "bar",
 | |
| 			},
 | |
| 			"foo",
 | |
| 			"bar",
 | |
| 		},
 | |
| 
 | |
| 		"string type, int value": {
 | |
| 			map[string]*FieldSchema{
 | |
| 				"foo": &FieldSchema{Type: TypeString},
 | |
| 			},
 | |
| 			map[string]interface{}{
 | |
| 				"foo": 42,
 | |
| 			},
 | |
| 			"foo",
 | |
| 			"42",
 | |
| 		},
 | |
| 
 | |
| 		"string type, unset value": {
 | |
| 			map[string]*FieldSchema{
 | |
| 				"foo": &FieldSchema{Type: TypeString},
 | |
| 			},
 | |
| 			map[string]interface{}{},
 | |
| 			"foo",
 | |
| 			"",
 | |
| 		},
 | |
| 
 | |
| 		"int type, int value": {
 | |
| 			map[string]*FieldSchema{
 | |
| 				"foo": &FieldSchema{Type: TypeInt},
 | |
| 			},
 | |
| 			map[string]interface{}{
 | |
| 				"foo": 42,
 | |
| 			},
 | |
| 			"foo",
 | |
| 			42,
 | |
| 		},
 | |
| 
 | |
| 		"bool type, bool value": {
 | |
| 			map[string]*FieldSchema{
 | |
| 				"foo": &FieldSchema{Type: TypeBool},
 | |
| 			},
 | |
| 			map[string]interface{}{
 | |
| 				"foo": false,
 | |
| 			},
 | |
| 			"foo",
 | |
| 			false,
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	for name, tc := range cases {
 | |
| 		data := &FieldData{
 | |
| 			Raw:    tc.Raw,
 | |
| 			Schema: tc.Schema,
 | |
| 		}
 | |
| 
 | |
| 		actual := data.Get(tc.Key)
 | |
| 		if !reflect.DeepEqual(actual, tc.Value) {
 | |
| 			t.Fatalf(
 | |
| 				"bad: %s\n\nExpected: %#v\nGot: %#v",
 | |
| 				name, tc.Value, actual)
 | |
| 		}
 | |
| 	}
 | |
| }
 | 
