-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkspaces_integration_test.go
More file actions
79 lines (68 loc) · 1.86 KB
/
Copy pathworkspaces_integration_test.go
File metadata and controls
79 lines (68 loc) · 1.86 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
//go:build integration
package toggl_test
import (
"testing"
toggl "github.com/shoekstra/go-toggl"
)
func TestIntegration_Workspaces_ListWorkspaces(t *testing.T) {
client := integrationClient(t)
ctx := integrationCtx(t)
workspaces, _, err := client.Workspaces.ListWorkspaces(ctx)
if err != nil {
t.Fatalf("ListWorkspaces: %v", err)
}
if len(workspaces) == 0 {
t.Fatal("expected at least one workspace")
}
for _, ws := range workspaces {
if ws.ID == 0 {
t.Errorf("workspace has ID=0")
}
if ws.Name == "" {
t.Errorf("workspace %d has empty name", ws.ID)
}
}
}
func TestIntegration_Workspaces_GetWorkspace(t *testing.T) {
client := integrationClient(t)
wsID := integrationWorkspaceID(t)
ctx := integrationCtx(t)
ws, _, err := client.Workspaces.GetWorkspace(ctx, wsID)
if err != nil {
t.Fatalf("GetWorkspace: %v", err)
}
if ws.ID != wsID {
t.Errorf("ID = %d, want %d", ws.ID, wsID)
}
if ws.Name == "" {
t.Error("Name is empty")
}
}
func TestIntegration_Workspaces_UpdateWorkspace(t *testing.T) {
client := integrationClient(t)
wsID := integrationWorkspaceID(t)
ctx := integrationCtx(t)
// Read the current name so we can restore it.
ws, _, err := client.Workspaces.GetWorkspace(ctx, wsID)
if err != nil {
t.Fatalf("GetWorkspace: %v", err)
}
originalName := ws.Name
t.Cleanup(func() {
if _, _, err := client.Workspaces.UpdateWorkspace(ctx, wsID, &toggl.UpdateWorkspaceOptions{
Name: toggl.String(originalName),
}); err != nil {
t.Errorf("cleanup: failed to restore workspace name: %v", err)
}
})
expectedName := uniqueName("ws")
updated, _, err := client.Workspaces.UpdateWorkspace(ctx, wsID, &toggl.UpdateWorkspaceOptions{
Name: toggl.String(expectedName),
})
if err != nil {
t.Fatalf("UpdateWorkspace: %v", err)
}
if updated.Name != expectedName {
t.Errorf("Name = %q, want %q", updated.Name, expectedName)
}
}