mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-25 00:06:46 +00:00
Fix and extend tests
This commit is contained in:
@@ -48,6 +48,11 @@ func TestNodeTables(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: docker.ImageTableID,
|
||||
Label: "Image",
|
||||
Rows: []report.MetadataRow{},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -34,8 +34,8 @@ func (node Node) AddPrefixTable(prefix string, labels map[string]string) Node {
|
||||
return node
|
||||
}
|
||||
|
||||
// extractTable returns the key-value pairs to build a table from this node
|
||||
func (node Node) extractTable(template TableTemplate) (rows map[string]string, truncationCount int) {
|
||||
// ExtractTable returns the key-value pairs to build a table from this node
|
||||
func (node Node) ExtractTable(template TableTemplate) (rows map[string]string, truncationCount int) {
|
||||
rows = map[string]string{}
|
||||
truncationCount = 0
|
||||
node.Latest.ForEach(func(key string, _ time.Time, value string) {
|
||||
@@ -141,7 +141,7 @@ type TableTemplates map[string]TableTemplate
|
||||
func (t TableTemplates) Tables(node Node) []Table {
|
||||
var result []Table
|
||||
for _, template := range t {
|
||||
rows, truncationCount := node.extractTable(template)
|
||||
rows, truncationCount := node.ExtractTable(template)
|
||||
table := Table{
|
||||
ID: template.ID,
|
||||
Label: template.Label,
|
||||
|
||||
@@ -9,15 +9,15 @@ import (
|
||||
"github.com/weaveworks/scope/test"
|
||||
)
|
||||
|
||||
func TestTables(t *testing.T) {
|
||||
func TestPrefixTables(t *testing.T) {
|
||||
want := map[string]string{
|
||||
"foo1": "bar1",
|
||||
"foo2": "bar2",
|
||||
}
|
||||
nmd := report.MakeNode("foo1")
|
||||
|
||||
nmd = nmd.AddTable("foo_", want)
|
||||
have, truncationCount := nmd.ExtractTable("foo_")
|
||||
nmd = nmd.AddPrefixTable("foo_", want)
|
||||
have, truncationCount := nmd.ExtractTable(report.TableTemplate{Prefix: "foo_"})
|
||||
|
||||
if truncationCount != 0 {
|
||||
t.Error("Table shouldn't had been truncated")
|
||||
@@ -28,6 +28,29 @@ func TestTables(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFixedTables(t *testing.T) {
|
||||
want := map[string]string{
|
||||
"foo1": "bar1",
|
||||
"foo2": "bar2",
|
||||
}
|
||||
nmd := report.MakeNodeWith("foo1", map[string]string{
|
||||
"foo1key": "bar1",
|
||||
"foo2key": "bar2",
|
||||
})
|
||||
|
||||
template := report.TableTemplate{FixedRows: map[string]string{
|
||||
"foo1key": "foo1",
|
||||
"foo2key": "foo2",
|
||||
},
|
||||
}
|
||||
|
||||
have, _ := nmd.ExtractTable(template)
|
||||
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Error(test.Diff(want, have))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTruncation(t *testing.T) {
|
||||
wantTruncationCount := 1
|
||||
want := map[string]string{}
|
||||
@@ -39,8 +62,8 @@ func TestTruncation(t *testing.T) {
|
||||
|
||||
nmd := report.MakeNode("foo1")
|
||||
|
||||
nmd = nmd.AddTable("foo_", want)
|
||||
_, truncationCount := nmd.ExtractTable("foo_")
|
||||
nmd = nmd.AddPrefixTable("foo_", want)
|
||||
_, truncationCount := nmd.ExtractTable(report.TableTemplate{Prefix: "foo_"})
|
||||
|
||||
if truncationCount != wantTruncationCount {
|
||||
t.Error(
|
||||
|
||||
Reference in New Issue
Block a user