|
6 | 6 | "strconv"
|
7 | 7 | "testing"
|
8 | 8 |
|
9 |
| - "github.com/stretchr/testify/assert" |
10 |
| - |
11 | 9 | cbor "github.com/ipfs/go-ipld-cbor"
|
| 10 | + "github.com/stretchr/testify/assert" |
12 | 11 | )
|
13 | 12 |
|
14 | 13 | type expectedChange struct {
|
@@ -102,6 +101,65 @@ func TestSimpleAdd(t *testing.T) {
|
102 | 101 | ec.assertExpectation(t, cs[0])
|
103 | 102 | }
|
104 | 103 |
|
| 104 | +func TestDiffEmptyStateWithNonEmptyState(t *testing.T) { |
| 105 | + t.Run("Removed values", func(t *testing.T) { |
| 106 | + prevBs := cbor.NewCborStore(newMockBlocks()) |
| 107 | + curBs := cbor.NewCborStore(newMockBlocks()) |
| 108 | + ctx := context.Background() |
| 109 | + |
| 110 | + prev, err := NewAMT(prevBs) |
| 111 | + assert.NoError(t, err) |
| 112 | + |
| 113 | + cur, err := NewAMT(curBs) |
| 114 | + assert.NoError(t, err) |
| 115 | + assertCount(t, cur, 0) |
| 116 | + |
| 117 | + assertSet(t, prev, 2, "foo") |
| 118 | + assertGet(ctx, t, prev, 2, "foo") |
| 119 | + assertCount(t, prev, 1) |
| 120 | + |
| 121 | + cs := diffAndAssertLength(ctx, t, prevBs, curBs, prev, cur, 1) |
| 122 | + |
| 123 | + ec := expectedChange{ |
| 124 | + Type: Remove, |
| 125 | + Key: 2, |
| 126 | + Before: "foo", |
| 127 | + After: "", |
| 128 | + } |
| 129 | + |
| 130 | + ec.assertExpectation(t, cs[0]) |
| 131 | + }) |
| 132 | + |
| 133 | + t.Run("Added values", func(t *testing.T) { |
| 134 | + prevBs := cbor.NewCborStore(newMockBlocks()) |
| 135 | + curBs := cbor.NewCborStore(newMockBlocks()) |
| 136 | + ctx := context.Background() |
| 137 | + |
| 138 | + prev, err := NewAMT(prevBs) |
| 139 | + assert.NoError(t, err) |
| 140 | + assertCount(t, prev, 0) |
| 141 | + |
| 142 | + cur, err := NewAMT(curBs) |
| 143 | + assert.NoError(t, err) |
| 144 | + |
| 145 | + assertSet(t, cur, 2, "foo") |
| 146 | + assertGet(ctx, t, cur, 2, "foo") |
| 147 | + assertCount(t, cur, 1) |
| 148 | + |
| 149 | + cs := diffAndAssertLength(ctx, t, prevBs, curBs, prev, cur, 1) |
| 150 | + |
| 151 | + ec := expectedChange{ |
| 152 | + Type: Add, |
| 153 | + Key: 2, |
| 154 | + Before: "", |
| 155 | + After: "foo", |
| 156 | + } |
| 157 | + |
| 158 | + ec.assertExpectation(t, cs[0]) |
| 159 | + |
| 160 | + }) |
| 161 | +} |
| 162 | + |
105 | 163 | func TestSimpleRemove(t *testing.T) {
|
106 | 164 | prevBs := cbor.NewCborStore(newMockBlocks())
|
107 | 165 | curBs := cbor.NewCborStore(newMockBlocks())
|
|
0 commit comments