Repository: grpc/grpc-go
File: rpc_util_test.go (Go)

Code before:
			maxReceiveMessageSize: len("message that is too large") - 1,
			want:                  nil,
			wantErr:               errMaxMessageSizeExceeded,
		},
		{
			name:                  "Decompresses to exactly maxReceiveMessageSize",
			input:                 mustCompress(t, []byte("exact size message")),
			maxReceiveMessageSize: len("exact size message"),
			want:                  []byte("exact size message"),
			wantErr:               nil,
		},
		{
			name:                  "Handles large buffer size MaxInt",
			input:                 mustCompress(t, []byte("large message")),
			maxReceiveMessageSize: math.MaxInt,
			want:                  []byte("large message"),
			wantErr:               nil,
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			output, err := decompress(compressor, tc.input, tc.maxReceiveMessageSize, mem.DefaultBufferPool())

			if !cmp.Equal(err, tc.wantErr, cmpopts.EquateErrors()) {
				t.Fatalf("decompress() error = %v, wantErr = %v", err, tc.wantErr)
			}

			if !cmp.Equal(tc.want, output.Materialize()) {
				t.Fatalf("decompress() output mismatch: got = %v, want = %v", output.Materialize(), tc.want)
			}
		})
	}
}


Review comment (suggestion):
`t.Fatalf("decompress() err = %v, wantErr = %v", err, tc.wantErr)` or `.Fatalf("decompress() error = %v, want error = %v", err, tc.wantErr)`

Code after:
// TestDecompress tests the decompress function behaves correctly for following scenarios
// decompress successfully when message is <= maxReceiveMessageSize
// errors when message > maxReceiveMessageSize
// decompress successfully when maxReceiveMessageSize is MaxInt
// errors when the decompressed message has an invalid format
// errors when the decompressed message exceeds the maxReceiveMessageSize.
func (s) TestDecompress(t *testing.T) {
	compressor := encoding.GetCompressor("gzip")
	validDecompressor := &MockDecompressor{ShouldError: false}
	invalidFormatDecompressor := &MockDecompressor{ShouldError: true}

	testCases := []struct {
		name                  string
		input                 mem.BufferSlice
		dc                    Decompressor
		maxReceiveMessageSize int
		want                  []byte
		wantErr               error
	}{
		{
			name:                  "Decompresses successfully with sufficient buffer size",
			input:                 compressWithDeterministicError(t, []byte("decompressed data")),
			dc:                    nil,
			maxReceiveMessageSize: 50,
			want:                  []byte("decompressed data"),
			wantErr:               nil,
		},
		{
			name:                  "Fails due to exceeding maxReceiveMessageSize",
			input:                 compressWithDeterministicError(t, []byte("message that is too large")),
			dc:                    nil,
			maxReceiveMessageSize: len("message that is too large") - 1,
			want:                  nil,
			wantErr:               status.Errorf(codes.ResourceExhausted, "grpc: received message after decompression larger than max %d", len("message that is too large")-1),
		},
		{
			name:                  "Decompresses to exactly maxReceiveMessageSize",
			input:                 compressWithDeterministicError(t, []byte("exact size message")),
			dc:                    nil,
			maxReceiveMessageSize: len("exact size message"),
			want:                  []byte("exact size message"),
			wantErr:               nil,
		},
		{
			name:                  "Decompresses successfully with maxReceiveMessageSize MaxInt",
			input:                 compressWithDeterministicError(t, []byte("large message")),
			dc:                    nil,
			maxReceiveMessageSize: math.MaxInt,
			want:                  []byte("large message"),
			wantErr:               nil,
		},