Skip to content
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 simple external test covering cache verification #118

Merged
merged 6 commits into from
Jan 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions test/external/external_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 VMware, Inc.
// Copyright 2022 VMware, Inc.
// SPDX-License-Identifier: BSD-2-Clause

package external_test
Expand All @@ -19,6 +19,15 @@ import (
. "github.com/onsi/gomega/gbytes"
)

func saveCacheFolder() string {
return filepath.Join(os.TempDir(), "relok8s-save-cache")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually deleting the cache that's being used by relok8s itself right? I don't like that running a test has the side-effect of deleting the actual tooling cache.

Could we instead run these tests pointing to an unique, per-test cache path? This might require adding support for our tool via ENV variable or flag to point to the cache directory.

Copy link
Contributor Author

@josvazg josvazg Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not want to add more code to be able to test, we already abandoned a change for that.

Maybe I can remove the specific layer instead for the test.

Copy link
Contributor

@migmartri migmartri Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, don't worry about it, we can live with that side-effect I guess

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

func expectedLayerFile() string {
layerFilename := "sha256-24fb2886d6f6c5d16481dd7608b47e78a8e92a13d6e64d87d57cb16d5f766d63.gz"
return filepath.Join(saveCacheFolder(), layerFilename)
}

var _ = Describe("External tests", func() {
var (
customRepoPrefix string
Expand Down Expand Up @@ -75,13 +84,26 @@ var _ = Describe("External tests", func() {
})

Scenario("running chart move to intermediate bundle", func() {
steps.When("clear relok8s-save-cache expected layer")
steps.When(fmt.Sprintf("running relok8s chart move -y ../fixtures/testchart --image-patterns ../fixtures/testchart.images.yaml --to-intermediate-bundle %s/testchart-intermediate.tar", tmpDir))
steps.And("the move is computed")
steps.Then("the command says it will archive the chart")
steps.Then("the command says it is writing the hints file")
steps.Then("the command says it is writing the Helm Chart files")
steps.Then("the command says it is writing the container images")
steps.Then("the command says the intermediate bundle is complete")
steps.Then("relok8s-save-cache contains expected layer")

info, err := os.Stat(expectedLayerFile())
Expect(err).ToNot(HaveOccurred())
modtime := info.ModTime()
steps.When(fmt.Sprintf("running relok8s chart move -y ../fixtures/testchart --image-patterns ../fixtures/testchart.images.yaml --to-intermediate-bundle %s/testchart-intermediate-2.tar", tmpDir))
steps.And("the move is computed")
steps.Then("the command says the intermediate bundle 2 is complete")
steps.Then("relok8s-save-cache contains expected layer")
info, err = os.Stat(expectedLayerFile())
Expect(err).ToNot(HaveOccurred())
Expect(info.ModTime()).To(Equal(modtime))
})

Scenario("running chart move from intermediate bundle", func() {
Expand Down Expand Up @@ -261,13 +283,25 @@ var _ = Describe("External tests", func() {
Eventually(test.CommandSession.Out, time.Minute).Should(Say("Intermediate bundle complete at %s/testchart-intermediate.tar\n", tmpDir))
})

define.Then(`^the command says the intermediate bundle 2 is complete$`, func() {
Eventually(test.CommandSession.Out, time.Minute).Should(Say("Intermediate bundle complete at %s/testchart-intermediate-2.tar\n", tmpDir))
})

define.Then(`^the command says it is writing the hints file$`, func() {
Eventually(test.CommandSession.Out, time.Minute).Should(Say("Writing hints.yaml...\n"))
})

define.Then(`^remove the archive folder at testchart-intermediate.tar$`, func() {
err := os.Remove("testchart-intermediate.tar")
define.When(`^clear relok8s-save-cache expected layer$`, func() {
err := os.RemoveAll(expectedLayerFile())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thanks!

Expect(err).ToNot(HaveOccurred())
})

define.Then(`^relok8s-save-cache contains expected layer$`, func() {
info, err := os.Stat(expectedLayerFile())
Expect(err).ToNot(HaveOccurred())
Expect(info.IsDir()).To(BeFalse())
Expect(info.Size()).To(Equal(int64(767322)))
Expect(time.Since(info.ModTime())).To(BeNumerically("<", 5*time.Minute))
})
})
})