Debian Codegraph @

internal/deptest/testlib/testlib.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 testlib
16
17 import (
18 "fmt"
19 "io"
20
21 "google.golang.org/grpc/encoding"
22 )
23
24 type Dummy string
25
26 var _ encoding.Compressor = Dummy("")
27
28 // AllNames lists every compressor in this repo, for testing.
29 var AllNames = []string{"zstd", "snappy", "lz4"}
30
31 func (d Dummy) Compress(io.Writer) (io.WriteCloser, error) {
32 return nil, fmt.Errorf("not implemented")
33 }
34
35 func (d Dummy) Decompress(r io.Reader) (io.Reader, error) {
36 return nil, fmt.Errorf("not implemented")
37 }
38
39 func (d Dummy) Name() string {
40 return string(d)
41 }
42
43 func init() {
44 for _, name := range AllNames {
45 // This test will not register the dummies in case
46 // of existing registrations, this ensures the import
47 // order of the deptest actually tests no-clobbering.
48 if encoding.GetCompressor(name) == nil {
49 encoding.RegisterCompressor(Dummy(name))
50 }
51 }
52 }