mirror of
https://github.com/weaveworks/scope.git
synced 2026-02-14 18:09:59 +00:00
Limiting env vars, docker&k8s labels, and weave net connection entries to 20 is problematic because - the truncation is arbitrary - there is a good chance that if you care about a specific entry it won't be there - the truncation is not consistent - different entries get truncated at different times - some of the rendering logic depends on specific labels, for example namespace filtering of containers depends on the `io.kubernetes.pod.namespace` label. In practice, there should never be a huge number of labels, or Weave Net connection entries. So there is no need to truncate them. That leaves env vars. These are of limited use, so we now omit them by default. If they are included they are included in full, so they are actually useful. Fixes #3127
240 lines
4.5 KiB
Go
240 lines
4.5 KiB
Go
package report_test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/weaveworks/common/test"
|
|
"github.com/weaveworks/scope/report"
|
|
)
|
|
|
|
func TestMulticolumnTables(t *testing.T) {
|
|
want := []report.Row{
|
|
{
|
|
ID: "row1",
|
|
Entries: map[string]string{
|
|
"col1": "r1c1",
|
|
"col2": "r1c2",
|
|
"col3": "r1c3",
|
|
},
|
|
},
|
|
{
|
|
ID: "row2",
|
|
Entries: map[string]string{
|
|
"col1": "r2c1",
|
|
"col3": "r2c3",
|
|
},
|
|
},
|
|
}
|
|
|
|
nmd := report.MakeNode("foo1")
|
|
nmd = nmd.AddPrefixMulticolumnTable("foo_", want)
|
|
|
|
template := report.TableTemplate{
|
|
Type: report.MulticolumnTableType,
|
|
Prefix: "foo_",
|
|
}
|
|
|
|
have, truncationCount := nmd.ExtractTable(template)
|
|
|
|
if truncationCount != 0 {
|
|
t.Error("Table shouldn't had been truncated")
|
|
}
|
|
|
|
if !reflect.DeepEqual(want, have) {
|
|
t.Error(test.Diff(want, have))
|
|
}
|
|
}
|
|
|
|
func TestPrefixPropertyLists(t *testing.T) {
|
|
want := []report.Row{
|
|
{
|
|
ID: "label_foo1",
|
|
Entries: map[string]string{
|
|
"label": "foo1",
|
|
"value": "bar1",
|
|
},
|
|
},
|
|
{
|
|
ID: "label_foo3",
|
|
Entries: map[string]string{
|
|
"label": "foo3",
|
|
"value": "bar3",
|
|
},
|
|
},
|
|
}
|
|
|
|
nmd := report.MakeNode("foo1")
|
|
nmd = nmd.AddPrefixPropertyList("foo_", map[string]string{
|
|
"foo3": "bar3",
|
|
"foo1": "bar1",
|
|
})
|
|
nmd = nmd.AddPrefixPropertyList("zzz_", map[string]string{
|
|
"foo2": "bar2",
|
|
})
|
|
|
|
template := report.TableTemplate{
|
|
Type: report.PropertyListType,
|
|
Prefix: "foo_",
|
|
}
|
|
|
|
have, truncationCount := nmd.ExtractTable(template)
|
|
|
|
if truncationCount != 0 {
|
|
t.Error("Table shouldn't had been truncated")
|
|
}
|
|
|
|
if !reflect.DeepEqual(want, have) {
|
|
t.Error(test.Diff(want, have))
|
|
}
|
|
}
|
|
|
|
func TestFixedPropertyLists(t *testing.T) {
|
|
want := []report.Row{
|
|
{
|
|
ID: "label_foo1",
|
|
Entries: map[string]string{
|
|
"label": "foo1",
|
|
"value": "bar1",
|
|
},
|
|
},
|
|
{
|
|
ID: "label_foo2",
|
|
Entries: map[string]string{
|
|
"label": "foo2",
|
|
"value": "bar2",
|
|
},
|
|
},
|
|
}
|
|
|
|
nmd := report.MakeNodeWith("foo1", map[string]string{
|
|
"foo2key": "bar2",
|
|
"foo1key": "bar1",
|
|
})
|
|
|
|
template := report.TableTemplate{
|
|
Type: report.PropertyListType,
|
|
FixedRows: map[string]string{
|
|
"foo2key": "foo2",
|
|
"foo1key": "foo1",
|
|
},
|
|
}
|
|
|
|
have, truncationCount := nmd.ExtractTable(template)
|
|
|
|
if truncationCount != 0 {
|
|
t.Error("Table shouldn't had been truncated")
|
|
}
|
|
|
|
if !reflect.DeepEqual(want, have) {
|
|
t.Error(test.Diff(want, have))
|
|
}
|
|
}
|
|
|
|
func TestTables(t *testing.T) {
|
|
want := []report.Table{
|
|
{
|
|
ID: "AAA",
|
|
Label: "Aaa",
|
|
Type: report.PropertyListType,
|
|
Columns: nil,
|
|
Rows: []report.Row{
|
|
{
|
|
ID: "label_foo1",
|
|
Entries: map[string]string{
|
|
"label": "foo1",
|
|
"value": "bar1",
|
|
},
|
|
},
|
|
{
|
|
ID: "label_foo3",
|
|
Entries: map[string]string{
|
|
"label": "foo3",
|
|
"value": "bar3",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
ID: "BBB",
|
|
Label: "Bbb",
|
|
Type: report.MulticolumnTableType,
|
|
Columns: []report.Column{{ID: "col1", Label: "Column 1"}},
|
|
Rows: []report.Row{
|
|
{
|
|
ID: "row1",
|
|
Entries: map[string]string{
|
|
"col1": "r1c1",
|
|
},
|
|
},
|
|
{
|
|
ID: "row2",
|
|
Entries: map[string]string{
|
|
"col3": "r2c3",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
ID: "CCC",
|
|
Label: "Ccc",
|
|
Type: report.PropertyListType,
|
|
Columns: nil,
|
|
Rows: []report.Row{
|
|
{
|
|
ID: "label_foo3",
|
|
Entries: map[string]string{
|
|
"label": "foo3",
|
|
"value": "bar3",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
nmd := report.MakeNodeWith("foo1", map[string]string{
|
|
"foo3key": "bar3",
|
|
"foo1key": "bar1",
|
|
})
|
|
nmd = nmd.AddPrefixMulticolumnTable("bbb_", []report.Row{
|
|
{ID: "row1", Entries: map[string]string{"col1": "r1c1"}},
|
|
{ID: "row2", Entries: map[string]string{"col3": "r2c3"}},
|
|
})
|
|
nmd = nmd.AddPrefixPropertyList("aaa_", map[string]string{
|
|
"foo3": "bar3",
|
|
"foo1": "bar1",
|
|
})
|
|
|
|
aaaTemplate := report.TableTemplate{
|
|
ID: "AAA",
|
|
Label: "Aaa",
|
|
Prefix: "aaa_",
|
|
Type: report.PropertyListType,
|
|
}
|
|
bbbTemplate := report.TableTemplate{
|
|
ID: "BBB",
|
|
Label: "Bbb",
|
|
Prefix: "bbb_",
|
|
Type: report.MulticolumnTableType,
|
|
Columns: []report.Column{{ID: "col1", Label: "Column 1"}},
|
|
}
|
|
cccTemplate := report.TableTemplate{
|
|
ID: "CCC",
|
|
Label: "Ccc",
|
|
Prefix: "ccc_",
|
|
Type: report.PropertyListType,
|
|
FixedRows: map[string]string{"foo3key": "foo3"},
|
|
}
|
|
templates := report.TableTemplates{
|
|
aaaTemplate.ID: aaaTemplate,
|
|
bbbTemplate.ID: bbbTemplate,
|
|
cccTemplate.ID: cccTemplate,
|
|
}
|
|
|
|
have := templates.Tables(nmd)
|
|
|
|
if !reflect.DeepEqual(want, have) {
|
|
t.Error(test.Diff(want, have))
|
|
}
|
|
}
|