-
Notifications
You must be signed in to change notification settings - Fork 4
/
provider_test.go
67 lines (60 loc) · 1.45 KB
/
provider_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
// Copyright 2018 GRAIL, Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package infra
import (
"reflect"
"testing"
)
func TestProvider(t *testing.T) {
type x int
typ := reflect.TypeOf(x(0))
p := provider{"", typ}
if err := p.Typecheck(); err != nil {
t.Fatal(err)
}
inst := p.New(Config{}, "")
if got, want := inst.val.Type(), typ; got != want {
t.Errorf("got %v, want %v", got, want)
}
if got, want := inst.val.Int(), int64(0); got != want {
t.Errorf("got %v, want %v", got, want)
}
typ = reflect.TypeOf(new(x))
p = provider{"", typ}
if err := p.Typecheck(); err != nil {
t.Fatal(err)
}
inst = p.New(Config{}, "")
if inst.val.Pointer() == uintptr(0) {
t.Error("instantiated nil pointer")
}
if got, want := inst.val.Elem().Int(), int64(0); got != want {
t.Errorf("got %v, want %v", got, want)
}
}
func TestProviderValidName(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Errorf("Unexpected panic: %v", r)
}
}()
Register("test", new(Schema))
Register("ec2cluster", new(Schema))
}
func TestProviderInvalidNameSpecialCharacters(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("Expected panic")
}
}()
Register("232*772", new(Schema))
}
func TestProviderInvalidNameCaps(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("Expected panic")
}
}()
Register("CAPS", new(Schema))
}