Skip to content

Commit

Permalink
Create integration test environment variable handler (#475)
Browse files Browse the repository at this point in the history
Skip integration tests unless the "INTEGRATION" environment variable is set
  • Loading branch information
jessejlt authored Dec 11, 2024
1 parent 0db0e6b commit 1a8d5f0
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
run: go build -mod=vendor -v ./...

- name: Test
run: go test -race -mod=vendor -v -timeout=30m ./...
run: INTEGRATION=1 go test -race -mod=vendor -v -timeout=30m ./...
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ clean:
.PHONY: clean

test:
go test -timeout 30m ./...
INTEGRATION=1 go test -timeout 30m ./...
.PHONY: test

default:
Expand Down
5 changes: 3 additions & 2 deletions ingestor/adx/uploader_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
//go:build !disableDocker

package adx

import (
"context"
"testing"

"github.com/Azure/adx-mon/pkg/testutils"
"github.com/Azure/adx-mon/pkg/testutils/kustainer"
"github.com/Azure/azure-kusto-go/kusto"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
)

func TestClusterRequiresDirectIngest(t *testing.T) {
testutils.IntegrationTest(t)

ctx := context.Background()
k, err := kustainer.Run(ctx, "mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest", kustainer.WithStarted())
testcontainers.CleanupContainer(t, k)
Expand Down
4 changes: 2 additions & 2 deletions ingestor/cluster/coordinator_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !disableDocker

package cluster

import (
Expand Down Expand Up @@ -263,6 +261,8 @@ func (l *fakePodLister) Pods(namespace string) v12.PodNamespaceLister {
}

func TestCoordinatorInK8s(t *testing.T) {
testutils.IntegrationTest(t)

// This is an integration test where a Coordinator is created using a k3s cluster
// configuration and a statefulset is then created that matches the Coordinator's
// peer predicate. What we're testing is that the Coordinator is correctly utilizing
Expand Down
4 changes: 2 additions & 2 deletions ingestor/storage/kql_functions_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !disableDocker

package storage_test

import (
Expand All @@ -22,6 +20,8 @@ import (
)

func TestFunctions(t *testing.T) {
testutils.IntegrationTest(t)

scheme := clientgoscheme.Scheme
require.NoError(t, clientgoscheme.AddToScheme(scheme))
require.NoError(t, v1.AddToScheme(scheme))
Expand Down
4 changes: 2 additions & 2 deletions pkg/crd/crd_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !disableDocker

package crd_test

import (
Expand Down Expand Up @@ -44,6 +42,8 @@ func (s *TestStore) Count() int32 {
}

func TestCRD(t *testing.T) {
testutils.IntegrationTest(t)

crdPath := filepath.Join(t.TempDir(), "crd.yaml")
require.NoError(t, testutils.CopyFile("../../kustomize/bases/functions_crd.yaml", crdPath))
fnCrdPath := filepath.Join(t.TempDir(), "fn-crd.yaml")
Expand Down
5 changes: 3 additions & 2 deletions pkg/testutils/collector/collector_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
//go:build !disableDocker

package collector_test

import (
"context"
"testing"
"time"

"github.com/Azure/adx-mon/pkg/testutils"
"github.com/Azure/adx-mon/pkg/testutils/collector"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
)

func TestCollector(t *testing.T) {
testutils.IntegrationTest(t)

ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
defer cancel()

Expand Down
5 changes: 3 additions & 2 deletions pkg/testutils/ingestor/ingestor_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
//go:build !disableDocker

package ingestor_test

import (
"context"
"testing"
"time"

"github.com/Azure/adx-mon/pkg/testutils"
"github.com/Azure/adx-mon/pkg/testutils/ingestor"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
)

func TestIngestor(t *testing.T) {
testutils.IntegrationTest(t)

ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
defer cancel()

Expand Down
2 changes: 2 additions & 0 deletions pkg/testutils/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
)

func TestIntegration(t *testing.T) {
testutils.IntegrationTest(t)

// An extra generous timeout for the test. The test should run in
// about 5 minutes, but when running with the race detector, it
// can take longer.
Expand Down
6 changes: 4 additions & 2 deletions pkg/testutils/kql_verify_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !disableDocker

package testutils_test

import (
Expand All @@ -13,6 +11,8 @@ import (
)

func TestTableExists(t *testing.T) {
testutils.IntegrationTest(t)

k, err := kustainer.Run(context.Background(), "mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest", kustainer.WithStarted())
testcontainers.CleanupContainer(t, k)
require.NoError(t, err)
Expand All @@ -22,6 +22,8 @@ func TestTableExists(t *testing.T) {
}

func TestTableHasRows(t *testing.T) {
testutils.IntegrationTest(t)

k, err := kustainer.Run(context.Background(), "mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest", kustainer.WithStarted())
testcontainers.CleanupContainer(t, k)
require.NoError(t, err)
Expand Down
13 changes: 13 additions & 0 deletions pkg/testutils/skip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package testutils

import (
"os"
"testing"
)

func IntegrationTest(t *testing.T) {
t.Helper()
if os.Getenv("INTEGRATION") == "" {
t.Skip("skipping integration tests, set environment variable INTEGRATION")
}
}
4 changes: 2 additions & 2 deletions pkg/testutils/uploader_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !disableDocker

package testutils_test

import (
Expand All @@ -16,6 +14,8 @@ import (
)

func TestUploader(t *testing.T) {
testutils.IntegrationTest(t)

var (
database = "NetDefaultDB"
table = "Table_0"
Expand Down

0 comments on commit 1a8d5f0

Please sign in to comment.