Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test-backend:

.PHONY: test-e2e
test-e2e:
go test -v -timeout=150m -count=1 ./test/e2e
go test -tags e2e -v -timeout=150m -count=1 ./test/e2e

.PHONY: test-frontend
test-frontend:
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/create_alert_rule_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//go:build e2e

package e2e

import (
"context"
"errors"
"testing"

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

func TestCreateUserDefinedAlertRule(t *testing.T) {
f, err := framework.New()
if errors.Is(err, framework.ErrSkip) {
t.Skip(err)
}
if err != nil {
t.Fatalf("Failed to create framework: %v", err)
}
Expand Down
12 changes: 2 additions & 10 deletions test/e2e/delete_alert_rule_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//go:build e2e

package e2e

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -19,9 +20,6 @@ import (

func TestDeleteAlertRule(t *testing.T) {
f, err := framework.New()
if errors.Is(err, framework.ErrSkip) {
t.Skip(err)
}
if err != nil {
t.Fatalf("Failed to create framework: %v", err)
}
Expand All @@ -38,10 +36,6 @@ func TestDeleteAlertRule(t *testing.T) {
ruleIDs := make([]string, 0, len(ruleNames))

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

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

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

deleteReq := managementrouter.BulkDeleteAlertRulesRequest{
Expand Down
13 changes: 7 additions & 6 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build e2e

package framework

import (
Expand Down Expand Up @@ -38,23 +40,22 @@ type Framework struct {

type CleanupFunc func() error

// ErrSkip is returned by New when required environment variables are not set,
// so callers can distinguish a missing-env skip from a real error.
var ErrSkip = fmt.Errorf("required environment variables not set, skipping e2e test")

// New creates a Framework backed by a real Kubernetes cluster. It reads
// KUBECONFIG and PLUGIN_URL from the environment and returns a singleton
// so that expensive client setup happens only once per test binary.
func New() (*Framework, error) {
if f != nil {
return f, nil
}

kubeConfigPath := os.Getenv("KUBECONFIG")
if kubeConfigPath == "" {
return nil, fmt.Errorf("%w: KUBECONFIG", ErrSkip)
return nil, fmt.Errorf("KUBECONFIG environment variable is not set")
}

pluginURL := os.Getenv("PLUGIN_URL")
if pluginURL == "" {
return nil, fmt.Errorf("%w: PLUGIN_URL", ErrSkip)
return nil, fmt.Errorf("PLUGIN_URL environment variable is not set")
}

config, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath)
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build e2e

package e2e

import (
Expand Down