Skip to content

Commit 4160207

Browse files
committed
test: add golden integration tests
Package integration is needed to test the functionality of golden in integration with the file system. Without side effects from other tests and TestMain. Large JSON inputs serve the purpose of format validation to provide an additional ability to catch changes in the behavior of the JSONEq function.
1 parent 63254b6 commit 4160207

File tree

14 files changed

+236
-0
lines changed

14 files changed

+236
-0
lines changed

‎internal/integration/golden.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright © 2019, Vasiliy Vasilyuk. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
/*
6+
Package integration is needed to test the functionality of golden
7+
in integration with the file system. Without side effects from
8+
other tests and TestMain.
9+
*/
10+
package integration
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright © 2019, Vasiliy Vasilyuk. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integration
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
12+
"github.com/xorcare/golden"
13+
)
14+
15+
func TestEqual(t *testing.T) {
16+
testTree(t, func(t *testing.T) {
17+
golden.Equal(t, golden.Read(t)).FailNow()
18+
assert.NotNil(t, golden.Read(t), "input data cannot be empty")
19+
assert.NotNil(t, golden.SetTest(t).Read(), "golden data cannot be empty")
20+
})
21+
}
22+
23+
func TestJSONEq(t *testing.T) {
24+
testTree(t, func(t *testing.T) {
25+
golden.JSONEq(t, string(golden.Read(t))).FailNow()
26+
assert.NotNil(t, golden.Read(t), "input data cannot be empty")
27+
assert.NotNil(t, golden.SetTest(t).SetPrefix("json").Read(), "golden data cannot be empty")
28+
})
29+
}
30+
31+
// testTree needed to run a test function in tests with three levels of nesting.
32+
func testTree(t *testing.T, f func(t *testing.T)) {
33+
// Simple test data without structure nesting.
34+
// testdata/TestExample.input
35+
// testdata/TestExample.golden
36+
f(t)
37+
t.Run("sublevel-one", func(t *testing.T) {
38+
// Tests with one level of nesting.
39+
// testdata/TestExample/sublevel-one.input
40+
// testdata/TestExample/sublevel-one.golden
41+
f(t)
42+
t.Run("sublevel-two", func(t *testing.T) {
43+
// Test with the second level of nesting.
44+
// testdata/TestExample/sublevel-one/sublevel-two.golden
45+
// testdata/TestExample/sublevel-one/sublevel-two.input
46+
f(t)
47+
})
48+
})
49+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01f2515f2a7e294ea03bd8434a7447687d12571b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01f2515f2a7e294ea03bd8434a7447687d12571b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01f2515f2a7e294ea03bd8434a7447687d12571b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01f2515f2a7e294ea03bd8434a7447687d12571b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01f2515f2a7e294ea03bd8434a7447687d12571b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01f2515f2a7e294ea03bd8434a7447687d12571b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"blocks":[{"hash":"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f","ver":1,"prev_block":"0000000000000000000000000000000000000000000000000000000000000000","next_block":["00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"],"mrkl_root":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b","time":1231006505,"bits":486604799,"fee":0,"nonce":2083236893,"n_tx":1,"size":285,"block_index":14849,"main_chain":true,"height":0,"tx":[{"lock_time":0,"ver":1,"size":204,"inputs":[{"sequence":4294967295,"witness":"","script":"04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73"}],"weight":816,"time":1231006505,"tx_index":14849,"vin_sz":1,"hash":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b","vout_sz":1,"relayed_by":"0.0.0.0","out":[{"addr_tag_link":"https:\/\/en.bitcoin.it\/wiki\/Genesis_block","addr_tag":"Genesis of Bitcoin","spent":false,"tx_index":14849,"type":0,"addr":"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa","value":5000000000,"n":0,"script":"4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"}]}]}]}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"blocks": [
3+
{
4+
"bits": 486604799,
5+
"block_index": 14849,
6+
"fee": 0,
7+
"hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
8+
"height": 0,
9+
"main_chain": true,
10+
"mrkl_root": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
11+
"n_tx": 1,
12+
"next_block": [
13+
"00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
14+
],
15+
"nonce": 2083236893,
16+
"prev_block": "0000000000000000000000000000000000000000000000000000000000000000",
17+
"size": 285,
18+
"time": 1231006505,
19+
"tx": [
20+
{
21+
"hash": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
22+
"inputs": [
23+
{
24+
"script": "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73",
25+
"sequence": 4294967295,
26+
"witness": ""
27+
}
28+
],
29+
"lock_time": 0,
30+
"out": [
31+
{
32+
"addr": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
33+
"addr_tag": "Genesis of Bitcoin",
34+
"addr_tag_link": "https://en.bitcoin.it/wiki/Genesis_block",
35+
"n": 0,
36+
"script": "4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac",
37+
"spent": false,
38+
"tx_index": 14849,
39+
"type": 0,
40+
"value": 5000000000
41+
}
42+
],
43+
"relayed_by": "0.0.0.0",
44+
"size": 204,
45+
"time": 1231006505,
46+
"tx_index": 14849,
47+
"ver": 1,
48+
"vin_sz": 1,
49+
"vout_sz": 1,
50+
"weight": 816
51+
}
52+
],
53+
"ver": 1
54+
}
55+
]
56+
}

0 commit comments

Comments
 (0)