-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_test.go
More file actions
104 lines (83 loc) · 2.33 KB
/
db_test.go
File metadata and controls
104 lines (83 loc) · 2.33 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
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
94
95
96
97
98
99
100
101
102
103
104
package gomsf
import (
"context"
"errors"
"strings"
"testing"
)
func TestDbManager_Status(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
status, err := client.DB().Status(context.Background())
if err != nil {
t.Fatalf("Status failed: %v", err)
}
if status == nil {
t.Log("Status returned nil (database may not be connected)")
}
}
func TestDbManager_CurrentWorkspace(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
workspace, err := client.DB().CurrentWorkspace(context.Background())
if err != nil {
t.Fatalf("CurrentWorkspace failed: %v", err)
}
t.Logf("Current workspace: %s", workspace)
}
func TestWorkspaceManager_List(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
workspaces, err := client.DB().Workspaces().List(context.Background())
if err != nil {
t.Fatalf("List failed: %v", err)
}
if workspaces == nil {
t.Log("Workspaces is nil (database may not be connected)")
}
}
func TestWorkspaceManager_AddRemove(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
wsName := "test_workspace_go_msf"
err := client.DB().Workspaces().Add(context.Background(), wsName)
if err != nil {
if !isDBUnavailableError(err) {
t.Fatalf("Add workspace failed: %v", err)
}
return
}
err = client.DB().Workspaces().Remove(context.Background(), wsName)
if err != nil {
t.Errorf("Remove workspace failed: %v", err)
}
}
func TestWorkspaceManager_Current(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
ws, err := client.DB().Workspaces().Current(context.Background())
if err != nil {
t.Fatalf("Current failed: %v", err)
}
if ws == nil {
t.Log("Current workspace is nil (database may not be connected)")
}
}
func TestDbManager_SetWorkspace(t *testing.T) {
client := getTestClient(t)
defer client.Logout(context.Background())
err := client.DB().SetWorkspace(context.Background(), "default")
if err != nil {
if !isDBUnavailableError(err) {
t.Fatalf("SetWorkspace failed: %v", err)
}
}
}
func isDBUnavailableError(err error) bool {
var rpcErr *RPCError
if !errors.As(err, &rpcErr) {
return false
}
return strings.Contains(rpcErr.Message, "Database Not Loaded") ||
strings.Contains(rpcErr.Message, "No connection pool")
}