Skip to content

Commit 2a32c06

Browse files
committed
Add missing check class data to ClassInfo struct
This is necessary so that the API can map accounting classes to check types and ther corresponding class. Signed-off-by: Marcelo E. Magallon <[email protected]>
1 parent 24d4136 commit 2a32c06

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

pkg/accounting/accounting.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ func GetCheckAccountingClass(check synthetic_monitoring.Check) (string, error) {
7474

7575
// ClassInfo contains information about a specific accounting class
7676
type ClassInfo struct {
77-
CheckType synthetic_monitoring.CheckType // the correspodning check type for this class
78-
Series int // how many series does this class of check produce
77+
CheckType synthetic_monitoring.CheckType // the correspodning check type for this class
78+
CheckClass synthetic_monitoring.CheckClass // the check class for this accounting class
79+
Series int // how many series does this class of check produce
7980
}
8081

8182
// GetAccountingClassInfo returns all the known accounting classes and
@@ -84,9 +85,11 @@ func GetAccountingClassInfo() map[string]ClassInfo {
8485
info := make(map[string]ClassInfo, len(activeSeriesByCheckType))
8586

8687
for class, as := range activeSeriesByCheckType {
88+
checkType := getTypeFromClass(class)
8789
info[class] = ClassInfo{
88-
CheckType: getTypeFromClass(class),
89-
Series: as,
90+
CheckType: getTypeFromClass(class),
91+
CheckClass: checkType.Class(),
92+
Series: as,
9093
}
9194
}
9295

pkg/pb/synthetic_monitoring/checks_extra.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ func (c Check) Type() CheckType {
201201
}
202202

203203
func (c Check) Class() CheckClass {
204-
switch c.Type() {
204+
return c.Type().Class()
205+
}
206+
207+
func (c CheckType) Class() CheckClass {
208+
switch c {
205209
case CheckTypeDns, CheckTypeHttp, CheckTypePing, CheckTypeTcp, CheckTypeTraceroute:
206210
return CheckClassProtocol
207211

pkg/pb/synthetic_monitoring/checks_extra_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,62 @@ func TestCheckTypeString(t *testing.T) {
426426
}
427427
}
428428

429+
func TestCheckTypeClass(t *testing.T) {
430+
testcases := map[string]struct {
431+
input CheckType
432+
expected CheckClass
433+
}{
434+
CheckTypeDns.String(): {
435+
input: CheckTypeDns,
436+
expected: CheckClassProtocol,
437+
},
438+
CheckTypeHttp.String(): {
439+
input: CheckTypeHttp,
440+
expected: CheckClassProtocol,
441+
},
442+
CheckTypePing.String(): {
443+
input: CheckTypePing,
444+
expected: CheckClassProtocol,
445+
},
446+
CheckTypeTcp.String(): {
447+
input: CheckTypeTcp,
448+
expected: CheckClassProtocol,
449+
},
450+
CheckTypeTraceroute.String(): {
451+
input: CheckTypeTraceroute,
452+
expected: CheckClassProtocol,
453+
},
454+
CheckTypeK6.String(): {
455+
input: CheckTypeK6,
456+
expected: CheckClassScripted,
457+
},
458+
CheckTypeMultiHttp.String(): {
459+
input: CheckTypeMultiHttp,
460+
expected: CheckClassScripted,
461+
},
462+
}
463+
464+
for name, testcase := range testcases {
465+
t.Run(name, func(t *testing.T) {
466+
actual := testcase.input.Class()
467+
require.Equal(t, testcase.expected, actual)
468+
})
469+
}
470+
471+
hasTest := make(map[CheckType]bool)
472+
for _, checkType := range CheckTypeValues() {
473+
hasTest[checkType] = false
474+
}
475+
476+
for _, testcase := range testcases {
477+
hasTest[testcase.input] = true
478+
}
479+
480+
for checkType, found := range hasTest {
481+
require.True(t, found, "missing test for check type %s", checkType)
482+
}
483+
}
484+
429485
func TestValidateHost(t *testing.T) {
430486
testcases := map[string]struct {
431487
input string

0 commit comments

Comments
 (0)