Skip to content

Commit

Permalink
enhance tests to cover the new function 'chkMaxWidthOfColums'
Browse files Browse the repository at this point in the history
  • Loading branch information
angelabriel committed Apr 25, 2024
1 parent 826b759 commit 227cd55
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
3 changes: 3 additions & 0 deletions actions/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ func getInformSettings(nID string, nComparisons map[string]map[string]note.Field
func setWidthOfColums(compare note.FieldComparison, c1, c2, c3, c4 int) (int, int, int, int) {
if len(compare.ReflectMapKey) != 0 {
if compare.ReflectFieldName == "OverrideParams" && len(compare.ActualValueJS) > c1 {
// in case of override content of ActualValueJS and
// ExpectedValueJS is the same, so one length check
// is sufficient
c1 = len(compare.ActualValueJS)
c1, c3, c4 = chkMaxWidthOfColums([]int{c1, c3, c4})
return c1, c2, c3, c4
Expand Down
42 changes: 32 additions & 10 deletions actions/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,62 @@ func TestSetWidthOfColums(t *testing.T) {
w4 := 5
v1, v2, v3, v4 := setWidthOfColums(compare, w1, w2, w3, w4)
if v1 != w1 {
t.Fatal(v1, w1)
t.Error(v1, w1)
}
if v2 != 16 {
t.Fatal(v2, w2)
t.Error(v2, w2)
}
if v3 != w3 || v4 != w4 {
t.Fatal(v3, w3, v4, w4)
t.Error(v3, w3, v4, w4)
}
compare = note.FieldComparison{ReflectFieldName: "OverrideParams", ReflectMapKey: "IO_SCHEDULER_sr0", ActualValueJS: "cfq", ExpectedValueJS: "cfq"}
v1, v2, v3, v4 = setWidthOfColums(compare, w1, w2, w3, w4)
if v1 != 3 {
t.Fatal(v1, w1)
t.Error(v1, w1)
}
if v2 != w2 || v3 != w3 || v4 != w4 {
t.Fatal(v2, w2, v3, w3, v4, w4)
t.Error(v2, w2, v3, w3, v4, w4)
}
compare = note.FieldComparison{ReflectFieldName: "SysctlParams", ReflectMapKey: "governor", ActualValueJS: "all-none", ExpectedValueJS: "all-performance"}
v1, v2, v3, v4 = setWidthOfColums(compare, w1, w2, w3, w4)
if v1 != w1 {
t.Fatal(v1, w1)
t.Error(v1, w1)
}
if v2 != 8 {
t.Fatal(v2, w2)
t.Error(v2, w2)
}
if v3 != 15 {
t.Fatal(v3, w3)
t.Error(v3, w3)
}
if v4 != 8 {
t.Fatal(v4, w4)
t.Error(v4, w4)
}
compare = note.FieldComparison{ReflectFieldName: "SysctlParams", ReflectMapKey: "", ActualValueJS: "all-none", ExpectedValueJS: "all-performance"}
v1, v2, v3, v4 = setWidthOfColums(compare, w1, w2, w3, w4)
if v1 != w1 || v2 != w2 || v3 != w3 || v4 != w4 {
t.Fatal(v1, w1, v2, w2, v3, w3, v4, w4)
t.Error(v1, w1, v2, w2, v3, w3, v4, w4)
}
compare = note.FieldComparison{ReflectFieldName: "SysctlParams", ReflectMapKey: "net.ipv4.ip_local_reserved_ports", ActualValueJS: "", ExpectedValueJS: "1089-1090,1095,1099,1200-1599,2000-2002,3200-3399,3500,3600-3699,3900-4001"}
v1, v2, v3, v4 = setWidthOfColums(compare, w1, w2, w3, w4)
if v1 != w1 {
t.Error(v1, w1)
}
if v2 != 32 {
t.Error(v2, w2)
}
if v3 != 30 {
t.Error(v3, w3)
}
if v4 != w4 {
t.Error(v4, w4)
}
compare = note.FieldComparison{ReflectFieldName: "OverrideParams", ReflectMapKey: "net.ipv4.ip_local_reserved_ports", ActualValueJS: "1089-1090,1095,1099,1200-1599,2000-2002,3200-3399,3500,3600-3699,3900-4001", ExpectedValueJS: "1089-1090,1095,1099,1200-1599,2000-2002,3200-3399,3500,3600-3699,3900-4001"}
v1, v2, v3, v4 = setWidthOfColums(compare, w1, w2, w3, w4)
if v1 != 30 {
t.Error(v1, w1)
}
if v2 != w2 || v3 != w3 || v4 != w4 {
t.Error(v2, w2, v3, w3, v4, w4)
}
}

Expand Down

0 comments on commit 227cd55

Please sign in to comment.