-
Notifications
You must be signed in to change notification settings - Fork 6
/
pacemaker_test.go
93 lines (80 loc) · 1.83 KB
/
pacemaker_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
85
86
87
88
89
90
91
92
93
// Copyright (C) 2017 Kristoffer Gronlund <[email protected]>
// See LICENSE for license.
package pacemaker_test
import (
"fmt"
"github.com/ClusterLabs/go-pacemaker"
"gopkg.in/xmlpath.v2"
"log"
"strings"
"testing"
)
func TestXmlpath(t *testing.T) {
cib, err := pacemaker.OpenCib(pacemaker.FromFile("testdata/simple.xml"))
if err != nil {
t.Fatal(err)
}
defer cib.Close()
doc, err := cib.Query()
if err != nil {
t.Fatal(err)
}
defer doc.Close()
path := xmlpath.MustCompile("/cib/configuration/nodes/node[@id='xxx']/@type")
root, err := xmlpath.Parse(strings.NewReader(doc.ToString()))
if err != nil {
t.Fatal(err)
}
value, ok := path.String(root)
if !ok {
t.Error("xpath query failed")
}
if value != "normal" {
t.Error(fmt.Sprintf("Expected 'normal', got '%v'", value))
}
}
func TestVersion(t *testing.T) {
cib, err := pacemaker.OpenCib(pacemaker.FromFile("testdata/simple.xml"))
if err != nil {
t.Fatal(err)
}
defer cib.Close()
ver, err := cib.Version()
if err != nil {
t.Error(err)
}
if ver.AdminEpoch != 1 {
t.Error("Expected admin_epoch == 1, got ", ver.AdminEpoch)
}
if ver.Epoch != 0 {
t.Error("Expected epoch == 0, got ", ver.Epoch)
}
}
func ExampleQuery() {
cib, err := pacemaker.OpenCib(pacemaker.FromFile("testdata/simple.xml"))
if err != nil {
log.Fatal(err)
}
defer cib.Close()
doc, err := cib.Query()
if err != nil {
log.Fatal(err)
}
defer doc.Close()
fmt.Printf("%s\n", doc.ToString()[0:4])
// Output: <cib
}
func ExampleQueryXPath() {
cib, err := pacemaker.OpenCib(pacemaker.FromFile("testdata/simple.xml"))
if err != nil {
log.Fatal(err)
}
defer cib.Close()
doc, err := cib.QueryXPath("//nodes/node[@id=\"xxx\"]")
if err != nil {
log.Fatal(err)
}
defer doc.Close()
fmt.Printf("%s\n", doc.ToString())
// Output: <node id="xxx" uname="c001n01" type="normal"/>
}