Skip to content

Commit

Permalink
add test for determinism between proto.lock writes
Browse files Browse the repository at this point in the history
  • Loading branch information
nilslice authored and wikiwong committed Sep 3, 2018
1 parent cb43f1c commit d5d4bb9
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
proto.lock
protolock
pkg
pkg
37 changes: 37 additions & 0 deletions order_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
274 changes: 274 additions & 0 deletions proto.lock
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
}
]
}

0 comments on commit d5d4bb9

Please sign in to comment.