-
Notifications
You must be signed in to change notification settings - Fork 9
/
uconfig_test.go
84 lines (58 loc) · 1.54 KB
/
uconfig_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
72
73
74
75
76
77
78
79
80
81
82
83
84
package uconfig_test
import (
"errors"
"testing"
"github.com/omeid/uconfig"
"github.com/omeid/uconfig/flat"
"github.com/omeid/uconfig/internal/f"
"github.com/omeid/uconfig/plugins"
)
type BadPlugin interface {
plugins.Plugin
NotWalkerOrVisitor()
}
func TestBadPlug(t *testing.T) {
var badPlugin BadPlugin
config := f.Config{}
_, err := uconfig.New(&config, badPlugin)
if err == nil {
t.Error("expected error for bad plugin, got nil")
}
if err.Error() != "Unsupported plugins. Expecting a Walker or Visitor" {
t.Errorf("Expected unsupported plugin error, got: %v", err)
}
}
type FailingPluginWalker struct {
plugins.Plugin
}
func (fp FailingPluginWalker) Walk(interface{}) error {
return errors.New("failed to walk")
}
func TestFailingPlugWalker(t *testing.T) {
var failingPluginWalker FailingPluginWalker
config := f.Config{}
_, err := uconfig.New(&config, failingPluginWalker)
if err == nil {
t.Error("expected error for bad plugin, got nil")
}
if err.Error() != "failed to walk" {
t.Errorf("Expected failed to walk, got: %v", err)
}
}
type FailingPluginVisitor struct {
plugins.Plugin
}
func (fp FailingPluginVisitor) Visit(flat.Fields) error {
return errors.New("failed to visit")
}
func TestFailingPlugVisitor(t *testing.T) {
var failingPluginVisitor FailingPluginVisitor
config := f.Config{}
_, err := uconfig.New(&config, failingPluginVisitor)
if err == nil {
t.Error("expected error for bad plugin, got nil")
}
if err.Error() != "failed to visit" {
t.Errorf("Expected failed to visit, got: %v", err)
}
}