Skip to content

Commit acdb029

Browse files
committed
tests
1 parent 885059b commit acdb029

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

components/usage/pkg/controller/reconciler_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,29 @@ import (
1515

1616
func TestUsageReconciler_Reconcile(t *testing.T) {
1717
conn := db.ConnectForTests(t)
18-
workspaceID := "gitpodio-gitpod-gyjr82jkfnd"
1918
instanceStatus := []byte(`{"phase": "stopped", "conditions": {"deployed": false, "pullingImages": false, "serviceExists": false}}`)
2019
startOfMay := time.Date(2022, 05, 1, 0, 00, 00, 00, time.UTC)
2120
startOfJune := time.Date(2022, 06, 1, 0, 00, 00, 00, time.UTC)
21+
workspace := db.Workspace{
22+
ID: "gitpodio-gitpod-gyjr82jkfnd",
23+
OwnerID: uuid.New(),
24+
Type: "prebuild",
25+
ContextURL: "https://github.com/gitpod-io/gitpod",
26+
Context: []byte(`{"title":"[usage] List workspaces for each workspace instance in usage period","repository":{"cloneUrl":"https://github.com/gitpod-io/gitpod.git","host":"github.com","name":"gitpod","owner":"gitpod-io","private":false},"ref":"mp/usage-list-workspaces","refType":"branch","revision":"586f22ecaeeb3b4796fd92f9ae1ca3512ca1e330","nr":10495,"base":{"repository":{"cloneUrl":"https://github.com/gitpod-io/gitpod.git","host":"github.com","name":"gitpod","owner":"gitpod-io","private":false},"ref":"mp/usage-validate-instances","refType":"branch"},"normalizedContextURL":"https://github.com/gitpod-io/gitpod/pull/10495","checkoutLocation":"gitpod"}`),
27+
Config: []byte(`{"image":"eu.gcr.io/gitpod-core-dev/dev/dev-environment:me-me-image.1","workspaceLocation":"gitpod/gitpod-ws.code-workspace","checkoutLocation":"gitpod","ports":[{"port":1337,"onOpen":"open-preview"},{"port":3000,"onOpen":"ignore"},{"port":3001,"onOpen":"ignore"},{"port":3306,"onOpen":"ignore"},{"port":4000,"onOpen":"ignore"},{"port":5900,"onOpen":"ignore"},{"port":6080,"onOpen":"ignore"},{"port":7777,"onOpen":"ignore"},{"port":9229,"onOpen":"ignore"},{"port":9999,"onOpen":"ignore"},{"port":13001,"onOpen":"ignore"},{"port":13444}],"tasks":[{"name":"Install Preview Environment kube-context","command":"(cd dev/preview/previewctl && go install .)\npreviewctl install-context\nexit\n"},{"name":"Add Harvester kubeconfig","command":"./dev/preview/util/download-and-merge-harvester-kubeconfig.sh\nexit 0\n"},{"name":"Java","command":"if [ -z \"$RUN_GRADLE_TASK\" ]; then\n read -r -p \"Press enter to continue Java gradle task\"\nfi\nleeway exec --package components/supervisor-api/java:lib --package components/gitpod-protocol/java:lib -- ./gradlew --build-cache build\nleeway exec --package components/ide/jetbrains/backend-plugin:plugin --package components/ide/jetbrains/gateway-plugin:publish --parallel -- ./gradlew --build-cache buildPlugin\n"},{"name":"TypeScript","before":"scripts/branch-namespace.sh","init":"yarn --network-timeout 100000 && yarn build"},{"name":"Go","before":"pre-commit install --install-hooks","init":"leeway exec --filter-type go -v -- go mod verify","openMode":"split-right"}],"vscode":{"extensions":["bradlc.vscode-tailwindcss","EditorConfig.EditorConfig","golang.go","hashicorp.terraform","ms-azuretools.vscode-docker","ms-kubernetes-tools.vscode-kubernetes-tools","stkb.rewrap","zxh404.vscode-proto3","matthewpi.caddyfile-support","heptio.jsonnet","timonwong.shellcheck","vscjava.vscode-java-pack","fwcd.kotlin","dbaeumer.vscode-eslint","esbenp.prettier-vscode"]},"jetbrains":{"goland":{"prebuilds":{"version":"stable"}}},"_origin":"repo","_featureFlags":[]}`),
28+
}
2229
instances := []db.WorkspaceInstance{
2330
{
2431
ID: uuid.New(),
25-
WorkspaceID: workspaceID,
32+
WorkspaceID: workspace.ID,
2633
StartedTime: db.NewVarcharTime(time.Date(2022, 05, 1, 00, 00, 00, 00, time.UTC)),
2734
StoppedTime: db.NewVarcharTime(time.Date(2022, 06, 1, 1, 0, 0, 0, time.UTC)),
2835
Status: instanceStatus,
2936
},
3037
// No creation time, invalid record
3138
{
3239
ID: uuid.New(),
33-
WorkspaceID: workspaceID,
40+
WorkspaceID: workspace.ID,
3441
StoppedTime: db.NewVarcharTime(time.Date(2022, 06, 1, 1, 0, 0, 0, time.UTC)),
3542
Status: instanceStatus,
3643
},
@@ -39,6 +46,9 @@ func TestUsageReconciler_Reconcile(t *testing.T) {
3946
tx := conn.Create(instances)
4047
require.NoError(t, tx.Error)
4148

49+
tx = conn.Create(&workspace)
50+
require.NoError(t, tx.Error)
51+
4252
reconciler := NewUsageReconciler(conn)
4353

4454
status, err := reconciler.ReconcileTimeRange(context.Background(), startOfMay, startOfJune)
@@ -48,16 +58,6 @@ func TestUsageReconciler_Reconcile(t *testing.T) {
4858
EndTime: startOfJune,
4959
WorkspaceInstances: 1,
5060
InvalidWorkspaceInstances: 1,
61+
Workspaces: 1,
5162
}, status)
5263
}
53-
54-
//
55-
//func createWorkspaceInstance(t *testing.T, conn *gorm.DB) {
56-
// instance := db.WorkspaceInstance{
57-
// ID: uuid.New(),
58-
// WorkspaceID: workspaceID,
59-
// CreationTime: db.NewVarcharTime(time.Date(2022, 06, 1, 00, 00, 00, 00, time.UTC)),
60-
// StoppedTime: db.NewVarcharTime(time.Date(2022, 06, 1, 1, 0, 0, 0, time.UTC)),
61-
// Status: status,
62-
// }
63-
//}

components/usage/pkg/db/workspace.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"database/sql"
1010
"fmt"
11+
"github.com/google/uuid"
1112
"gorm.io/datatypes"
1213
"gorm.io/gorm"
1314
"time"
@@ -16,7 +17,7 @@ import (
1617
// Workspace represents the underlying DB object
1718
type Workspace struct {
1819
ID string `gorm:"primary_key;column:id;type:char;size:36;" json:"id"`
19-
OwnerID string `gorm:"column:ownerId;type:char;size:36;" json:"ownerId"`
20+
OwnerID uuid.UUID `gorm:"column:ownerId;type:char;size:36;" json:"ownerId"`
2021
ProjectID sql.NullString `gorm:"column:projectId;type:char;size:36;" json:"projectId"`
2122
Description string `gorm:"column:description;type:varchar;size:255;" json:"description"`
2223
Type string `gorm:"column:type;type:char;size:16;default:regular;" json:"type"`

0 commit comments

Comments
 (0)