forked from moby/buildkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep serialized protobuf binaries for testing
These serialized binaries can be used to test changes like moby#4422. Signed-off-by: Kazuyoshi Kato <[email protected]>
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package api | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/golang/protobuf/proto" | ||
moby_buildkit_v1_types "github.com/moby/buildkit/api/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var record = flag.Bool("record", false, "record actual values as fixtures") | ||
|
||
func TestProto(t *testing.T) { | ||
r := &moby_buildkit_v1_types.WorkerRecord{ | ||
ID: "hello", | ||
Labels: map[string]string{ | ||
"a": "foo", | ||
"b": "bar", | ||
"c": "baz", | ||
}, | ||
} | ||
|
||
var buf proto.Buffer | ||
buf.SetDeterministic(true) | ||
err := buf.Marshal(r) | ||
require.NoError(t, err) | ||
|
||
assertProto(t, buf.Bytes(), "WorkerRecord") | ||
} | ||
|
||
func assertProto(tb testing.TB, actual []byte, name string) { | ||
path := fmt.Sprintf("testdata/%s.bin", name) | ||
if *record { | ||
err := os.WriteFile(path, actual, 0600) | ||
require.NoError(tb, err) | ||
return | ||
} | ||
expected, err := os.ReadFile(path) | ||
require.NoError(tb, err) | ||
assert.Equal(tb, expected, actual) | ||
} |
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,5 @@ | ||
|
||
hello | ||
afoo | ||
cbaz | ||
bbar |