提交 5e36aa14 编写于 作者: C Chris Marchbanks 提交者: Krasi Georgiev

Add test for MemPostings.Delete (#5910)

Signed-off-by: NChris Marchbanks <csmarchbanks@gmail.com>
上级 d89e7832
......@@ -20,6 +20,7 @@ import (
"sort"
"testing"
"github.com/prometheus/prometheus/tsdb/labels"
"github.com/prometheus/prometheus/util/testutil"
)
......@@ -812,3 +813,33 @@ func TestWithoutPostings(t *testing.T) {
})
}
}
func TestMemPostings_Delete(t *testing.T) {
p := NewMemPostings()
p.Add(1, labels.FromStrings("lbl1", "a"))
p.Add(2, labels.FromStrings("lbl1", "b"))
p.Add(3, labels.FromStrings("lbl2", "a"))
before := p.Get(allPostingsKey.Name, allPostingsKey.Value)
p.Delete(map[uint64]struct{}{
2: struct{}{},
})
after := p.Get(allPostingsKey.Name, allPostingsKey.Value)
// Make sure postings gotten before the delete have the old data when
// iterated over.
expanded, err := ExpandPostings(before)
testutil.Ok(t, err)
testutil.Equals(t, []uint64{1, 2, 3}, expanded)
// Make sure postings gotten after the delete have the new data when
// iterated over.
expanded, err = ExpandPostings(after)
testutil.Ok(t, err)
testutil.Equals(t, []uint64{1, 3}, expanded)
deleted := p.Get("lbl1", "b")
expanded, err = ExpandPostings(deleted)
testutil.Ok(t, err)
testutil.Assert(t, 0 == len(expanded), "expected empty postings, got %v", expanded)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册