github.com/yandex/pandora@v0.5.32/components/providers/scenario/grpc/postprocessor/assert_response_test.go (about) 1 package postprocessor 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/golang/protobuf/proto" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 type testProto struct { 13 proto.Message 14 str string 15 } 16 17 func (t testProto) String() string { 18 return t.str 19 } 20 21 func TestAssertResponse_Process(t *testing.T) { 22 type fields struct { 23 Payload []string 24 StatusCode int 25 } 26 type args struct { 27 msg proto.Message 28 code int 29 } 30 tests := []struct { 31 name string 32 fields fields 33 args args 34 wantErr assert.ErrorAssertionFunc 35 }{ 36 { 37 name: "Valid Response", 38 fields: fields{ 39 Payload: []string{"Hello, World!"}, 40 StatusCode: http.StatusOK, 41 }, 42 args: args{ 43 msg: testProto{str: "Hello, World!"}, 44 code: 200, 45 }, 46 wantErr: assert.NoError, 47 }, 48 { 49 name: "Invalid Payload", 50 fields: fields{ 51 Payload: []string{"Invalid Text"}, 52 StatusCode: http.StatusOK, 53 }, 54 args: args{ 55 msg: testProto{str: "Hello, World!"}, 56 code: 200, 57 }, 58 wantErr: assert.Error, 59 }, 60 { 61 name: "Empty Payload", 62 fields: fields{ 63 Payload: []string{"Hello, World!"}, 64 StatusCode: http.StatusOK, 65 }, 66 args: args{ 67 msg: nil, 68 code: 200, 69 }, 70 wantErr: assert.Error, 71 }, 72 { 73 name: "Empty Payload", 74 fields: fields{ 75 Payload: []string{}, 76 StatusCode: http.StatusOK, 77 }, 78 args: args{ 79 msg: nil, 80 code: 200, 81 }, 82 wantErr: assert.NoError, 83 }, 84 { 85 name: "Invalid StatusCode", 86 fields: fields{ 87 Payload: []string{"Hello, World!"}, 88 StatusCode: http.StatusOK, 89 }, 90 args: args{ 91 msg: testProto{str: "Hello, World!"}, 92 code: 404, 93 }, 94 wantErr: assert.Error, 95 }, 96 } 97 for _, tt := range tests { 98 t.Run(tt.name, func(t *testing.T) { 99 a := AssertResponse{ 100 Payload: tt.fields.Payload, 101 StatusCode: tt.fields.StatusCode, 102 } 103 process, err := a.Process(tt.args.msg, tt.args.code) 104 assert.Nil(t, process) 105 tt.wantErr(t, err, fmt.Sprintf("Process(%v, %v)", tt.args.msg, tt.args.code)) 106 }) 107 } 108 }