-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
grpcclient: Support custom gRPC compressors (#583)
* grpcclient: Support custom gRPC compressors --------- Signed-off-by: Arve Knudsen <[email protected]>
- Loading branch information
Showing
3 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package grpcclient | ||
|
||
import ( | ||
"flag" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
t.Run("custom compressors", func(t *testing.T) { | ||
const comp = "custom" | ||
cfg := Config{ | ||
CustomCompressors: []string{comp}, | ||
} | ||
fs := flag.NewFlagSet("test", flag.PanicOnError) | ||
cfg.RegisterFlagsWithPrefix("test", fs) | ||
f := fs.Lookup("test.grpc-compression") | ||
require.NotNil(t, f) | ||
require.Equal(t, "Use compression when sending messages. Supported values are: 'gzip', 'snappy', 'custom' and '' (disable compression)", f.Usage) | ||
|
||
t.Run("valid compressor", func(t *testing.T) { | ||
cfg.GRPCCompression = comp | ||
|
||
require.NoError(t, cfg.Validate()) | ||
opts := cfg.CallOptions() | ||
|
||
var compressorOpt grpc.CompressorCallOption | ||
for _, o := range opts { | ||
co, ok := o.(grpc.CompressorCallOption) | ||
if ok { | ||
compressorOpt = co | ||
break | ||
} | ||
} | ||
require.Equal(t, comp, compressorOpt.CompressorType) | ||
}) | ||
|
||
t.Run("invalid compressor", func(t *testing.T) { | ||
cfg.GRPCCompression = "invalid" | ||
|
||
require.EqualError(t, cfg.Validate(), `unsupported compression type: "invalid"`) | ||
}) | ||
}) | ||
} |