-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathhelp_test.go
71 lines (59 loc) · 1.55 KB
/
help_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package baker_test
import (
"io"
"reflect"
"testing"
"github.com/AdRoll/baker"
"github.com/AdRoll/baker/filter"
"github.com/AdRoll/baker/input"
"github.com/AdRoll/baker/output"
"github.com/AdRoll/baker/upload"
)
func assertValidConfigHelp(t *testing.T, name string, cfg interface{}) {
t.Helper()
tCfg := reflect.TypeOf(cfg).Elem()
if tCfg.Kind() != reflect.Struct {
t.Errorf("Got %v, struct expected", tCfg.Kind())
}
for i := 0; i < tCfg.NumField(); i++ {
if tCfg.Field(i).PkgPath != "" {
// This is an unexported field
continue
}
if tCfg.Field(i).Tag.Get("help") == "" {
t.Errorf("%v is missing the config help for %v", name, tCfg.Field(i).Name)
}
}
}
func TestAllInputsHaveConfigHelp(t *testing.T) {
for _, input := range input.All {
assertValidConfigHelp(t, input.Name, input.Config)
}
}
func TestAllFiltersHaveConfigHelp(t *testing.T) {
for _, filter := range filter.All {
assertValidConfigHelp(t, filter.Name, filter.Config)
}
}
func TestAllOutputsHaveConfigHelp(t *testing.T) {
for _, output := range output.All {
assertValidConfigHelp(t, output.Name, output.Config)
}
}
func TestAllUploadsHaveConfigHelp(t *testing.T) {
for _, upload := range upload.All {
assertValidConfigHelp(t, upload.Name, upload.Config)
}
}
func TestPrintHelp(t *testing.T) {
comp := baker.Components{
Inputs: input.All,
Filters: filter.All,
Outputs: output.All,
Uploads: upload.All,
}
err := baker.PrintHelp(io.Discard, "*", comp, baker.HelpFormatMarkdown)
if err != nil {
t.Fatalf("PrintHelp return err: %v, want nil", err)
}
}