-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathworkspaces_internal_test.go
More file actions
88 lines (82 loc) · 1.99 KB
/
Copy pathworkspaces_internal_test.go
File metadata and controls
88 lines (82 loc) · 1.99 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
package codersdk
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestWorkspaceFilterAsRequestOption(t *testing.T) {
t.Parallel()
// applyFilter applies the filter's request option to a blank request and
// returns the resulting "q" query parameter.
applyFilter := func(f WorkspaceFilter) string {
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://example.com", nil)
require.NoError(t, err)
f.asRequestOption()(req)
return req.URL.Query().Get("q")
}
tests := []struct {
name string
filter WorkspaceFilter
contains []string
empty bool
}{
{
name: "Empty",
filter: WorkspaceFilter{},
empty: true,
},
{
name: "Owner",
filter: WorkspaceFilter{Owner: "alice"},
contains: []string{`owner:"alice"`},
},
{
name: "Name",
filter: WorkspaceFilter{Name: "my-workspace"},
contains: []string{`name:"my-workspace"`},
},
{
name: "Template",
filter: WorkspaceFilter{Template: "base"},
contains: []string{`template:"base"`},
},
{
name: "Status",
filter: WorkspaceFilter{Status: "running"},
contains: []string{`status:"running"`},
},
{
name: "Organization",
filter: WorkspaceFilter{Organization: "acme"},
contains: []string{`organization:"acme"`},
},
{
name: "OrganizationByUUID",
filter: WorkspaceFilter{Organization: "550e8400-e29b-41d4-a716-446655440000"},
contains: []string{`organization:"550e8400-e29b-41d4-a716-446655440000"`},
},
{
name: "MultipleFields",
filter: WorkspaceFilter{Owner: "alice", Organization: "acme", Status: "running"},
contains: []string{
`owner:"alice"`,
`organization:"acme"`,
`status:"running"`,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
q := applyFilter(tt.filter)
if tt.empty {
require.Empty(t, q)
return
}
for _, s := range tt.contains {
require.Contains(t, q, s)
}
})
}
}