Skip to content

Commit 6ffc7ba

Browse files
sradcocursoragent
andcommitted
test: use build tags for e2e tests, remove ErrSkip pattern
Add //go:build e2e to all e2e test files and the framework so that go test ./... works locally without a cluster. CI runs e2e via make test-e2e which passes -tags e2e. Replace the ErrSkip sentinel with direct error returns from framework.New() — the build tag is the exclusion mechanism, not runtime skips. Tests now t.Fatal immediately if KUBECONFIG or PLUGIN_URL are unset when compiled with the e2e tag. Also adds a unit-test Makefile alias (delegates to test-backend) for clarity. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 6810f45 commit 6ffc7ba

5 files changed

Lines changed: 17 additions & 22 deletions

File tree

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ build-backend:
5858
start-backend:
5959
go run ./cmd/plugin-backend.go -port='9001' -config-path='./config' -static-path='./web/dist'
6060

61-
.PHONY: test-backend
61+
.PHONY: unit-test test-backend
62+
unit-test: test-backend
63+
6264
test-backend:
6365
go test ./pkg/... ./internal/... -v
6466

6567
.PHONY: test-e2e
6668
test-e2e:
67-
go test -v -timeout=150m -count=1 ./test/e2e
69+
go test -tags e2e -v -timeout=150m -count=1 ./test/e2e
6870

6971
.PHONY: test-frontend
7072
test-frontend:

test/e2e/create_alert_rule_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
//go:build e2e
2+
13
package e2e
24

35
import (
46
"context"
5-
"errors"
67
"testing"
78

89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -13,9 +14,6 @@ import (
1314

1415
func TestCreateUserDefinedAlertRule(t *testing.T) {
1516
f, err := framework.New()
16-
if errors.Is(err, framework.ErrSkip) {
17-
t.Skip(err)
18-
}
1917
if err != nil {
2018
t.Fatalf("Failed to create framework: %v", err)
2119
}

test/e2e/delete_alert_rule_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
//go:build e2e
2+
13
package e2e
24

35
import (
46
"bytes"
57
"context"
68
"encoding/json"
7-
"errors"
89
"fmt"
910
"io"
1011
"net/http"
@@ -19,9 +20,6 @@ import (
1920

2021
func TestDeleteAlertRule(t *testing.T) {
2122
f, err := framework.New()
22-
if errors.Is(err, framework.ErrSkip) {
23-
t.Skip(err)
24-
}
2523
if err != nil {
2624
t.Fatalf("Failed to create framework: %v", err)
2725
}
@@ -38,10 +36,6 @@ func TestDeleteAlertRule(t *testing.T) {
3836
ruleIDs := make([]string, 0, len(ruleNames))
3937

4038
for _, name := range ruleNames {
41-
// Each rule needs a unique expression so the spec-equivalence check
42-
// does not reject it as a duplicate of a rule from another test.
43-
// absent() returns 1 when the selector matches nothing, which is
44-
// always the case for a fabricated metric name.
4539
expr := fmt.Sprintf("absent(nonexistent{e2e_rule=%q})", name)
4640
id, err := createRuleViaAPI(ctx, f, managementrouter.CreateAlertRuleRequest{
4741
AlertingRule: &managementrouter.AlertRuleSpec{
@@ -65,8 +59,6 @@ func TestDeleteAlertRule(t *testing.T) {
6559

6660
t.Logf("Created 3 rules with IDs: %v", ruleIDs)
6761

68-
// Allow time for the informer watch event to propagate and
69-
// the relabeled-rules cache to sync the new PrometheusRule.
7062
time.Sleep(2 * time.Second)
7163

7264
deleteReq := managementrouter.BulkDeleteAlertRulesRequest{

test/e2e/framework/framework.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
package framework
24

35
import (
@@ -38,23 +40,22 @@ type Framework struct {
3840

3941
type CleanupFunc func() error
4042

41-
// ErrSkip is returned by New when required environment variables are not set,
42-
// so callers can distinguish a missing-env skip from a real error.
43-
var ErrSkip = fmt.Errorf("required environment variables not set, skipping e2e test")
44-
43+
// New creates a Framework backed by a real Kubernetes cluster. It reads
44+
// KUBECONFIG and PLUGIN_URL from the environment and returns a singleton
45+
// so that expensive client setup happens only once per test binary.
4546
func New() (*Framework, error) {
4647
if f != nil {
4748
return f, nil
4849
}
4950

5051
kubeConfigPath := os.Getenv("KUBECONFIG")
5152
if kubeConfigPath == "" {
52-
return nil, fmt.Errorf("%w: KUBECONFIG", ErrSkip)
53+
return nil, fmt.Errorf("KUBECONFIG environment variable is not set")
5354
}
5455

5556
pluginURL := os.Getenv("PLUGIN_URL")
5657
if pluginURL == "" {
57-
return nil, fmt.Errorf("%w: PLUGIN_URL", ErrSkip)
58+
return nil, fmt.Errorf("PLUGIN_URL environment variable is not set")
5859
}
5960

6061
config, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath)

test/e2e/helpers_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build e2e
2+
13
package e2e
24

35
import (

0 commit comments

Comments
 (0)