Skip to content

Commit 7195b24

Browse files
committed
remove spurious type
1 parent e3386e6 commit 7195b24

File tree

5 files changed

+126
-125
lines changed

5 files changed

+126
-125
lines changed

pkg/connectivity/junit.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111
)
1212

13-
func PrintJUnitResults(filename string, summary *Summary) {
13+
func PrintJUnitResults(filename string, summary *SummaryTable) {
1414
if filename == "" {
1515
return
1616
}
@@ -27,14 +27,14 @@ func PrintJUnitResults(filename string, summary *Summary) {
2727
}
2828
}
2929

30-
func printJunit(w io.Writer, summary *Summary) error {
30+
func printJunit(w io.Writer, summary *SummaryTable) error {
3131
s := summaryToJunit(summary)
3232
enc := xml.NewEncoder(w)
3333
enc.Indent("", " ")
3434
return enc.Encode(s)
3535
}
3636

37-
func summaryToJunit(summary *Summary) junit.JUnitTestSuite {
37+
func summaryToJunit(summary *SummaryTable) junit.JUnitTestSuite {
3838
s := junit.JUnitTestSuite{
3939
Name: "cyclonus",
4040
Failures: summary.Failed,

pkg/connectivity/printer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Printer struct {
2424
}
2525

2626
func (t *Printer) PrintSummary() {
27-
summary := (&CombinedResults{Results: t.Results}).Summary(t.IgnoreLoopback)
27+
summary := NewSummaryTableFromResults(t.IgnoreLoopback, t.Results)
2828
t.printTestSummary(summary.Tests)
2929
for primary, counts := range summary.TagCounts {
3030
fmt.Println(passFailTable(primary, counts, nil, nil))
@@ -103,7 +103,7 @@ func (t *Printer) printMarkdownFeatureTable(primaryCounts map[string]map[bool]in
103103

104104
func (t *Printer) printTestSummary(rows [][]string) {
105105
tableString := &strings.Builder{}
106-
tableString.WriteString("Summary:\n")
106+
tableString.WriteString("SummaryTable:\n")
107107
table := tablewriter.NewWriter(tableString)
108108
table.SetRowLine(true)
109109

pkg/connectivity/printer_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ func RunPrinterTests() {
1515
Describe("Test junit file print", func() {
1616
testCases := []struct {
1717
desc string
18-
summary *Summary
18+
summary *SummaryTable
1919
expectFile string
2020
expectErr string
2121
}{
2222
{
2323
desc: "Empty summary",
24-
summary: &Summary{},
24+
summary: &SummaryTable{},
2525
expectFile: "testdata/empty-summary.golden.xml",
2626
}, {
2727
desc: "2 pass 2 fail",
28-
summary: &Summary{
28+
summary: &SummaryTable{
2929
Tests: [][]string{
3030
{"1: test1", "passed", ""},
3131
{"2: test2 with spaces", "failed", ""},
@@ -36,7 +36,7 @@ func RunPrinterTests() {
3636
expectFile: "testdata/2-pass-2-fail.golden.xml",
3737
}, {
3838
desc: "Uses failure count from summary",
39-
summary: &Summary{
39+
summary: &SummaryTable{
4040
Failed: 10,
4141
},
4242
expectFile: "testdata/use-summary-failure-count.golden.xml",

pkg/connectivity/result.go

-116
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package connectivity
22

33
import (
4-
"fmt"
54
"github.com/mattfenwick/cyclonus/pkg/connectivity/probe"
65
"github.com/mattfenwick/cyclonus/pkg/generator"
76
v1 "k8s.io/api/core/v1"
@@ -39,118 +38,3 @@ func (r *Result) Passed(ignoreLoopback bool) bool {
3938
}
4039
return true
4140
}
42-
43-
type CombinedResults struct {
44-
Results []*Result
45-
}
46-
47-
type Summary struct {
48-
Tests [][]string
49-
Passed int
50-
Failed int
51-
ProtocolCounts map[v1.Protocol]map[Comparison]int
52-
TagCounts map[string]map[string]map[bool]int
53-
TagPrimaryCounts map[string]map[bool]int
54-
FeatureCounts map[string]map[string]map[bool]int
55-
FeaturePrimaryCounts map[string]map[bool]int
56-
}
57-
58-
func (c *CombinedResults) Summary(ignoreLoopback bool) *Summary {
59-
summary := &Summary{
60-
Tests: nil,
61-
Passed: 0,
62-
Failed: 0,
63-
ProtocolCounts: map[v1.Protocol]map[Comparison]int{v1.ProtocolTCP: {}, v1.ProtocolSCTP: {}, v1.ProtocolUDP: {}},
64-
TagCounts: map[string]map[string]map[bool]int{},
65-
TagPrimaryCounts: map[string]map[bool]int{},
66-
FeatureCounts: map[string]map[string]map[bool]int{},
67-
FeaturePrimaryCounts: map[string]map[bool]int{},
68-
}
69-
passedTotal, failedTotal := 0, 0
70-
71-
for testNumber, result := range c.Results {
72-
passed := result.Passed(ignoreLoopback)
73-
74-
for primary, subs := range result.Features() {
75-
if _, ok := summary.FeatureCounts[primary]; !ok {
76-
summary.FeatureCounts[primary] = map[string]map[bool]int{}
77-
}
78-
incrementCounts(summary.FeatureCounts[primary], subs, passed)
79-
incrementCounts(summary.FeaturePrimaryCounts, []string{primary}, passed)
80-
}
81-
82-
groupedTags := result.TestCase.Tags.GroupTags()
83-
for primary, subs := range groupedTags {
84-
if _, ok := summary.TagCounts[primary]; !ok {
85-
summary.TagCounts[primary] = map[string]map[bool]int{}
86-
}
87-
incrementCounts(summary.TagCounts[primary], subs, passed)
88-
incrementCounts(summary.TagPrimaryCounts, []string{primary}, passed)
89-
}
90-
91-
var testResult string
92-
if passed {
93-
testResult = "passed"
94-
passedTotal++
95-
} else {
96-
testResult = "failed"
97-
failedTotal++
98-
}
99-
100-
summary.Tests = append(summary.Tests, []string{
101-
fmt.Sprintf("%d: %s", testNumber+1, result.TestCase.Description),
102-
testResult, "", "", "", "",
103-
"", "", "",
104-
})
105-
106-
for stepNumber, step := range result.Steps {
107-
for tryNumber := range step.KubeProbes {
108-
counts := step.Comparison(tryNumber).ValueCounts(ignoreLoopback)
109-
tryProtocolCounts := step.Comparison(tryNumber).ValueCountsByProtocol(ignoreLoopback)
110-
tcp := tryProtocolCounts[v1.ProtocolTCP]
111-
sctp := tryProtocolCounts[v1.ProtocolSCTP]
112-
udp := tryProtocolCounts[v1.ProtocolUDP]
113-
summary.Tests = append(summary.Tests, []string{
114-
"",
115-
"",
116-
fmt.Sprintf("Step %d, try %d", stepNumber+1, tryNumber+1),
117-
intToString(counts[DifferentComparison]),
118-
intToString(counts[SameComparison]),
119-
intToString(counts[IgnoredComparison]),
120-
protocolResult(tcp[SameComparison], tcp[DifferentComparison]),
121-
protocolResult(sctp[SameComparison], sctp[DifferentComparison]),
122-
protocolResult(udp[SameComparison], udp[DifferentComparison]),
123-
})
124-
125-
summary.ProtocolCounts[v1.ProtocolTCP][SameComparison] += tcp[SameComparison]
126-
summary.ProtocolCounts[v1.ProtocolTCP][DifferentComparison] += tcp[DifferentComparison]
127-
summary.ProtocolCounts[v1.ProtocolSCTP][SameComparison] += sctp[SameComparison]
128-
summary.ProtocolCounts[v1.ProtocolSCTP][DifferentComparison] += sctp[DifferentComparison]
129-
summary.ProtocolCounts[v1.ProtocolUDP][SameComparison] += udp[SameComparison]
130-
summary.ProtocolCounts[v1.ProtocolUDP][DifferentComparison] += udp[DifferentComparison]
131-
}
132-
}
133-
}
134-
135-
summary.Passed = passedTotal
136-
summary.Failed = failedTotal
137-
138-
return summary
139-
}
140-
141-
func incrementCounts(dict map[string]map[bool]int, keys []string, b bool) {
142-
for _, k := range keys {
143-
if _, ok := dict[k]; !ok {
144-
dict[k] = map[bool]int{}
145-
}
146-
dict[k][b]++
147-
}
148-
}
149-
150-
func protocolResult(passed int, failed int) string {
151-
total := passed + failed
152-
if total == 0 {
153-
return "-"
154-
}
155-
return fmt.Sprintf("%d / %d (%.0f%%)", passed, total, percentage(passed, total))
156-
}

pkg/connectivity/summary.go

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package connectivity
2+
3+
import (
4+
"fmt"
5+
v1 "k8s.io/api/core/v1"
6+
)
7+
8+
type SummaryTable struct {
9+
Tests [][]string
10+
Passed int
11+
Failed int
12+
ProtocolCounts map[v1.Protocol]map[Comparison]int
13+
TagCounts map[string]map[string]map[bool]int
14+
TagPrimaryCounts map[string]map[bool]int
15+
FeatureCounts map[string]map[string]map[bool]int
16+
FeaturePrimaryCounts map[string]map[bool]int
17+
}
18+
19+
func NewSummaryTableFromResults(ignoreLoopback bool, results []*Result) *SummaryTable {
20+
summary := &SummaryTable{
21+
Tests: nil,
22+
Passed: 0,
23+
Failed: 0,
24+
ProtocolCounts: map[v1.Protocol]map[Comparison]int{v1.ProtocolTCP: {}, v1.ProtocolSCTP: {}, v1.ProtocolUDP: {}},
25+
TagCounts: map[string]map[string]map[bool]int{},
26+
TagPrimaryCounts: map[string]map[bool]int{},
27+
FeatureCounts: map[string]map[string]map[bool]int{},
28+
FeaturePrimaryCounts: map[string]map[bool]int{},
29+
}
30+
passedTotal, failedTotal := 0, 0
31+
32+
for testNumber, result := range results {
33+
passed := result.Passed(ignoreLoopback)
34+
35+
for primary, subs := range result.Features() {
36+
if _, ok := summary.FeatureCounts[primary]; !ok {
37+
summary.FeatureCounts[primary] = map[string]map[bool]int{}
38+
}
39+
incrementCounts(summary.FeatureCounts[primary], subs, passed)
40+
incrementCounts(summary.FeaturePrimaryCounts, []string{primary}, passed)
41+
}
42+
43+
groupedTags := result.TestCase.Tags.GroupTags()
44+
for primary, subs := range groupedTags {
45+
if _, ok := summary.TagCounts[primary]; !ok {
46+
summary.TagCounts[primary] = map[string]map[bool]int{}
47+
}
48+
incrementCounts(summary.TagCounts[primary], subs, passed)
49+
incrementCounts(summary.TagPrimaryCounts, []string{primary}, passed)
50+
}
51+
52+
var testResult string
53+
if passed {
54+
testResult = "passed"
55+
passedTotal++
56+
} else {
57+
testResult = "failed"
58+
failedTotal++
59+
}
60+
61+
summary.Tests = append(summary.Tests, []string{
62+
fmt.Sprintf("%d: %s", testNumber+1, result.TestCase.Description),
63+
testResult, "", "", "", "",
64+
"", "", "",
65+
})
66+
67+
for stepNumber, step := range result.Steps {
68+
for tryNumber := range step.KubeProbes {
69+
counts := step.Comparison(tryNumber).ValueCounts(ignoreLoopback)
70+
tryProtocolCounts := step.Comparison(tryNumber).ValueCountsByProtocol(ignoreLoopback)
71+
tcp := tryProtocolCounts[v1.ProtocolTCP]
72+
sctp := tryProtocolCounts[v1.ProtocolSCTP]
73+
udp := tryProtocolCounts[v1.ProtocolUDP]
74+
summary.Tests = append(summary.Tests, []string{
75+
"",
76+
"",
77+
fmt.Sprintf("Step %d, try %d", stepNumber+1, tryNumber+1),
78+
intToString(counts[DifferentComparison]),
79+
intToString(counts[SameComparison]),
80+
intToString(counts[IgnoredComparison]),
81+
protocolResult(tcp[SameComparison], tcp[DifferentComparison]),
82+
protocolResult(sctp[SameComparison], sctp[DifferentComparison]),
83+
protocolResult(udp[SameComparison], udp[DifferentComparison]),
84+
})
85+
86+
summary.ProtocolCounts[v1.ProtocolTCP][SameComparison] += tcp[SameComparison]
87+
summary.ProtocolCounts[v1.ProtocolTCP][DifferentComparison] += tcp[DifferentComparison]
88+
summary.ProtocolCounts[v1.ProtocolSCTP][SameComparison] += sctp[SameComparison]
89+
summary.ProtocolCounts[v1.ProtocolSCTP][DifferentComparison] += sctp[DifferentComparison]
90+
summary.ProtocolCounts[v1.ProtocolUDP][SameComparison] += udp[SameComparison]
91+
summary.ProtocolCounts[v1.ProtocolUDP][DifferentComparison] += udp[DifferentComparison]
92+
}
93+
}
94+
}
95+
96+
summary.Passed = passedTotal
97+
summary.Failed = failedTotal
98+
99+
return summary
100+
}
101+
102+
func incrementCounts(dict map[string]map[bool]int, keys []string, b bool) {
103+
for _, k := range keys {
104+
if _, ok := dict[k]; !ok {
105+
dict[k] = map[bool]int{}
106+
}
107+
dict[k][b]++
108+
}
109+
}
110+
111+
func protocolResult(passed int, failed int) string {
112+
total := passed + failed
113+
if total == 0 {
114+
return "-"
115+
}
116+
return fmt.Sprintf("%d / %d (%.0f%%)", passed, total, percentage(passed, total))
117+
}

0 commit comments

Comments
 (0)