Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/go/workspace_test.go
2497 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package db_test
6
7
import (
8
"context"
9
"testing"
10
11
db "github.com/gitpod-io/gitpod/components/gitpod-db/go"
12
13
"github.com/gitpod-io/gitpod/components/gitpod-db/go/dbtest"
14
"github.com/stretchr/testify/require"
15
)
16
17
func stringToVarchar(t *testing.T, s string) db.VarcharTime {
18
t.Helper()
19
20
converted, err := db.NewVarCharTimeFromStr(s)
21
require.NoError(t, err)
22
return converted
23
}
24
25
func TestListWorkspacesByID(t *testing.T) {
26
workspaces := []db.Workspace{
27
dbtest.NewWorkspace(t, db.Workspace{}),
28
dbtest.NewWorkspace(t, db.Workspace{}),
29
}
30
31
for _, scenario := range []struct {
32
Name string
33
QueryIDs []string
34
Expected int
35
}{
36
{
37
Name: "no query ids returns empty results",
38
QueryIDs: nil,
39
Expected: 0,
40
},
41
{
42
Name: "not found id returns emtpy results",
43
QueryIDs: []string{"gitpodio-gitpod-xxxxxxxxxxx"},
44
Expected: 0,
45
},
46
{
47
Name: "one matching returns results",
48
QueryIDs: []string{workspaces[0].ID},
49
Expected: 1,
50
},
51
{
52
Name: "one matching and one non existent returns one found result",
53
QueryIDs: []string{workspaces[0].ID, "gitpodio-gitpod-xxxxxxxxxxx"},
54
Expected: 1,
55
},
56
{
57
Name: "multiple matching ids return results for each",
58
QueryIDs: []string{workspaces[0].ID, workspaces[1].ID},
59
Expected: 2,
60
},
61
} {
62
t.Run(scenario.Name, func(t *testing.T) {
63
conn := dbtest.ConnectForTests(t)
64
dbtest.CreateWorkspaces(t, conn, workspaces...)
65
66
results, err := db.ListWorkspacesByID(context.Background(), conn, scenario.QueryIDs)
67
require.NoError(t, err)
68
require.Len(t, results, scenario.Expected)
69
})
70
71
}
72
}
73
74