github.com/grpc-ecosystem/grpc-gateway/v2@v2.19.1/protoc-gen-openapiv2/internal/genopenapi/helpers_test.go (about) 1 package genopenapi 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func Test_getUniqueFields(t *testing.T) { 9 type args struct { 10 schemaFieldsRequired []string 11 fieldsRequired []string 12 } 13 var tests = []struct { 14 name string 15 args args 16 want []string 17 }{ 18 { 19 name: "test_1", 20 args: args{ 21 schemaFieldsRequired: []string{"Field_1", "Field_2", "Field_3"}, 22 fieldsRequired: []string{"Field_2"}, 23 }, 24 want: []string{"Field_1", "Field_3"}, 25 }, 26 { 27 name: "test_2", 28 args: args{ 29 schemaFieldsRequired: []string{"Field_1", "Field_2", "Field_3"}, 30 fieldsRequired: []string{"Field_3"}, 31 }, 32 want: []string{"Field_1", "Field_2"}, 33 }, 34 { 35 name: "test_3", 36 args: args{ 37 schemaFieldsRequired: []string{"Field_1", "Field_2", "Field_3"}, 38 fieldsRequired: []string{"Field_4"}, 39 }, 40 want: []string{"Field_1", "Field_2", "Field_3"}, 41 }, 42 { 43 name: "test_4", 44 args: args{ 45 schemaFieldsRequired: []string{"Field_1", "Field_2", "Field_3", "Field_4", "Field_5", "Field_6"}, 46 fieldsRequired: []string{"Field_6", "Field_4", "Field_1"}, 47 }, 48 want: []string{"Field_2", "Field_3", "Field_5"}, 49 }, 50 { 51 name: "test_5", 52 args: args{ 53 schemaFieldsRequired: []string{"Field_1", "Field_2", "Field_3"}, 54 fieldsRequired: []string{}, 55 }, 56 want: []string{"Field_1", "Field_2", "Field_3"}, 57 }, 58 } 59 for _, tt := range tests { 60 t.Run(tt.name, func(t *testing.T) { 61 if got := getUniqueFields(tt.args.schemaFieldsRequired, tt.args.fieldsRequired); !reflect.DeepEqual(got, tt.want) { 62 t.Errorf("getUniqueFields() = %v, want %v", got, tt.want) 63 } 64 }) 65 } 66 }