-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add e2e tests #458
Open
jessejlt
wants to merge
1
commit into
main
Choose a base branch
from
jesse/e2e-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add e2e tests #458
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ clean: | |
.PHONY: clean | ||
|
||
test: | ||
go test ./... | ||
go test -timeout 30m ./... | ||
.PHONY: test | ||
|
||
default: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package testutils_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Azure/adx-mon/pkg/testutils" | ||
"github.com/Azure/adx-mon/pkg/testutils/collector" | ||
"github.com/Azure/adx-mon/pkg/testutils/ingestor" | ||
"github.com/Azure/adx-mon/pkg/testutils/kustainer" | ||
"github.com/stretchr/testify/require" | ||
"github.com/testcontainers/testcontainers-go" | ||
"github.com/testcontainers/testcontainers-go/modules/k3s" | ||
) | ||
|
||
func TestIntegration(t *testing.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. | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Hour) | ||
defer cancel() | ||
|
||
k3sContainer, err := k3s.Run(ctx, "rancher/k3s:v1.31.2-k3s1") | ||
testcontainers.CleanupContainer(t, k3sContainer) | ||
require.NoError(t, err) | ||
|
||
kustoContainer, err := kustainer.Run(ctx, "mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest", kustainer.WithCluster(ctx, k3sContainer)) | ||
testcontainers.CleanupContainer(t, kustoContainer) | ||
require.NoError(t, err) | ||
|
||
restConfig, _, err := testutils.GetKubeConfig(ctx, k3sContainer) | ||
require.NoError(t, err) | ||
require.NoError(t, kustoContainer.PortForward(ctx, restConfig)) | ||
|
||
kubeconfig, err := testutils.WriteKubeConfig(ctx, k3sContainer, t.TempDir()) | ||
require.NoError(t, err) | ||
t.Logf("Kubeconfig: %s", kubeconfig) | ||
t.Logf("Kustainer: %s", kustoContainer.ConnectionUrl()) | ||
|
||
t.Run("Create databases", func(t *testing.T) { | ||
for _, dbName := range []string{"Metrics", "Logs"} { | ||
require.NoError(t, kustoContainer.CreateDatabase(ctx, dbName)) | ||
} | ||
}) | ||
|
||
ingestorContainer, err := ingestor.Run(ctx, ingestor.WithCluster(ctx, k3sContainer)) | ||
testcontainers.CleanupContainer(t, ingestorContainer) | ||
require.NoError(t, err) | ||
|
||
collectorContainer, err := collector.Run(ctx, collector.WithCluster(ctx, k3sContainer)) | ||
testcontainers.CleanupContainer(t, collectorContainer) | ||
require.NoError(t, err) | ||
|
||
t.Run("Logs", func(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we set the Logs and Metrics blocks to run with |
||
var ( | ||
pollInterval = time.Second | ||
timeout = 5 * time.Minute | ||
database = "Logs" | ||
table = "Collector" | ||
) | ||
|
||
t.Run("Table exists in Kusto", func(t *testing.T) { | ||
require.Eventually(t, func() bool { | ||
return testutils.TableExists(ctx, t, database, table, kustoContainer.ConnectionUrl()) | ||
}, timeout, pollInterval) | ||
}) | ||
|
||
t.Run("Table has rows", func(t *testing.T) { | ||
require.Eventually(t, func() bool { | ||
return testutils.TableHasRows(ctx, t, database, table, kustoContainer.ConnectionUrl()) | ||
}, timeout, pollInterval) | ||
}) | ||
|
||
t.Run("View exists in Kusto", func(t *testing.T) { | ||
require.Eventually(t, func() bool { | ||
return testutils.FunctionExists(ctx, t, database, table, kustoContainer.ConnectionUrl()) | ||
}, timeout, pollInterval) | ||
}) | ||
|
||
t.Run("Verify view schema", func(t *testing.T) { | ||
testutils.VerifyTableSchema(ctx, t, database, table, kustoContainer.ConnectionUrl(), &collector.KustoTableSchema{}) | ||
}) | ||
}) | ||
|
||
t.Run("Metrics", func(t *testing.T) { | ||
var ( | ||
pollInterval = time.Second | ||
timeout = 5 * time.Minute | ||
database = "Metrics" | ||
table = "AdxmonCollectorHealthCheck" | ||
) | ||
|
||
t.Run("Table exists in Kusto", func(t *testing.T) { | ||
require.Eventually(t, func() bool { | ||
return testutils.TableExists(ctx, t, database, table, kustoContainer.ConnectionUrl()) | ||
}, timeout, pollInterval) | ||
}) | ||
|
||
t.Run("Table has rows", func(t *testing.T) { | ||
require.Eventually(t, func() bool { | ||
return testutils.TableHasRows(ctx, t, database, table, kustoContainer.ConnectionUrl()) | ||
}, timeout, pollInterval) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a follow on PR, I think it would be nice to have a way to configure the Kusto batch policies so we can set them to something like 30s for logs (instead of the 5m we hard code them to) which hopefully speeds this test up a lot.