Skip to content

Commit

Permalink
feat: add more tests to collector utility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
smartinov committed Dec 5, 2018
1 parent 186a2c7 commit 712404d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,49 @@ func Test_getConstLabels(t *testing.T) {
})
}
}

func Test_convertCategoryToScore(t *testing.T) {
type args struct {
category string
}
tests := []struct {
name string
args args
want float64
}{
{"average", args{"AVERAGE"}, 0.5},
{"fast", args{"FAST"}, 1},
{"none", args{"NONE"}, -1},
{"jibberish", args{""}, -1},
{"slow", args{"SLOW"}, 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := convertCategoryToScore(tt.args.category); got != tt.want {
t.Errorf("convertCategoryToScore() = %v, want %v", got, tt.want)
}
})
}
}

func Test_fqname(t *testing.T) {
type args struct {
values []string
}
tests := []struct {
name string
args args
want string
}{
{"empty", args{[]string{}}, "pagespeed_"},
{"single", args{[]string{"one"}}, "pagespeed_one"},
{"multi", args{[]string{"one", "two", "three"}}, "pagespeed_one_two_three"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := fqname(tt.args.values...); got != tt.want {
t.Errorf("fqname() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 712404d

Please sign in to comment.