-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathnew_context_test.go
58 lines (47 loc) · 1.24 KB
/
new_context_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
package ovirtclient_test
import (
"context"
"testing"
ovirtclient "github.com/ovirt/go-ovirt-client/v3"
)
type ctxKey string
func TestContext(t *testing.T) {
helper := getHelper(t)
cli1 := helper.GetClient()
ctx := context.WithValue(context.Background(), ctxKey("foo"), "bar")
cli2 := cli1.WithContext(ctx)
if err := cli1.Reconnect(); err != nil {
t.Fatalf("failed to reconnect (%v)", err)
}
if cli1.GetContext() != nil {
t.Fatalf("Context of client 1 is not nil.")
}
if cli2.GetContext() == nil {
t.Fatalf("Context of client 2 is nil.")
}
if cli2.GetContext().Value(ctxKey("foo")) != "bar" {
t.Fatalf("Incorrect context value on client 2.")
}
vm, err := cli1.CreateVM(
helper.GetClusterID(),
helper.GetBlankTemplateID(),
helper.GenerateTestResourceName(t),
nil,
)
if err != nil {
t.Fatalf("Failed to create test VM (%v)", err)
}
t.Cleanup(
func() {
if vm != nil {
t.Logf("Cleaning up test VM %s...", vm.ID())
if err := vm.Remove(); err != nil && !ovirtclient.HasErrorCode(err, ovirtclient.ENotFound) {
t.Fatalf("Failed to remove test VM %s (%v)", vm.ID(), err)
}
}
},
)
if _, err := cli2.GetVM(vm.ID()); err != nil {
t.Fatalf("Failed to fetch VM from secondary connection (%v)", err)
}
}