Skip to content

Commit

Permalink
chore: improvements from review
Browse files Browse the repository at this point in the history
  • Loading branch information
pivotal-marcela-campo committed Mar 19, 2024
1 parent 365141d commit 14e3679
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions internal/brokerpak/packer/pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ func testManifest() *manifest.Manifest {
}

// TODO: can we avoid passing URL template if we change the logic in the packer?
func testManifestTofu() *manifest.Manifest {
version1, _ := version.NewVersion("1.6.0")
func fakeManifestTofu() *manifest.Manifest {
return &manifest.Manifest{
Platforms: []platform.Platform{
{
Expand All @@ -31,7 +30,7 @@ func testManifestTofu() *manifest.Manifest {
},
TerraformVersions: []manifest.TerraformVersion{
{
Version: version1,
Version: version.Must(version.NewVersion("1.6.0")),
Source: "https://github.com/opentofu/opentofu/archive/refs/tags/v1.6.0.zip",
URLTemplate: "https://github.com/opentofu/opentofu/releases/download/v${version}/tofu_${version}_${os}_${arch}.zip",
Default: true,
Expand All @@ -40,9 +39,7 @@ func testManifestTofu() *manifest.Manifest {
}
}

func testManifestTwoTofus() *manifest.Manifest {
version1, _ := version.NewVersion("1.6.0")
version2, _ := version.NewVersion("1.6.1")
func fakeManifestTwoTofus() *manifest.Manifest {
return &manifest.Manifest{
Platforms: []platform.Platform{
{
Expand All @@ -52,12 +49,12 @@ func testManifestTwoTofus() *manifest.Manifest {
},
TerraformVersions: []manifest.TerraformVersion{
{
Version: version1,
Version: version.Must(version.NewVersion("1.6.0")),
Source: "https://github.com/opentofu/opentofu/archive/refs/tags/v1.6.0.zip",
URLTemplate: "https://github.com/opentofu/opentofu/releases/download/v${version}/tofu_${version}_${os}_${arch}.zip",
},
{
Version: version2,
Version: version.Must(version.NewVersion("1.6.1")),
Source: "https://github.com/opentofu/opentofu/archive/refs/tags/v1.6.1.zip",
URLTemplate: "https://github.com/opentofu/opentofu/releases/download/v${version}/tofu_${version}_${os}_${arch}.zip",
Default: true,
Expand All @@ -66,8 +63,7 @@ func testManifestTwoTofus() *manifest.Manifest {
}
}

func testManifestProviders() *manifest.Manifest {
version1, _ := version.NewVersion("3.6.0")
func fakeManifestProviders() *manifest.Manifest {
return &manifest.Manifest{
Platforms: []platform.Platform{
{
Expand All @@ -77,13 +73,12 @@ func testManifestProviders() *manifest.Manifest {
},
TerraformProviders: []manifest.TerraformProvider{{
Name: "terraform-provider-random",
Version: version1,
Version: version.Must(version.NewVersion("3.6.0")),
Source: "https://github.com/terraform-providers/terraform-provider-random/archive/v3.6.0.zip",
}},
}
}

// TODO test with cache
var _ = Describe("Pack", func() {
Context("packing binaries", func() {
It("packs empty binaries", func() {
Expand All @@ -107,7 +102,7 @@ var _ = Describe("Pack", func() {
zipOutputDir := GinkgoT().TempDir()
zipOutputFile := filepath.Join(zipOutputDir, "packdest")

err := packer.Pack(testManifestTofu(), "testmanifest", zipOutputFile, "", false, false)
err := packer.Pack(fakeManifestTofu(), "testmanifest", zipOutputFile, "", false, false)
Expect(err).ToNot(HaveOccurred())
reader, err := zippy.Open(zipOutputFile)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -125,7 +120,7 @@ var _ = Describe("Pack", func() {
zipOutputDir := GinkgoT().TempDir()
zipOutputFile := filepath.Join(zipOutputDir, "packdest")

err := packer.Pack(testManifestTwoTofus(), "testmanifest", zipOutputFile, "", false, false)
err := packer.Pack(fakeManifestTwoTofus(), "testmanifest", zipOutputFile, "", false, false)
Expect(err).ToNot(HaveOccurred())
reader, err := zippy.Open(zipOutputFile)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -142,7 +137,7 @@ var _ = Describe("Pack", func() {
zipOutputDir := GinkgoT().TempDir()
zipOutputFile := filepath.Join(zipOutputDir, "packdest")

err := packer.Pack(testManifestProviders(), "testmanifest", zipOutputFile, "", false, false)
err := packer.Pack(fakeManifestProviders(), "testmanifest", zipOutputFile, "", false, false)
Expect(err).ToNot(HaveOccurred())
reader, err := zippy.Open(zipOutputFile)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -161,7 +156,7 @@ var _ = Describe("Pack", func() {
zipOutputDir := GinkgoT().TempDir()
zipOutputFile := filepath.Join(zipOutputDir, "packdest")

err := packer.Pack(testManifestTofu(), "testmanifest", zipOutputFile, "", true, false)
err := packer.Pack(fakeManifestTofu(), "testmanifest", zipOutputFile, "", true, false)
Expect(err).ToNot(HaveOccurred())
reader, err := zippy.Open(zipOutputFile)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -173,7 +168,7 @@ var _ = Describe("Pack", func() {
zipOutputDir := GinkgoT().TempDir()
zipOutputFile := filepath.Join(zipOutputDir, "packdest")

err := packer.Pack(testManifestTwoTofus(), "testmanifest", zipOutputFile, "", true, false)
err := packer.Pack(fakeManifestTwoTofus(), "testmanifest", zipOutputFile, "", true, false)
Expect(err).ToNot(HaveOccurred())
reader, err := zippy.Open(zipOutputFile)
Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit 14e3679

Please sign in to comment.