mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 02:28:09 +00:00 
			
		
		
		
	Add field type TypeNameString (#3028)
This commit is contained in:
		| @@ -256,6 +256,28 @@ func TestFieldDataGet(t *testing.T) { | ||||
| 			"foo", | ||||
| 			[]string{}, | ||||
| 		}, | ||||
|  | ||||
| 		"name string type, valid string": { | ||||
| 			map[string]*FieldSchema{ | ||||
| 				"foo": &FieldSchema{Type: TypeNameString}, | ||||
| 			}, | ||||
| 			map[string]interface{}{ | ||||
| 				"foo": "bar", | ||||
| 			}, | ||||
| 			"foo", | ||||
| 			"bar", | ||||
| 		}, | ||||
|  | ||||
| 		"name string type, valid value with special characters": { | ||||
| 			map[string]*FieldSchema{ | ||||
| 				"foo": &FieldSchema{Type: TypeNameString}, | ||||
| 			}, | ||||
| 			map[string]interface{}{ | ||||
| 				"foo": "bar.baz-bay123", | ||||
| 			}, | ||||
| 			"foo", | ||||
| 			"bar.baz-bay123", | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	for name, tc := range cases { | ||||
| @@ -272,3 +294,60 @@ func TestFieldDataGet(t *testing.T) { | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestFieldDataGet_Error(t *testing.T) { | ||||
| 	cases := map[string]struct { | ||||
| 		Schema map[string]*FieldSchema | ||||
| 		Raw    map[string]interface{} | ||||
| 		Key    string | ||||
| 	}{ | ||||
| 		"name string type, invalid value with invalid characters": { | ||||
| 			map[string]*FieldSchema{ | ||||
| 				"foo": &FieldSchema{Type: TypeNameString}, | ||||
| 			}, | ||||
| 			map[string]interface{}{ | ||||
| 				"foo": "bar baz", | ||||
| 			}, | ||||
| 			"foo", | ||||
| 		}, | ||||
| 		"name string type, invalid value with special characters at beginning": { | ||||
| 			map[string]*FieldSchema{ | ||||
| 				"foo": &FieldSchema{Type: TypeNameString}, | ||||
| 			}, | ||||
| 			map[string]interface{}{ | ||||
| 				"foo": ".barbaz", | ||||
| 			}, | ||||
| 			"foo", | ||||
| 		}, | ||||
| 		"name string type, invalid value with special characters at end": { | ||||
| 			map[string]*FieldSchema{ | ||||
| 				"foo": &FieldSchema{Type: TypeNameString}, | ||||
| 			}, | ||||
| 			map[string]interface{}{ | ||||
| 				"foo": "barbaz-", | ||||
| 			}, | ||||
| 			"foo", | ||||
| 		}, | ||||
| 		"name string type, empty string": { | ||||
| 			map[string]*FieldSchema{ | ||||
| 				"foo": &FieldSchema{Type: TypeNameString}, | ||||
| 			}, | ||||
| 			map[string]interface{}{ | ||||
| 				"foo": "", | ||||
| 			}, | ||||
| 			"foo", | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	for _, tc := range cases { | ||||
| 		data := &FieldData{ | ||||
| 			Raw:    tc.Raw, | ||||
| 			Schema: tc.Schema, | ||||
| 		} | ||||
|  | ||||
| 		_, _, err := data.GetOkErr(tc.Key) | ||||
| 		if err == nil { | ||||
| 			t.Fatalf("error expected, none received") | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Chris Hoffman
					Chris Hoffman