-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
55 lines (46 loc) · 1.17 KB
/
main_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
package main
import (
"bytes"
"fmt"
"testing"
"github.com/brightpuddle/goaci/backup"
"github.com/stretchr/testify/assert"
)
func TestBackupQuery(t *testing.T) {
// Class query
res, _ := backupQuery(Args{
Target: "./testdata/config.tar.gz",
Class: "fvTenant",
})
if !assert.Equal(t, 2, len(res.Array())) {
fmt.Println(res.Get("@pretty"))
}
// DN query
res, _ = backupQuery(Args{
Target: "./testdata/config.tar.gz",
Dn: "uni/tn-a",
})
if !assert.Equal(t, "a", res.Get("fvTenant.attributes.name").Str) {
fmt.Println(res.Get("@pretty"))
}
// No class or DN
_, err := backupQuery(Args{Target: "./testdata/config.tar.gz"})
assert.Error(t, err)
// File doesn't exist
_, err = backupQuery(Args{Target: "does.not.exist"})
assert.Error(t, err)
}
func TestPrintResult(t *testing.T) {
// Single object
client, _ := backup.NewClient("./testdata/config.tar.gz")
res, _ := client.GetDn("uni/tn-a")
b := bytes.Buffer{}
printResult(res, &b)
assert.Contains(t, b.String(), "uni/tn-a")
// Array
res, _ = client.GetClass("fvTenant")
b = bytes.Buffer{}
printResult(res, &b)
assert.Contains(t, b.String(), "uni/tn-a")
assert.Contains(t, b.String(), "uni/tn-b")
}