(t *testing.T)
| 93 | } |
| 94 | |
| 95 | func TestScopedDistinctDiff(t *testing.T) { |
| 96 | c := NewScopedDistinctStringWithDiff(0, 0, 0) |
| 97 | |
| 98 | c.Collect("scope1", "val1") |
| 99 | expected := map[string][]string{ |
| 100 | "scope1": {"val1"}, |
| 101 | } |
| 102 | assertMaps(t, expected, readScopedDistinctStringDiff(t, c)) |
| 103 | |
| 104 | // no diff |
| 105 | c.Collect("scope1", "val1") |
| 106 | expected = map[string][]string{} |
| 107 | assertMaps(t, expected, readScopedDistinctStringDiff(t, c)) |
| 108 | assertMaps(t, map[string][]string{}, readScopedDistinctStringDiff(t, c)) |
| 109 | |
| 110 | // new value |
| 111 | c.Collect("scope1", "val2") |
| 112 | expected = map[string][]string{ |
| 113 | "scope1": {"val2"}, |
| 114 | } |
| 115 | assertMaps(t, expected, readScopedDistinctStringDiff(t, c)) |
| 116 | assertMaps(t, map[string][]string{}, readScopedDistinctStringDiff(t, c)) |
| 117 | |
| 118 | // new scope |
| 119 | c.Collect("scope2", "val1") |
| 120 | expected = map[string][]string{ |
| 121 | "scope2": {"val1"}, |
| 122 | } |
| 123 | assertMaps(t, expected, readScopedDistinctStringDiff(t, c)) |
| 124 | assertMaps(t, map[string][]string{}, readScopedDistinctStringDiff(t, c)) |
| 125 | |
| 126 | // all |
| 127 | c.Collect("scope2", "val1") |
| 128 | c.Collect("scope2", "val2") |
| 129 | c.Collect("scope1", "val3") |
| 130 | expected = map[string][]string{ |
| 131 | "scope1": {"val3"}, |
| 132 | "scope2": {"val2"}, |
| 133 | } |
| 134 | assertMaps(t, expected, readScopedDistinctStringDiff(t, c)) |
| 135 | assertMaps(t, map[string][]string{}, readScopedDistinctStringDiff(t, c)) |
| 136 | |
| 137 | // diff should error when diff is not enabled |
| 138 | col := NewScopedDistinctString(0, 0, 0) |
| 139 | col.Collect("scope1", "val1") |
| 140 | res, err := col.Diff() |
| 141 | require.Nil(t, res) |
| 142 | require.Error(t, err, errDiffNotEnabled) |
| 143 | } |
| 144 | |
| 145 | func readScopedDistinctStringDiff(t *testing.T, d *ScopedDistinctString) map[string][]string { |
| 146 | res, err := d.Diff() |
nothing calls this directly
no test coverage detected