Skip to content

Commit

Permalink
Keep serialized protobuf binaries for testing
Browse files Browse the repository at this point in the history
These serialized binaries can be used to test changes like moby#4422.

Signed-off-by: Kazuyoshi Kato <[email protected]>
  • Loading branch information
kzys committed Feb 1, 2024
1 parent 1981eb1 commit ac3a02c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
41 changes: 41 additions & 0 deletions api/proto_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package api

import (
"flag"
"fmt"
"os"
"testing"

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",
},
}
b, err := r.Marshal()
require.NoError(t, err)

assertProto(t, b, "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)
}
5 changes: 5 additions & 0 deletions api/testdata/WorkerRecord.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

hello
cbaz
bbar
afoo

0 comments on commit ac3a02c

Please sign in to comment.