From d5d4bb9b878be24a92f50776934a4db9f11a3ab3 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Sun, 2 Sep 2018 15:52:06 -0600 Subject: [PATCH] add test for determinism between proto.lock writes --- .gitignore | 3 +- order_test.go | 37 +++++++ proto.lock | 274 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 312 insertions(+), 2 deletions(-) create mode 100644 order_test.go create mode 100644 proto.lock diff --git a/.gitignore b/.gitignore index 328b756..ac430f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -proto.lock protolock -pkg +pkg \ No newline at end of file diff --git a/order_test.go b/order_test.go new file mode 100644 index 0000000..c677d14 --- /dev/null +++ b/order_test.go @@ -0,0 +1,37 @@ +package protolock + +import ( + "encoding/json" + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +const ignoreArg = "" + +func TestOrder(t *testing.T) { + // verify that the re-production of the same Protolock encoded as json + // is equivalent to any previously encoded version of the same Protolock + f, err := os.Open("proto.lock") + assert.NoError(t, err) + + current, err := protolockFromReader(f) + assert.NoError(t, err) + + r, err := Commit(ignoreArg) + assert.NoError(t, err) + assert.NotNil(t, r) + + updated, err := protolockFromReader(r) + assert.NoError(t, err) + + assert.Equal(t, current, updated) + + a, err := json.Marshal(current) + assert.NoError(t, err) + b, err := json.Marshal(updated) + assert.NoError(t, err) + + assert.Equal(t, a, b) +} diff --git a/proto.lock b/proto.lock new file mode 100644 index 0000000..304b9bf --- /dev/null +++ b/proto.lock @@ -0,0 +1,274 @@ +{ + "definitions": [ + { + "protopath": "testdata:/:getProtoFiles:/:exclude:/:test.proto", + "def": { + "messages": [ + { + "name": "Test", + "fields": [ + { + "id": 1, + "name": "name", + "type": "string" + } + ] + } + ] + } + }, + { + "protopath": "testdata:/:getProtoFiles:/:exclude.proto", + "def": { + "messages": [ + { + "name": "Exclude", + "fields": [ + { + "id": 1, + "name": "name", + "type": "string" + } + ] + } + ] + } + }, + { + "protopath": "testdata:/:getProtoFiles:/:include:/:exclude.proto", + "def": { + "messages": [ + { + "name": "Exclude", + "fields": [ + { + "id": 1, + "name": "name", + "type": "string" + } + ] + } + ] + } + }, + { + "protopath": "testdata:/:getProtoFiles:/:include:/:include.proto", + "def": { + "messages": [ + { + "name": "Include", + "fields": [ + { + "id": 1, + "name": "name", + "type": "string" + } + ] + } + ] + } + }, + { + "protopath": "testdata:/:test.proto", + "def": { + "enums": [ + { + "name": "TestEnum", + "enum_fields": [ + { + "name": "FIRST", + "integer": 0 + }, + { + "name": "SECOND", + "integer": 1 + }, + { + "name": "SEGUNDO", + "integer": 1 + } + ], + "reserved_ids": [ + 2 + ] + }, + { + "name": "ContainsEnum.NestedEnum", + "enum_fields": [ + { + "name": "ABC", + "integer": 1 + }, + { + "name": "DEF", + "integer": 2 + } + ], + "reserved_ids": [ + 101 + ], + "reserved_names": [ + "DEPTH" + ] + } + ], + "messages": [ + { + "name": "Channel", + "fields": [ + { + "id": 1, + "name": "id", + "type": "int64" + }, + { + "id": 2, + "name": "name", + "type": "string" + }, + { + "id": 3, + "name": "description", + "type": "string" + }, + { + "id": 4, + "name": "foo", + "type": "string" + }, + { + "id": 5, + "name": "age", + "type": "int32" + }, + { + "id": 44, + "name": "msg", + "type": "A" + } + ], + "reserved_ids": [ + 6, + 8, + 9, + 10, + 11 + ], + "messages": [ + { + "name": "A", + "fields": [ + { + "id": 1, + "name": "id", + "type": "int32" + } + ] + } + ] + }, + { + "name": "Display", + "fields": [ + { + "id": 1, + "name": "width", + "type": "int32" + }, + { + "id": 2, + "name": "height", + "type": "int32" + }, + { + "id": 44, + "name": "msg", + "type": "A" + } + ], + "maps": [ + { + "key_type": "string", + "field": { + "id": 4, + "name": "b_map", + "type": "int32" + } + } + ], + "reserved_ids": [ + 3 + ], + "reserved_names": [ + "a_map" + ], + "messages": [ + { + "name": "A", + "fields": [ + { + "id": 1, + "name": "id", + "type": "int64" + } + ], + "reserved_ids": [ + 2 + ] + } + ] + }, + { + "name": "ContainsEnum", + "fields": [ + { + "id": 1, + "name": "id", + "type": "int32" + }, + { + "id": 2, + "name": "value", + "type": "NestedEnum" + } + ] + }, + { + "name": "PreviousRequest", + "fields": [ + { + "id": 4, + "name": "name", + "type": "string" + }, + { + "id": 9, + "name": "is_active", + "type": "bool" + } + ] + } + ], + "services": [ + { + "name": "ChannelChanger", + "rpcs": [ + { + "name": "Next", + "in_type": "NextRequest", + "out_type": "Channel", + "in_streamed": true + }, + { + "name": "Previous", + "in_type": "PreviousRequest", + "out_type": "Channel", + "out_streamed": true + } + ] + } + ] + } + } + ] +} \ No newline at end of file