Skip to content

Commit cad2c8e

Browse files
committed
Keep serialized protobuf binaries for testing
These serialized binaries can be used to test changes like #4422. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 1981eb1 commit cad2c8e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

solver/pb/proto_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package pb
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
var record = flag.Bool("record", false, "record actual values as fixtures")
14+
15+
func TestProto(t *testing.T) {
16+
// Because of stable_marshaler_all, the map will be sorted in the result binary.
17+
r := &SourceOp{
18+
Identifier: "docker-image://docker.io/library/foo:latest",
19+
Attrs: map[string]string{
20+
"a": "foo",
21+
"b": "bar",
22+
"c": "baz",
23+
},
24+
}
25+
26+
b, err := r.Marshal()
27+
require.NoError(t, err)
28+
29+
assertProto(t, b, "SourceOp")
30+
}
31+
32+
func assertProto(tb testing.TB, actual []byte, name string) {
33+
path := fmt.Sprintf("testdata/%s.bin", name)
34+
if *record {
35+
err := os.WriteFile(path, actual, 0600)
36+
require.NoError(tb, err)
37+
return
38+
}
39+
expected, err := os.ReadFile(path)
40+
require.NoError(tb, err)
41+
assert.Equal(tb, expected, actual)
42+
}

solver/pb/testdata/SourceOp.bin

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
+docker-image://docker.io/library/foo:latest
3+
afoo
4+
bbar
5+
cbaz

0 commit comments

Comments
 (0)