Skip to content

Commit

Permalink
fix: see if CI is flaking with the original tests. probably just need…
Browse files Browse the repository at this point in the history
… to nolint ignore them

Signed-off-by: Kit Patella <[email protected]>
  • Loading branch information
mkcp committed Sep 25, 2024
1 parent 4a0d6ef commit 4da92b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
6 changes: 1 addition & 5 deletions src/test/external/ext_in_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ func (suite *ExtInClusterTestSuite) Test_1_Deploy() {
initArgs = append(initArgs, inClusterInitCredentialArgs...)
err := exec.CmdWithPrint(zarfBinPath, initArgs...)
suite.NoError(err, "unable to initialize the k8s server with zarf")

// Create tempdir
temp := suite.T().TempDir()
defer os.Remove(temp)
createPodInfoPackageWithInsecureSources(suite.T(), temp)

// Deploy the flux example package
Expand Down Expand Up @@ -199,11 +198,8 @@ func (suite *ExtInClusterTestSuite) Test_1_Deploy() {
err = pkgkubernetes.WaitForReady(waitCtx, c.Watcher, objs)
suite.NoError(err)

// Cleanup
_, _, err = exec.CmdWithTesting(suite.T(), exec.PrintCfg(), zarfBinPath, "destroy", "--confirm")
suite.NoError(err, "unable to teardown zarf")
err = os.RemoveAll(temp)
suite.NoError(err, "unable to remove tempdir")
}

func TestExtInClusterTestSuite(t *testing.T) {
Expand Down
47 changes: 14 additions & 33 deletions src/test/external/ext_out_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@ func (suite *ExtOutClusterTestSuite) SetupSuite() {
suite.Assertions = require.New(suite.T())

// Teardown any leftovers from previous tests
err := exec.CmdWithPrint("k3d", "cluster", "delete", clusterName)
suite.NoError(err, "unable to teardown cluster")
err = exec.CmdWithPrint("docker", "rm", "-f", "k3d-"+registryHost)
suite.NoError(err, "unable to teardown k3d registry")
err = exec.CmdWithPrint("docker", "compose", "down")
suite.NoError(err, "unable to teardown docker compose resources")
err = exec.CmdWithPrint("docker", "network", "remove", network)
suite.NoError(err, "unable to teardown docker network resources")
_ = exec.CmdWithPrint("k3d", "cluster", "delete", clusterName)
_ = exec.CmdWithPrint("docker", "rm", "-f", "k3d-"+registryHost)
_ = exec.CmdWithPrint("docker", "compose", "down")
_ = exec.CmdWithPrint("docker", "network", "remove", network)

// Set up a network for everything to live inside
err = exec.CmdWithPrint("docker", "network", "create", "--driver=bridge", "--subnet="+subnet, "--gateway="+gateway, network)
// Setup a network for everything to live inside
err := exec.CmdWithPrint("docker", "network", "create", "--driver=bridge", "--subnet="+subnet, "--gateway="+gateway, network)
suite.NoError(err, "unable to create the k3d registry")

// Install a k3d-managed registry server to act as the 'remote' container registry
Expand Down Expand Up @@ -150,8 +146,8 @@ func (suite *ExtOutClusterTestSuite) Test_1_Deploy() {

func (suite *ExtOutClusterTestSuite) Test_2_DeployGitOps() {
// Deploy the flux example package
// Cleanup dir at end of test
temp := suite.T().TempDir()
defer os.Remove(temp)
createPodInfoPackageWithInsecureSources(suite.T(), temp)

deployArgs := []string{"package", "deploy", filepath.Join(temp, "zarf-package-podinfo-flux-amd64.tar.zst"), "--confirm"}
Expand All @@ -162,9 +158,6 @@ func (suite *ExtOutClusterTestSuite) Test_2_DeployGitOps() {
deployArgs = []string{"package", "deploy", path, "--confirm"}
err = exec.CmdWithPrint(zarfBinPath, deployArgs...)
suite.NoError(err)

err = os.RemoveAll(temp)
suite.NoError(err, "unable to remove tempdir")
}

func (suite *ExtOutClusterTestSuite) Test_3_AuthToPrivateHelmChart() {
Expand All @@ -175,13 +168,12 @@ func (suite *ExtOutClusterTestSuite) Test_3_AuthToPrivateHelmChart() {

tempDir := suite.T().TempDir()
repoPath := filepath.Join(tempDir, "repositories.yaml")
// Cleanup at end of func
err := os.Setenv("HELM_REPOSITORY_CONFIG", repoPath)
suite.Error(err, "Unable to set HELM_REPOSITORY_CONFIG")
os.Setenv("HELM_REPOSITORY_CONFIG", repoPath)
defer os.Unsetenv("HELM_REPOSITORY_CONFIG")

packagePath := filepath.Join("..", "packages", "external-helm-auth")
findImageArgs := []string{"dev", "find-images", packagePath}
err = exec.CmdWithPrint(zarfBinPath, findImageArgs...)
err := exec.CmdWithPrint(zarfBinPath, findImageArgs...)
suite.Error(err, "Since auth has not been setup, this should fail")

repoFile := repo.NewFile()
Expand All @@ -203,9 +195,6 @@ func (suite *ExtOutClusterTestSuite) Test_3_AuthToPrivateHelmChart() {
packageCreateArgs := []string{"package", "create", packagePath, fmt.Sprintf("--output=%s", tempDir), "--confirm"}
err = exec.CmdWithPrint(zarfBinPath, packageCreateArgs...)
suite.NoError(err, "Unable to create package, helm auth likely failed")

err = os.Unsetenv("HELM_REPOSITORY_CONFIG")
suite.Error(err, "Unable to Unset HELM_REPOSITORY_CONFIG")
}

func (suite *ExtOutClusterTestSuite) createHelmChartInGitea(baseURL string, username string, password string) {
Expand All @@ -222,18 +211,17 @@ func (suite *ExtOutClusterTestSuite) createHelmChartInGitea(baseURL string, user
suite.NoError(err)
url := fmt.Sprintf("%s/api/packages/%s/helm/api/charts", baseURL, username)

// Close the file directly at the end of the test
file, err := os.Open(podinfoTarballPath)
suite.NoError(err)
defer file.Close()

body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("file", podinfoTarballPath)
suite.NoError(err)
_, err = io.Copy(part, file)
suite.NoError(err)
err = writer.Close()
suite.NoError(err)
writer.Close()

req, err := http.NewRequest("POST", url, body)
suite.NoError(err)
Expand All @@ -245,11 +233,7 @@ func (suite *ExtOutClusterTestSuite) createHelmChartInGitea(baseURL string, user

resp, err := client.Do(req)
suite.NoError(err)
err = resp.Body.Close()
suite.NoError(err)

err = file.Close()
suite.NoError(err)
resp.Body.Close()
}

func (suite *ExtOutClusterTestSuite) makeGiteaUserPrivate(baseURL string, username string, password string) {
Expand All @@ -272,15 +256,12 @@ func (suite *ExtOutClusterTestSuite) makeGiteaUserPrivate(baseURL string, userna
req.SetBasicAuth(username, password)

client := &http.Client{}
// Close resp body at end of test
resp, err := client.Do(req)
suite.NoError(err)
defer resp.Body.Close()

_, err = io.ReadAll(resp.Body)
suite.NoError(err)

err = resp.Body.Close()
suite.NoError(err, "Unable to close response body")
}

func TestExtOurClusterTestSuite(t *testing.T) {
Expand Down

0 comments on commit 4da92b9

Please sign in to comment.