@@ -15,22 +15,29 @@ import (
15
15
16
16
func TestUsageReconciler_Reconcile (t * testing.T ) {
17
17
conn := db .ConnectForTests (t )
18
- workspaceID := "gitpodio-gitpod-gyjr82jkfnd"
19
18
instanceStatus := []byte (`{"phase": "stopped", "conditions": {"deployed": false, "pullingImages": false, "serviceExists": false}}` )
20
19
startOfMay := time .Date (2022 , 05 , 1 , 0 , 00 , 00 , 00 , time .UTC )
21
20
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
+ }
22
29
instances := []db.WorkspaceInstance {
23
30
{
24
31
ID : uuid .New (),
25
- WorkspaceID : workspaceID ,
32
+ WorkspaceID : workspace . ID ,
26
33
StartedTime : db .NewVarcharTime (time .Date (2022 , 05 , 1 , 00 , 00 , 00 , 00 , time .UTC )),
27
34
StoppedTime : db .NewVarcharTime (time .Date (2022 , 06 , 1 , 1 , 0 , 0 , 0 , time .UTC )),
28
35
Status : instanceStatus ,
29
36
},
30
37
// No creation time, invalid record
31
38
{
32
39
ID : uuid .New (),
33
- WorkspaceID : workspaceID ,
40
+ WorkspaceID : workspace . ID ,
34
41
StoppedTime : db .NewVarcharTime (time .Date (2022 , 06 , 1 , 1 , 0 , 0 , 0 , time .UTC )),
35
42
Status : instanceStatus ,
36
43
},
@@ -39,6 +46,9 @@ func TestUsageReconciler_Reconcile(t *testing.T) {
39
46
tx := conn .Create (instances )
40
47
require .NoError (t , tx .Error )
41
48
49
+ tx = conn .Create (& workspace )
50
+ require .NoError (t , tx .Error )
51
+
42
52
reconciler := NewUsageReconciler (conn )
43
53
44
54
status , err := reconciler .ReconcileTimeRange (context .Background (), startOfMay , startOfJune )
@@ -48,16 +58,6 @@ func TestUsageReconciler_Reconcile(t *testing.T) {
48
58
EndTime : startOfJune ,
49
59
WorkspaceInstances : 1 ,
50
60
InvalidWorkspaceInstances : 1 ,
61
+ Workspaces : 1 ,
51
62
}, status )
52
63
}
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
- //}
0 commit comments