Path: blob/main/components/gitpod-db/go/workspace_test.go
2497 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package db_test56import (7"context"8"testing"910db "github.com/gitpod-io/gitpod/components/gitpod-db/go"1112"github.com/gitpod-io/gitpod/components/gitpod-db/go/dbtest"13"github.com/stretchr/testify/require"14)1516func stringToVarchar(t *testing.T, s string) db.VarcharTime {17t.Helper()1819converted, err := db.NewVarCharTimeFromStr(s)20require.NoError(t, err)21return converted22}2324func TestListWorkspacesByID(t *testing.T) {25workspaces := []db.Workspace{26dbtest.NewWorkspace(t, db.Workspace{}),27dbtest.NewWorkspace(t, db.Workspace{}),28}2930for _, scenario := range []struct {31Name string32QueryIDs []string33Expected int34}{35{36Name: "no query ids returns empty results",37QueryIDs: nil,38Expected: 0,39},40{41Name: "not found id returns emtpy results",42QueryIDs: []string{"gitpodio-gitpod-xxxxxxxxxxx"},43Expected: 0,44},45{46Name: "one matching returns results",47QueryIDs: []string{workspaces[0].ID},48Expected: 1,49},50{51Name: "one matching and one non existent returns one found result",52QueryIDs: []string{workspaces[0].ID, "gitpodio-gitpod-xxxxxxxxxxx"},53Expected: 1,54},55{56Name: "multiple matching ids return results for each",57QueryIDs: []string{workspaces[0].ID, workspaces[1].ID},58Expected: 2,59},60} {61t.Run(scenario.Name, func(t *testing.T) {62conn := dbtest.ConnectForTests(t)63dbtest.CreateWorkspaces(t, conn, workspaces...)6465results, err := db.ListWorkspacesByID(context.Background(), conn, scenario.QueryIDs)66require.NoError(t, err)67require.Len(t, results, scenario.Expected)68})6970}71}727374