diff --git a/Taskfile.yaml b/Taskfile.yaml deleted file mode 100644 index b55bdd3ab..000000000 --- a/Taskfile.yaml +++ /dev/null @@ -1,38 +0,0 @@ -version: '3' - -tasks: - unit-test: - - go test -v -short ./... - unit-test-with-report: - - go test -v ./... -coverpkg=./... -coverprofile cover.out - - go tool cover -html cover.out -o coverage.html - integration-tests: - - go run . init --profile default --cloud aws --region $AWS_REGION --aws-nodes-spot --cluster-name $CLUSTER_NAME --s3-suffix $SUFFIX_S3 --admin-email $EMAIL --hosted-zone-name $HOSTED_ZONE_NAME --gitops-branch $GITOPS_BRANCH --silent || echo $? - - go test -v -run TestAreS3BucketsLiveIntegration ./internal/aws || echo $? - - go run . cluster create --silent || echo $? - - go test -v -run TestArgoCDLivenessIntegration ./internal/argocd || echo $? - - go test -v -run TestArgoWorkflowLivenessIntegration ./internal/argocd || echo $? - - go test -v -run TestGitLabLivenessIntegration ./internal/gitlab || echo $? - - go test -v -run TestMetaphorsLivenessIntegration ./internal/metaphor || echo $? - - go run . destroy --silent || echo $? - - go test -v -run TestIsVPCByTagDestroyedIntegration ./internal/aws || echo $? - - go test -v -run TestIsLoadBalancerByTagDestroyedIntegration ./internal/aws || echo $? - - go test -v -run TestAreS3BucketsDestroyedIntegration ./internal/aws || echo $? - - go test -v -run TestIsKMSKeyAliasDestroyedIntegration ./internal/aws || echo $? - - go test -v -run TestIsEKSDestroyedIntegration ./internal/aws || echo $? - - go run . clean --destroy-buckets --destroy-confirm || echo $? - - aws s3 sync $HOME/kubefirst/logs s3://$CICD_LOGS_BUCKET - integration-test-for-tls-localdev: - - go test -v -run TestArgoCertificateIntegration ./internal/ssl -count=1 - e2e-test-local-metaphors: - - go test -v -run TestLocalMetaphorFrontendEndToEnd ./tests -count=1 - e2e-test-cloud-metaphors: - - go test -v -run TestCloudMetaphorsEndToEnd ./tests -count=1 - e2e-test-github-user-creation-and-login: - # creates GitHub user - - go test -v -run TestGitHubUserCreationEndToEnd ./tests -count=1 - # before checking if user exists, we need to wait for Atlantis apply to finish - - sleep 10 - # check is the created user can log in into Vault - # this test requires E2E_VAULT_USERNAME to be set (aone, or kbot) - - go test -v -run TestVaultLoginEndToEnd ./tests -count=1 diff --git a/test/artifacts/init/aws_profile.yaml b/test/artifacts/init/aws_profile.yaml deleted file mode 100644 index 1db6474bd..000000000 --- a/test/artifacts/init/aws_profile.yaml +++ /dev/null @@ -1,5 +0,0 @@ -config: - admin-email: user@domain.com - cloud: aws - hosted-zone-name: my.domain.com - profile: default diff --git a/test/artifacts/init/sample.yaml b/test/artifacts/init/sample.yaml deleted file mode 100644 index baa08d17d..000000000 --- a/test/artifacts/init/sample.yaml +++ /dev/null @@ -1,2 +0,0 @@ -config: - sample: set-by-config diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index c766a180b..000000000 --- a/tests/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# End to End tests - -This directory contains end to end tests to be run against a running Kubefirst instance of the [local](https://docs.kubefirst.io/kubefirst/local/install.html), [AWS with GitHub](https://docs.kubefirst.io/kubefirst/github/install.html), and [AWS with GitLab](https://docs.kubefirst.io/kubefirst/gitlab/install.html) installations. After a successful installation, the tests can be run to verify that the: - -- installation was successful -- cluster is working as expected -- downloaded repositories are working as expected -- Metaphor application is working as expected -- Traefik ingress controller rules are working as expected -- TLS certificates are working as expected -- Vault is working as expected -- Vault initial token is able to be used to login to Vault -- Kubefirst process is able to create new GitHub users via IAC/Webhooks/Atlantis/Terraform -- newly created users are able to login into Vault - -## Taskfile to trigger sequential execution of the tests - -Kubefirst make use of [Taskfile](https://github.com/go-task/task) (instead of makefile), to trigger sequential execution of the tests. The [Taskfile](../Taskfile.yaml) is located in the root of this repository, so you need to run the tests from there. The following test cases are avaialble: - -### test Traefik rules and TLS certificates - -```bash -task integration-test-for-tls-localdev -``` - -### test Metaphor application - -```bash -task e2e-test-local-metaphors -``` - -### test user creation via IAC/Webhooks/Atlantis/Terraform, and check if is able to login with the new user - -```bash -task e2e-test-github-user-creation-and-login -``` diff --git a/tests/metaphor-frontend_test.go b/tests/metaphor-frontend_test.go deleted file mode 100644 index 02c6af666..000000000 --- a/tests/metaphor-frontend_test.go +++ /dev/null @@ -1,105 +0,0 @@ -/* -Copyright (C) 2021-2023, Kubefirst - -This program is licensed under MIT. -See the LICENSE file for more details. -*/ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/kubefirst/runtime/configs" - "github.com/kubefirst/runtime/pkg" - "github.com/spf13/viper" -) - -// TestLocalMetaphorFrontendEndToEnd tests the Metaphor frontend (dev, staging, prod), and look for a http response code of 200 -func TestLocalMetaphorFrontendEndToEnd(t *testing.T) { - - if testing.Short() { - t.Skip("skipping end to tend test") - } - - testCases := []struct { - name string - url string - expected int - }{ - {name: "metaphor frontend development", url: pkg.MetaphorFrontendSlimTLSDev, expected: http.StatusOK}, - {name: "metaphor frontend staging", url: pkg.MetaphorFrontendSlimTLSStaging, expected: http.StatusOK}, - {name: "metaphor frontend production", url: pkg.MetaphorFrontendSlimTLSProd, expected: http.StatusOK}, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - - resp, err := http.Get(tc.url) - if err != nil { - t.Errorf(err.Error()) - return - } - defer resp.Body.Close() - - fmt.Println("HTTP status code:", resp.StatusCode) - - if resp.StatusCode != http.StatusOK { - t.Errorf("HTTP status code is not 200") - } - }) - } - -} - -// TestCloudMetaphorsEndToEnd tests the Metaphor frontend, and look for a http response code of 200 for cloud -func TestCloudMetaphorsEndToEnd(t *testing.T) { - - if testing.Short() { - t.Skip("skipping end to tend test") - } - - config := configs.ReadConfig() - if err := pkg.SetupViper(config); err != nil { - t.Errorf(err.Error()) - } - - testCases := []struct { - name string - url string - expected int - }{ - {name: "metaphor frontend development", url: "https://metaphor-development." + viper.GetString("aws.hostedzonename"), expected: http.StatusOK}, - {name: "metaphor frontend staging", url: "https://metaphor-staging." + viper.GetString("aws.hostedzonename"), expected: http.StatusOK}, - {name: "metaphor frontend production", url: "https://metaphor-production." + viper.GetString("aws.hostedzonename"), expected: http.StatusOK}, - {name: "metaphor NodeJs development", url: "https://metaphor-development." + viper.GetString("aws.hostedzonename") + "/app", expected: http.StatusOK}, - {name: "metaphor NodeJs staging", url: "https://metaphor-staging." + viper.GetString("aws.hostedzonename") + "/app", expected: http.StatusOK}, - {name: "metaphor NodeJs production", url: "https://metaphor-production." + viper.GetString("aws.hostedzonename") + "/app", expected: http.StatusOK}, - {name: "metaphor Go development", url: "https://metaphor-go-development." + viper.GetString("aws.hostedzonename") + "/app", expected: http.StatusOK}, - {name: "metaphor Go staging", url: "https://metaphor-go-staging." + viper.GetString("aws.hostedzonename") + "/app", expected: http.StatusOK}, - {name: "metaphor Go production", url: "https://metaphor-go-production." + viper.GetString("aws.hostedzonename") + "/app", expected: http.StatusOK}, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - - resp, err := http.Get(tc.url) - if err != nil { - t.Errorf(err.Error()) - return - } - defer resp.Body.Close() - - fmt.Println("HTTP status code:", resp.StatusCode) - - if resp.StatusCode != http.StatusOK { - t.Errorf("HTTP status code is not 200") - } - if resp.StatusCode != tc.expected { - t.Errorf("[%s] wanted http status code (%d), got (%d)", tc.url, resp.StatusCode, tc.expected) - } - }) - } - -} diff --git a/tests/ngrok_test.go b/tests/ngrok_test.go deleted file mode 100644 index 0b581255f..000000000 --- a/tests/ngrok_test.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright (C) 2021-2023, Kubefirst - -This program is licensed under MIT. -See the LICENSE file for more details. -*/ -package tests - -import ( - "fmt" - "net/http" - "testing" - "time" - - "github.com/kubefirst/runtime/configs" - "github.com/kubefirst/runtime/pkg" - "github.com/spf13/viper" -) - -// TestNgrokGitHubWebhookIntegration tests the ngrok GitHub webhook response, and look for a http response code of 200 -func TestNgrokGitHubWebhookIntegration(t *testing.T) { - - if testing.Short() { - t.Skip("skipping end to tend test") - } - - config := configs.ReadConfig() - err := pkg.SetupViper(config) - if err != nil { - t.Error(err) - } - - testCases := []struct { - name string - url string - expected int - }{ - {name: "ngrok", url: viper.GetString("ngrok.url") + "/events", expected: http.StatusOK}, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - - client := &http.Client{ - Timeout: time.Second * 10, - } - resp, err := client.Get(tc.url) - if err != nil { - t.Errorf(err.Error()) - return - } - defer resp.Body.Close() - - fmt.Println("HTTP status code:", resp.StatusCode) - - if resp.StatusCode != http.StatusOK { - t.Errorf("HTTP status code is not 200") - } - }) - } - -} diff --git a/tests/vault_test.go b/tests/vault_test.go deleted file mode 100644 index 6d4a57ff9..000000000 --- a/tests/vault_test.go +++ /dev/null @@ -1,169 +0,0 @@ -/* -Copyright (C) 2021-2023, Kubefirst - -This program is licensed under MIT. -See the LICENSE file for more details. -*/ -package tests - -import ( - "context" - "os" - "testing" - "time" - - "github.com/chromedp/chromedp" - "github.com/kubefirst/runtime/configs" - "github.com/kubefirst/runtime/pkg" - "github.com/spf13/viper" -) - -// TestVaultLoginEndToEnd tests the end to end flow of logging into the cloud and local vault and retrieving a secret -// from it. This test is not run by default because it requires a cloud vault to be running. -// This test does: -// - login to the cloud vault -// - make sure the login was successful -// - retrieve kbot secret -// - logout of the cloud vault -// - login to the cloud vault again using kbot credentials and userpass flow -// - make sure the kbot is logged in -// -// prerequisites: this test requires E2E_VAULT_USERNAME to be set to "aone" in case we want to test a new created user -// and "kbot" in case we want to test the login for the initial account -func TestVaultLoginEndToEnd(t *testing.T) { - - if testing.Short() { - t.Skip("skipping end to tend test") - } - - username := os.Getenv("E2E_VAULT_USERNAME") - if username == "" { - t.Error("E2E_VAULT_USERNAME is not set") - return - } - - config := configs.ReadConfig() - - err := pkg.SetupViper(config) - if err != nil { - t.Error(err) - } - - initialVaultToken := viper.GetString("vault.token") - if initialVaultToken == "" { - t.Error("Vault token is empty") - } - - // Headless is active by default - opts := append(chromedp.DefaultExecAllocatorOptions[3:], - chromedp.NoFirstRun, - chromedp.NoDefaultBrowserCheck, - chromedp.IgnoreCertErrors, - chromedp.Headless, - ) - - ctx, cancel := chromedp.NewExecAllocator(context.Background(), opts...) - defer cancel() - - // create chrome instance - ctx, cancel = chromedp.NewContext(ctx) - defer cancel() - - // create a timeout - ctx, cancel = context.WithTimeout(ctx, 60*time.Second) - defer cancel() - - // find Vault url - var vaultURL string - switch viper.GetString("cloud") { - case pkg.CloudK3d: - vaultURL = viper.GetString("vault.local.service") - default: - // cloud default - vaultURL = "https://vault." + viper.GetString("aws.hostedzonename") - } - - if err = chromedp.Run( - ctx, - chromedp.Navigate(vaultURL), - chromedp.WaitVisible("//h1[text()='Sign in to Vault']"), - ); err != nil { - t.Error(err.Error()) - } - - if err = chromedp.Run(ctx, chromedp.SendKeys(`//form/div/div/input`, initialVaultToken)); err != nil { - t.Error(err) - } - - time.Sleep(1 * time.Second) - - if err = chromedp.Run(ctx, chromedp.Click(`//button[@id='auth-submit']`)); err != nil { - t.Error(err) - } - - // confirm its logged in - if err = chromedp.Run(ctx, - chromedp.WaitVisible(`//div[@class='level-left']/h1[contains(text(),'Secrets Engines')]`), - ); err != nil { - t.Error(err) - } - - if err = chromedp.Run(ctx, - chromedp.Click(`(//div[@class='linkable-item-content'])[3]//a`), - ); err != nil { - t.Error(err) - } - - if err = chromedp.Run(ctx, chromedp.Click(`(//a)[10]`)); err != nil { - t.Error(err) - } - - // show secret - if err = chromedp.Run(ctx, chromedp.Click(`//button[@class=' masked-input-toggle button']`)); err != nil { - t.Error(err) - } - - var initialPassword string - if err = chromedp.Run(ctx, - chromedp.Text(`//pre[@class='masked-value display-only is-word-break']`, &initialPassword), - ); err != nil { - t.Error(err) - } - - if initialPassword == "" { - t.Error("initial user password is empty") - } - - vaultLogoutURL := vaultURL + "/ui/vault/logout" - if err = chromedp.Run(ctx, - chromedp.Navigate(vaultLogoutURL), - ); err != nil { - t.Error(err) - } - - // select - if err = chromedp.Run(ctx, chromedp.SetValue(`//select[@class="select"]`, "userpass", chromedp.BySearch)); err != nil { - t.Error(err) - } - // force wait above select update - time.Sleep(1 * time.Second) - - if err = chromedp.Run(ctx, chromedp.SendKeys(`//input[@id="username"]`, username)); err != nil { - t.Error(err) - } - if err = chromedp.Run(ctx, chromedp.SendKeys(`//input[@id="password"]`, initialPassword)); err != nil { - t.Error(err) - } - - // click sign in - if err = chromedp.Run(ctx, chromedp.Click(`//button[@id='auth-submit']`)); err != nil { - t.Error(err) - } - - if err = chromedp.Run(ctx, - chromedp.WaitVisible(`//div[@class='level-left']/h1[contains(text(),'Secrets Engines')]`), - ); err != nil { - t.Error(err) - } - -}