-
Notifications
You must be signed in to change notification settings - Fork 79
feature: integration test: in github workflow #396
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
Changes from 1 commit
1bd1d4a
cfaafec
d01e02a
bc63190
5a6beca
ef374fb
ae43bae
fb75f69
08c8a31
90f190d
0444bfd
4d5595e
392fd96
e9a9b90
4c4c8fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| name: Golang Unit and Integration Tests | ||
| on: | ||
| push: | ||
| branches: | ||
| - "master" | ||
| paths: | ||
| - "**.go" | ||
| - "**.golden" | ||
| pull_request: | ||
| branches: | ||
| - "master" | ||
| paths: | ||
| - "**.go" | ||
| - "**.golden" | ||
| workflow_dispatch: | ||
| inputs: | ||
| logLevel: | ||
| description: "Log level" | ||
| required: true | ||
| default: "warning" | ||
|
|
||
| jobs: | ||
| integration-tests: | ||
| name: Integration tests | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 2 | ||
| - name: Install lynx for xdg-open support | ||
| run: sudo apt-get install lynx | ||
| - name: Setup Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: "1.23" | ||
| - name: Install Docker Compose | ||
| run: | | ||
| sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | ||
| sudo chmod +x /usr/local/bin/docker-compose | ||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
| - name: Create k8s Kind Cluster | ||
| uses: helm/[email protected] | ||
| with: | ||
| cluster_name: "kind-cluster" | ||
| - name: Run integration tests | ||
| run: | | ||
| make integration-test | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,4 +85,13 @@ test: check | |
| go test -failfast --short ./... -race | ||
| ## Lint check Golang | ||
| lint: | ||
| golangci-lint run ./... | ||
| golangci-lint run ./... | ||
| ## Runs integration tests | ||
| ## it does not start kind (neither install CRD), only starts nats | ||
| ## hence to successful run you need a k8s cluster (with installed meshsync CRD); | ||
| ## docker compose exposes nats on default ports to host, so they must be available | ||
| integration-test: | ||
| docker compose up -d | ||
| sleep 4 | ||
|
Contributor
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. The
Contributor
Author
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. thanks gemi 🤗 , the idea is good, but the suggested snippet is not working.
Member
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. This is a good comment from Gemini. While use of
Contributor
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. You're welcome! I understand the challenges with dynamic checks in |
||
| RUN_INTEGRATION_TESTS=true go test -v -count=1 -run Integration . | ||
| docker compose down | ||
leecalcote marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| version: '3.8' | ||
|
|
||
| # this docker compose is solely for local run with main_test.go | ||
| services: | ||
| nats: | ||
| image: nats:2.11-alpine3.21 | ||
| container_name: nats | ||
| ports: | ||
| - "4222:4222" # client connections | ||
| - "8222:8222" # HTTP monitoring (optional) | ||
| healthcheck: | ||
| test: ["CMD", "curl", "-f", "http://localhost:8222/varz"] | ||
| interval: 5s | ||
| timeout: 3s | ||
| retries: 5 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/layer5io/meshkit/broker" | ||
| "github.com/layer5io/meshkit/broker/nats" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| var runIntegrationTest bool | ||
| var testMeshsyncTopic = "meshery.meshsync.core" | ||
| var testMeshsyncNatsURL = "localhost:4222" | ||
|
|
||
| func init() { | ||
| runIntegrationTest = os.Getenv("RUN_INTEGRATION_TESTS") == "true" | ||
| } | ||
|
|
||
| /** | ||
| * this test requires k8s cluster (with installed CRDs: broker, meshsync) and nats streaming | ||
| * could be a good idea to put a test into ci workflow: | ||
| * - start a kind cluster and nats container | ||
| * - check that the messages are received in nats | ||
| * -- | ||
| * use docker compose to start nats | ||
| * --- | ||
| * TODO: | ||
| * - add starting kind cluster to docker compose | ||
| * - run all test in container to avoid port exposure to host | ||
| */ | ||
| func TestWithNatsIntegration(t *testing.T) { | ||
| if !runIntegrationTest { | ||
| t.Skip("skipping integration test") | ||
| } | ||
|
|
||
| br, err := nats.New(nats.Options{ | ||
| URLS: []string{testMeshsyncNatsURL}, | ||
| ConnectionName: "meshsync", | ||
| Username: "", | ||
| Password: "", | ||
| ReconnectWait: 2 * time.Second, | ||
| MaxReconnect: 60, | ||
| }) | ||
| if err != nil { | ||
| t.Fatal("error connecting to nats", err) | ||
| } | ||
| count := 0 | ||
|
|
||
| go func() { | ||
| out := make(chan *broker.Message) | ||
| br.SubscribeWithChannel(testMeshsyncTopic, "", out) | ||
|
|
||
| for range out { | ||
| count++ | ||
| } | ||
| }() | ||
|
|
||
| os.Setenv("BROKER_URL", testMeshsyncNatsURL) | ||
| go main() | ||
|
|
||
| <-time.After(time.Second * 8) | ||
| // TODO some more meaningful check | ||
| assert.True(t, count > 0) | ||
leecalcote marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| t.Logf("received %d messages from broker", count) | ||
| t.Log("done") | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.