Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/test/tests/workspace/disk_test.go
2498 views
1
// Copyright (c) 2023 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 workspace
6
7
import (
8
"context"
9
"fmt"
10
"strings"
11
12
"testing"
13
"time"
14
15
"sigs.k8s.io/e2e-framework/pkg/envconf"
16
"sigs.k8s.io/e2e-framework/pkg/features"
17
18
"github.com/gitpod-io/gitpod/test/pkg/integration"
19
"github.com/gitpod-io/gitpod/test/pkg/report"
20
)
21
22
type DiskTest struct {
23
Name string
24
ContextURL string
25
SpaceToAllocate string
26
TestFilePath string
27
ExpectError bool
28
}
29
30
func TestDiskActions(t *testing.T) {
31
tests := []DiskTest{
32
{
33
Name: "xfs-quota-is_exceeded",
34
ContextURL: "github.com/gitpod-io/empty",
35
SpaceToAllocate: "55G",
36
TestFilePath: "/workspace/is-exceeded",
37
ExpectError: true,
38
},
39
{
40
Name: "xfs-quota-is_OK",
41
ContextURL: "github.com/gitpod-io/empty",
42
SpaceToAllocate: "4G",
43
TestFilePath: "/workspace/is-OK",
44
ExpectError: false,
45
},
46
}
47
runDiskTests(t, tests)
48
}
49
50
func runDiskTests(t *testing.T, tests []DiskTest) {
51
f := features.New("ResourceLimiting").
52
WithLabel("component", "workspace").
53
Assess("it can enforce disk limits", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
54
55
ctx, cancel := context.WithTimeout(testCtx, time.Duration(5*len(tests))*time.Minute)
56
defer cancel()
57
58
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
59
defer api.Done(t)
60
61
for _, test := range tests {
62
test := test
63
t.Run(test.Name, func(t *testing.T) {
64
report.SetupReport(t, report.FeatureResourceLimit, fmt.Sprintf("Test to open %v", test.ContextURL))
65
66
t.Parallel()
67
68
nfo, stopWs, err := integration.LaunchWorkspaceFromContextURL(t, ctx, test.ContextURL, username, api)
69
if err != nil {
70
t.Fatal(err)
71
}
72
73
t.Cleanup(func() {
74
sctx, scancel := context.WithTimeout(context.Background(), 10*time.Minute)
75
scancel()
76
77
sapi := integration.NewComponentAPI(sctx, cfg.Namespace(), kubeconfig, cfg.Client())
78
sapi.Done(t)
79
_, err := stopWs(false, sapi)
80
if err != nil {
81
t.Fatal(err)
82
}
83
})
84
rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(),
85
kubeconfig, cfg.Client(),
86
integration.WithInstanceID(nfo.LatestInstance.ID),
87
)
88
if err != nil {
89
t.Fatal(err)
90
}
91
defer rsa.Close()
92
integration.DeferCloser(t, closer)
93
diskClient := integration.Disk(rsa)
94
95
err = diskClient.Fallocate(test.TestFilePath, test.SpaceToAllocate)
96
97
if test.ExpectError {
98
if err != nil && strings.Contains(err.Error(), integration.NoSpaceErrorMsg) {
99
// NOM
100
} else {
101
t.Fatalf("expected an error object containing %s, got '%v'!", integration.NoSpaceErrorMsg, err)
102
}
103
} else {
104
if err != nil {
105
t.Fatal(err)
106
}
107
}
108
t.Log("test finished successfully")
109
})
110
}
111
return testCtx
112
}).
113
Feature()
114
115
testEnv.Test(t, f)
116
}
117
118