Debian Codegraph @

internal/deptest/deptest_test.go

raw
1 // Copyright 2020 Mostyn Bramley-Moore.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // package deptest ensures that the go-grpc-compression sub-packages will
16 // not clobber an existing registration.
17 package deptest
18
19 import (
20 "testing"
21
22 // This import happens first for the test, keep it ahead of
23 // the three unnamed imports below.
24 "github.com/mostynb/go-grpc-compression/internal/deptest/testlib"
25
26 // If these were moved above, the test would fail because
27 // testlib has the same no-clobber logic as the main packages.
28 _ "github.com/mostynb/go-grpc-compression/nonclobbering/lz4"
29 _ "github.com/mostynb/go-grpc-compression/nonclobbering/snappy"
30 _ "github.com/mostynb/go-grpc-compression/nonclobbering/zstd"
31
32 "github.com/stretchr/testify/require"
33 "google.golang.org/grpc/encoding"
34 )
35
36 func TestCompressorNotClobbered(t *testing.T) {
37 // Because the deptest/lib imports first, it's init() function
38 // registers dummy compressors. The following libraries do not
39 // clobber, so we should find Dummy compressors.
40 for _, name := range testlib.AllNames {
41 _, ok := encoding.GetCompressor(name).(testlib.Dummy)
42 require.True(t, ok)
43 }
44 }