Skip to content

Commit

Permalink
#208. ADD e2e_composability_test: set up basic tests to ensure that t…
Browse files Browse the repository at this point in the history
…he composed packages flux and games are properly deployed together. UPDATE examples/Makefile with the package-example-composability command and added that command to the package-examples command. RENAME examples/composable-example -> examples/composable-packages
  • Loading branch information
mike-winberry committed Mar 1, 2022
1 parent c5943ee commit a0cd189
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
6 changes: 5 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ vm-destroy: ## Cleanup plz
@vagrant destroy -f

.PHONY: package-examples
package-examples: package-example-big-bang package-example-software-factory package-example-data-injection package-example-game package-example-gitops-data package-example-single-big-bang-package package-example-tiny-kafka package-example-postgres-operator ## Create zarf packages from all examples
package-examples: package-example-big-bang package-example-software-factory package-example-data-injection package-example-game package-example-gitops-data package-example-single-big-bang-package package-example-tiny-kafka package-example-postgres-operator package-example-composability ## Create zarf packages from all examples

.PHONY: package-example-big-bang
package-example-big-bang: ## Create the Big Bang Core example
Expand Down Expand Up @@ -101,3 +101,7 @@ package-example-tiny-kafka: ## Create the Tiny Kafka example
.PHONY: package-example-postgres-operator
package-example-postgres-operator: ## Create the Postgres Operator example
cd postgres-operator && $(ZARF_BIN) package create --confirm && mv zarf-package-* ../sync/

.PHONY: package-example-composability
package-example-composability: ## Create the Composable example
cd composable-packages && $(ZARF_BIN) package create --confirm && mv zarf-package-* ../sync/
File renamed without changes.
63 changes: 63 additions & 0 deletions test/e2e/e2e_composability_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package test

import (
"fmt"
"testing"
"time"

teststructure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/stretchr/testify/require"
)

func TestE2eExampleComposability(t *testing.T) {

e2e := NewE2ETest(t)

// At the end of the test, run `terraform destroy` to clean up any resources that were created
defer teststructure.RunTestStage(e2e.testing, "TEARDOWN", e2e.teardown)

// Upload the Zarf artifacts
teststructure.RunTestStage(e2e.testing, "UPLOAD", func() {
e2e.syncFileToRemoteServer("../../build/zarf", fmt.Sprintf("/home/%s/build/zarf", e2e.username), "0700")
e2e.syncFileToRemoteServer("../../build/zarf-init.tar.zst", fmt.Sprintf("/home/%s/build/zarf-init.tar.zst", e2e.username), "0600")
e2e.syncFileToRemoteServer("../../build/zarf-package-compose-example.tar.zst", fmt.Sprintf("/home/%s/build/zarf-package-compose-example.tar.zst", e2e.username), "0600")
})

teststructure.RunTestStage(e2e.testing, "TEST", func() {
// Make sure `zarf --help` doesn't error
output, err := e2e.runSSHCommand("sudo /home/%s/build/zarf --help", e2e.username)
require.NoError(e2e.testing, err, output)

// run `zarf init`
output, err = e2e.runSSHCommand("sudo bash -c 'cd /home/%s/build && ./zarf init --confirm --components k3s'", e2e.username)
require.NoError(e2e.testing, err, output)

// Deploy the composable package
output, err = e2e.runSSHCommand("sudo bash -c 'cd /home/%s/build && ./zarf package deploy zarf-package-composable-example.tar.zst --confirm'", e2e.username)
require.NoError(e2e.testing, err, output)

// Validate that the composed sub packages exist
require.Contains(e2e.testing, "flux-baseline", output)
require.Contains(e2e.testing, "appliance-demo-multi-games-baseline", output)

// Establish the port-forward into the game service; give the service a few seconds to come up since this is not a command we can retry
time.Sleep(5 * time.Second)
output, err = e2e.runSSHCommand("sudo bash -c '(/home/%s/build/zarf connect doom --local-port 22333 &> /dev/nul &)'", e2e.username)
require.NoError(e2e.testing, err, output)

// Right now we're just checking that `curl` returns 0. It can be enhanced by scraping the HTML that gets returned or something.
output, err = e2e.runSSHCommand("bash -c '[[ $(curl -sfSL --retry 15 --retry-connrefused --retry-delay 5 http://127.0.0.1:22333?doom') ]]'")
require.NoError(e2e.testing, err, output)
require.Contains(e2e.testing, "Zarf needs games too", output)

// Validate that the flux composed component was deployed by describing the flux helm controller and validating availibility
output, err = e2e.runSSHCommand(`sudo bash -c '/usr/sbin/kubectl describe deployment helm-controller -n flux-system'`)
require.NoError(e2e.testing, err, output)
require.Contains(e2e.testing, "1 desired | 1 updated | 1 total | 1 available | 0 unavailable", output)

// Run `zarf destroy` to make sure that works correctly
output, err = e2e.runSSHCommand("sudo bash -c 'cd /home/%s/build && ./zarf destroy --confirm'", e2e.username)
require.NoError(e2e.testing, err, output)
})

}

0 comments on commit a0cd189

Please sign in to comment.