File tree 2 files changed +47
-0
lines changed
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+
2
+ +docker-image://docker.io/library/foo:latest
3
+ afoo
4
+ bbar
5
+ cbaz
You can’t perform that action at this time.
0 commit comments