forked from Juniper/jtimon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
60 lines (53 loc) · 1.33 KB
/
config_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
/*
* Copyright (c) 2018, Juniper Networks, Inc.
* All rights reserved.
*/
package main
import (
"testing"
)
func TestNewJTIMONConfig(t *testing.T) {
var xerr error
files := []struct {
name string
error bool
}{
{"tests/data/noerror.json", false}, // no error
{"tests/data/error.jso", true}, // file does not exists
{"tests/data/error.json", true}, // syntax error in JSON file
}
for _, file := range files {
_, err := NewJTIMONConfig(file.name)
if err != nil && !file.error {
t.Errorf("NewJTIMONConfig failed, got: %v, want: %v", err, xerr)
}
if err == nil && file.error {
t.Errorf("NewJTIMONConfig failed, got: %v, want error", err)
}
}
}
func TestValidateConfig(t *testing.T) {
files := []struct {
name string
error bool
}{
{"tests/data/noerror.json", false}, // no error
{"tests/data/error.jso", true}, // file does not exists
{"tests/data/error.json", true}, // syntax error in JSON file
}
for _, file := range files {
config, err := NewJTIMONConfig(file.name)
if err != nil {
configString, err := ValidateConfig(config)
if err != nil {
t.Errorf("TestValidateConfig failed. Error: %v\nConfig %s\n", err, configString)
}
}
}
}
func TestExploreConfig(t *testing.T) {
_, err := ExploreConfig()
if err != nil {
t.Errorf("ExploreConfig failed, Error: %v\n", err)
}
}