|
| 1 | +package schema_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/openmfp/kubernetes-graphql-gateway/gateway/schema" |
| 5 | + "reflect" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/graphql-go/graphql/language/ast" |
| 9 | + "github.com/graphql-go/graphql/language/kinds" |
| 10 | +) |
| 11 | + |
| 12 | +func TestStringMapScalar_ParseValue(t *testing.T) { |
| 13 | + tests := []struct { |
| 14 | + input interface{} |
| 15 | + expected interface{} |
| 16 | + }{ |
| 17 | + { |
| 18 | + input: map[string]interface{}{"key": "val"}, |
| 19 | + expected: map[string]interface{}{"key": "val"}, |
| 20 | + }, |
| 21 | + { |
| 22 | + input: map[string]string{"a": "b"}, |
| 23 | + expected: map[string]string{"a": "b"}, |
| 24 | + }, |
| 25 | + { |
| 26 | + input: "key=val", |
| 27 | + expected: nil, |
| 28 | + }, |
| 29 | + } |
| 30 | + |
| 31 | + for _, test := range tests { |
| 32 | + out := schema.StringMapScalar.ParseValue(test.input) |
| 33 | + if !reflect.DeepEqual(out, test.expected) { |
| 34 | + t.Errorf("ParseValue(%v) = %v; want %v", test.input, out, test.expected) |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +func TestStringMapScalar_ParseLiteral(t *testing.T) { |
| 40 | + tests := []struct { |
| 41 | + name string |
| 42 | + input ast.Value |
| 43 | + expected interface{} |
| 44 | + }{ |
| 45 | + { |
| 46 | + name: "valid_object_value", |
| 47 | + input: &ast.ObjectValue{ |
| 48 | + Kind: kinds.ObjectValue, |
| 49 | + Fields: []*ast.ObjectField{ |
| 50 | + { |
| 51 | + Name: &ast.Name{Value: "key"}, |
| 52 | + Value: &ast.StringValue{Kind: kinds.StringValue, Value: "val"}, |
| 53 | + }, |
| 54 | + { |
| 55 | + Name: &ast.Name{Value: "key2"}, |
| 56 | + Value: &ast.StringValue{Kind: kinds.StringValue, Value: "val2"}, |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | + expected: map[string]string{"key": "val", "key2": "val2"}, |
| 61 | + }, |
| 62 | + { |
| 63 | + name: "invalid_string_value", |
| 64 | + input: &ast.StringValue{Kind: kinds.StringValue, Value: "key=val"}, |
| 65 | + expected: nil, |
| 66 | + }, |
| 67 | + } |
| 68 | + |
| 69 | + for _, tt := range tests { |
| 70 | + t.Run(tt.name, func(t *testing.T) { |
| 71 | + out := schema.StringMapScalar.ParseLiteral(tt.input) |
| 72 | + if !reflect.DeepEqual(out, tt.expected) { |
| 73 | + t.Errorf("ParseLiteral() = %v, want %v", out, tt.expected) |
| 74 | + } |
| 75 | + }) |
| 76 | + } |
| 77 | +} |
0 commit comments