Skip to content

Commit bae188f

Browse files
committed
[go components] Fixed "go test ./..." in various components
Tool: gitpod/catfood.gitpod.cloud
1 parent d25d928 commit bae188f

File tree

9 files changed

+46
-10
lines changed

9 files changed

+46
-10
lines changed

WORKSPACE.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ defaultVariant:
3838
- GOARCH=amd64
3939
- DOCKER_DEFAULT_PLATFORM=linux/amd64
4040
- NODE_OPTIONS=--max_old_space_size=8192
41+
- LEEWAY_BUILD=true
4142
srcs:
4243
exclude:
4344
# Make sure we don't include node_modules/**/*.ts by accident

components/common-go/util/util.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2025 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 util
6+
7+
import "os"
8+
9+
func InLeewayBuild() bool {
10+
for _, ev := range os.Environ() {
11+
// env var set in WORKSPACE.yaml
12+
if ev == "LEEWAY_BUILD=true" {
13+
return true
14+
}
15+
}
16+
return false
17+
}

components/ide-metrics/pkg/metrics/aggregated-histograms_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/google/go-cmp/cmp"
11+
"github.com/google/go-cmp/cmp/cmpopts"
1112

1213
dto "github.com/prometheus/client_model/go"
1314
)
@@ -54,7 +55,7 @@ func TestAggregatedHistograms(t *testing.T) {
5455
{CumulativeCount: &highCount, UpperBound: &highBound},
5556
},
5657
},
57-
}}, actual)
58+
}}, actual, cmpopts.IgnoreUnexported(dto.Metric{}, dto.LabelPair{}, dto.Histogram{}, dto.Bucket{}))
5859
}
5960

6061
_ = agg.Add([]string{"foo"}, 1, 0.004, []uint64{1, 1, 1})

components/node-labeler/cmd/run_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"time"
1212

1313
"github.com/aws/smithy-go/ptr"
14-
csapi "github.com/gitpod-io/gitpod/content-service/api"
15-
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
1614
"github.com/golang/mock/gomock"
1715
"github.com/google/uuid"
1816
. "github.com/onsi/ginkgo/v2"
@@ -25,9 +23,12 @@ import (
2523
ctrl "sigs.k8s.io/controller-runtime"
2624
"sigs.k8s.io/controller-runtime/pkg/client"
2725
"sigs.k8s.io/controller-runtime/pkg/envtest"
26+
logf "sigs.k8s.io/controller-runtime/pkg/log"
2827
"sigs.k8s.io/controller-runtime/pkg/log/zap"
2928

30-
logf "sigs.k8s.io/controller-runtime/pkg/log"
29+
"github.com/gitpod-io/gitpod/common-go/util"
30+
csapi "github.com/gitpod-io/gitpod/content-service/api"
31+
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
3132
)
3233

3334
const (
@@ -101,11 +102,16 @@ var _ = Describe("NodeScaledownAnnotationController", func() {
101102
var _ = BeforeSuite(func() {
102103
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
103104

105+
crdPath := filepath.Join("..", "crd")
106+
if !util.InLeewayBuild() {
107+
crdPath = filepath.Join("..", "..", "ws-manager-mk2", "config", "crd", "bases")
108+
}
109+
104110
By("bootstrapping test environment")
105111
testEnv = &envtest.Environment{
106112
ControlPlaneStartTimeout: 1 * time.Minute,
107113
ControlPlaneStopTimeout: 1 * time.Minute,
108-
CRDDirectoryPaths: []string{filepath.Join("..", "crd")},
114+
CRDDirectoryPaths: []string{crdPath},
109115
ErrorIfCRDPathMissing: true,
110116
}
111117

components/ws-daemon/pkg/controller/suite_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
//+kubebuilder:scaffold:imports
2727

28+
"github.com/gitpod-io/gitpod/common-go/util"
2829
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
2930
logf "sigs.k8s.io/controller-runtime/pkg/log"
3031
)
@@ -50,11 +51,16 @@ func TestAPIs(t *testing.T) {
5051
var _ = BeforeSuite(func() {
5152
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
5253

54+
crdPath := filepath.Join("..", "..", "crd")
55+
if !util.InLeewayBuild() {
56+
crdPath = filepath.Join("..", "..", "..", "ws-manager-mk2", "config", "crd", "bases")
57+
}
58+
5359
By("bootstrapping test environment")
5460
testEnv = &envtest.Environment{
5561
ControlPlaneStartTimeout: 1 * time.Minute,
5662
ControlPlaneStopTimeout: 1 * time.Minute,
57-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "crd")},
63+
CRDDirectoryPaths: []string{crdPath},
5864
ErrorIfCRDPathMissing: true,
5965
}
6066

components/ws-manager-api/go/BUILD.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ packages:
1010
- "go.sum"
1111
config:
1212
packaging: library
13-
dontTest: true

components/ws-manager-api/go/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (c *Configuration) Validate() error {
254254
}
255255

256256
if _, ok := c.WorkspaceClasses[DefaultWorkspaceClass]; !ok {
257-
return xerrors.Errorf("missing \"%s\" workspace class", DefaultWorkspaceClass)
257+
return xerrors.Errorf("missing default workspace class (\"%s\")", DefaultWorkspaceClass)
258258
}
259259
for name, class := range c.WorkspaceClasses {
260260
if errs := validation.IsValidLabelValue(name); len(errs) > 0 {

components/ws-manager-api/go/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestValidate(t *testing.T) {
5656
Cfg: fromValidConfig(func(c *Configuration) {
5757
delete(c.WorkspaceClasses, DefaultWorkspaceClass)
5858
}),
59-
Expectation: `missing "default" workspace class`,
59+
Expectation: `missing default workspace class ("g1-standard")`,
6060
},
6161
{
6262
Name: "invalid workspace class name",

components/ws-manager-api/go/crd/v1/webhook_suite_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"testing"
1414
"time"
1515

16+
"github.com/gitpod-io/gitpod/common-go/util"
1617
. "github.com/onsi/ginkgo/v2"
1718
. "github.com/onsi/gomega"
1819

@@ -48,11 +49,16 @@ var _ = BeforeSuite(func() {
4849

4950
ctx, cancel = context.WithCancel(context.TODO())
5051

52+
crdPath := filepath.Join("..", "..", "config", "crd", "bases")
53+
if !util.InLeewayBuild() {
54+
crdPath = filepath.Join("..", "..", "..", "..", "ws-manager-mk2", "config", "crd", "bases")
55+
}
56+
5157
By("bootstrapping test environment")
5258
testEnv = &envtest.Environment{
5359
ControlPlaneStartTimeout: 1 * time.Minute,
5460
ControlPlaneStopTimeout: 1 * time.Minute,
55-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
61+
CRDDirectoryPaths: []string{crdPath},
5662
ErrorIfCRDPathMissing: false,
5763
WebhookInstallOptions: envtest.WebhookInstallOptions{
5864
Paths: []string{filepath.Join("..", "..", "config", "webhook")},

0 commit comments

Comments
 (0)