-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprovider_test.go
More file actions
51 lines (40 loc) · 1.07 KB
/
provider_test.go
File metadata and controls
51 lines (40 loc) · 1.07 KB
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
package mijnhost
import (
"encoding/json"
"os"
"strconv"
"testing"
"github.com/pbergman/provider"
"github.com/pbergman/provider/test"
)
func TestProvider_Unmarshall(t *testing.T) {
var object *Provider
var buf = `{
"api_key": "testkey",
"base_uri": "http://127.0.0.1:8080",
"debug_level": 2
}`
if err := json.Unmarshal([]byte(buf), &object); err != nil {
t.Fatal(err)
}
if object.GetApiKey() != "testkey" {
t.Fatalf("api key = %s; want %s", object.GetApiKey(), "testkey")
}
if object.GetBaseUri().String() != "http://127.0.0.1:8080" {
t.Fatalf("base uri = %s; want %s", object.GetBaseUri().String(), "http://127.0.0.1:8080")
}
if object.DebugOutputLevel() != provider.OutputVeryVerbose {
t.Fatalf("expected debug to be 2 got %d", object.DebugOutputLevel())
}
}
func TestProvider(t *testing.T) {
var object = &Provider{
ApiKey: os.Getenv("API_KEY"),
}
if _, ok := os.LookupEnv("DEBUG"); ok {
if x, ok := strconv.Atoi(os.Getenv("DEBUG")); ok == nil {
object.DebugLevel = provider.OutputLevel(x)
}
}
test.RunProviderTests(t, object, test.TestAll)
}