Skip to content

Commit

Permalink
test: Use table test for push image bundle (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Jun 5, 2023
1 parent 5940d32 commit 8d023e5
Showing 1 changed file with 116 additions and 258 deletions.
374 changes: 116 additions & 258 deletions test/e2e/imagebundle/push_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,266 +41,124 @@ var _ = Describe("Push Bundle", func() {
cmd = helpers.NewCommand(GinkgoT(), pushimagebundle.NewCommand)
})

It("Without TLS", func() {
helpers.CreateBundle(
GinkgoT(),
bundleFile,
filepath.Join("testdata", "create-success.yaml"),
)

port, err := freeport.GetFreePort()
Expect(err).NotTo(HaveOccurred())
reg, err := registry.NewRegistry(registry.Config{
StorageDirectory: filepath.Join(tmpDir, "registry"),
Port: uint16(port),
})
Expect(err).NotTo(HaveOccurred())

done := make(chan struct{})
go func() {
defer GinkgoRecover()

Expect(reg.ListenAndServe()).To(Succeed())

close(done)
}()

helpers.WaitForTCPPort(GinkgoT(), "localhost", port)

cmd.SetArgs([]string{
"--image-bundle", bundleFile,
"--to-registry", fmt.Sprintf("localhost:%d", port),
"--to-registry-insecure-skip-tls-verify",
})

Expect(cmd.Execute()).To(Succeed())

helpers.ValidateImageIsAvailable(
GinkgoT(),
"localhost",
port,
"stefanprodan/podinfo",
"6.2.0",
[]*v1.Platform{{
OS: "linux",
Architecture: runtime.GOARCH,
}},
)

Expect(reg.Shutdown(context.Background())).To((Succeed()))

Eventually(done).Should(BeClosed())
})

It("With TLS", func() {
helpers.CreateBundle(
GinkgoT(),
bundleFile,
filepath.Join("testdata", "create-success.yaml"),
)

ipAddr := helpers.GetFirstNonLoopbackIP(GinkgoT())

tempCertDir := GinkgoT().TempDir()
caCertFile, _, certFile, keyFile := helpers.GenerateCertificateAndKeyWithIPSAN(
GinkgoT(),
tempCertDir,
ipAddr,
)

port, err := freeport.GetFreePort()
Expect(err).NotTo(HaveOccurred())
reg, err := registry.NewRegistry(registry.Config{
StorageDirectory: filepath.Join(tmpDir, "registry"),
Host: ipAddr.String(),
Port: uint16(port),
TLS: registry.TLS{
Certificate: certFile,
Key: keyFile,
},
})
Expect(err).NotTo(HaveOccurred())

done := make(chan struct{})
go func() {
defer GinkgoRecover()

Expect(reg.ListenAndServe()).To(Succeed())

close(done)
}()

helpers.WaitForTCPPort(GinkgoT(), ipAddr.String(), port)

cmd.SetArgs([]string{
"--image-bundle", bundleFile,
"--to-registry", fmt.Sprintf("%s:%d", ipAddr, port),
"--to-registry-ca-cert-file", caCertFile,
})

Expect(cmd.Execute()).To(Succeed())

testRoundTripper, err := httputils.TLSConfiguredRoundTripper(
remote.DefaultTransport,
net.JoinHostPort(ipAddr.String(), strconv.Itoa(port)),
false,
caCertFile,
)
Expect(err).NotTo(HaveOccurred())

helpers.ValidateImageIsAvailable(
GinkgoT(),
ipAddr.String(),
port,
"stefanprodan/podinfo",
"6.2.0",
[]*v1.Platform{{
OS: "linux",
Architecture: runtime.GOARCH,
}},
remote.WithTransport(testRoundTripper),
)

Expect(reg.Shutdown(context.Background())).To((Succeed()))

Eventually(done).Should(BeClosed())
})

It("With Insecure TLS", func() {
helpers.CreateBundle(
GinkgoT(),
bundleFile,
filepath.Join("testdata", "create-success.yaml"),
)

ipAddr := helpers.GetFirstNonLoopbackIP(GinkgoT())

tempCertDir := GinkgoT().TempDir()
caCertFile, _, certFile, keyFile := helpers.GenerateCertificateAndKeyWithIPSAN(
GinkgoT(),
tempCertDir,
ipAddr,
)

port, err := freeport.GetFreePort()
Expect(err).NotTo(HaveOccurred())
reg, err := registry.NewRegistry(registry.Config{
StorageDirectory: filepath.Join(tmpDir, "registry"),
Host: ipAddr.String(),
Port: uint16(port),
TLS: registry.TLS{
Certificate: certFile,
Key: keyFile,
},
})
Expect(err).NotTo(HaveOccurred())

done := make(chan struct{})
go func() {
defer GinkgoRecover()

Expect(reg.ListenAndServe()).To(Succeed())

close(done)
}()

helpers.WaitForTCPPort(GinkgoT(), ipAddr.String(), port)

cmd.SetArgs([]string{
"--image-bundle", bundleFile,
"--to-registry", fmt.Sprintf("%s:%d", ipAddr, port),
"--to-registry-insecure-skip-tls-verify",
})

Expect(cmd.Execute()).To(Succeed())

testRoundTripper, err := httputils.TLSConfiguredRoundTripper(
remote.DefaultTransport,
net.JoinHostPort(ipAddr.String(), strconv.Itoa(port)),
false,
caCertFile,
)
Expect(err).NotTo(HaveOccurred())

helpers.ValidateImageIsAvailable(
GinkgoT(),
ipAddr.String(),
port,
"stefanprodan/podinfo",
"6.2.0",
[]*v1.Platform{{
OS: "linux",
Architecture: runtime.GOARCH,
}},
remote.WithTransport(testRoundTripper),
)

Expect(reg.Shutdown(context.Background())).To((Succeed()))

Eventually(done).Should(BeClosed())
})

It("With non-TLS", func() {
helpers.CreateBundle(
GinkgoT(),
bundleFile,
filepath.Join("testdata", "create-success.yaml"),
)

ipAddr := helpers.GetFirstNonLoopbackIP(GinkgoT())

port, err := freeport.GetFreePort()
Expect(err).NotTo(HaveOccurred())
reg, err := registry.NewRegistry(registry.Config{
StorageDirectory: filepath.Join(tmpDir, "registry"),
Host: ipAddr.String(),
Port: uint16(port),
})
Expect(err).NotTo(HaveOccurred())

done := make(chan struct{})
go func() {
defer GinkgoRecover()

Expect(reg.ListenAndServe()).To(Succeed())

close(done)
}()

helpers.WaitForTCPPort(GinkgoT(), ipAddr.String(), port)

cmd.SetArgs([]string{
"--image-bundle", bundleFile,
"--to-registry", fmt.Sprintf("http://%s:%d", ipAddr, port),
})

Expect(cmd.Execute()).To(Succeed())

testRoundTripper, err := httputils.TLSConfiguredRoundTripper(
remote.DefaultTransport,
net.JoinHostPort(ipAddr.String(), strconv.Itoa(port)),
DescribeTable(
"Success",
func(
registryHost string,
registryScheme string,
registryInsecure bool,
) {
helpers.CreateBundle(
GinkgoT(),
bundleFile,
filepath.Join("testdata", "create-success.yaml"),
)

registryCACertFile := ""
registryCertFile := ""
registryKeyFile := ""
if registryHost != "localhost" && registryScheme != "http" {
tempCertDir := GinkgoT().TempDir()
registryCACertFile, _, registryCertFile, registryKeyFile = helpers.GenerateCertificateAndKeyWithIPSAN(
GinkgoT(),
tempCertDir,
net.ParseIP(registryHost),
)
}

port, err := freeport.GetFreePort()
Expect(err).NotTo(HaveOccurred())
reg, err := registry.NewRegistry(registry.Config{
StorageDirectory: filepath.Join(tmpDir, "registry"),
Host: registryHost,
Port: uint16(port),
TLS: registry.TLS{
Certificate: registryCertFile,
Key: registryKeyFile,
},
})
Expect(err).NotTo(HaveOccurred())

done := make(chan struct{})
go func() {
defer GinkgoRecover()

Expect(reg.ListenAndServe()).To(Succeed())

close(done)
}()

helpers.WaitForTCPPort(GinkgoT(), registryHost, port)

registryHostWithOptionalScheme := fmt.Sprintf("%s:%d", registryHost, port)
if registryScheme != "" {
registryHostWithOptionalScheme = fmt.Sprintf(
"%s://%s",
registryScheme,
registryHostWithOptionalScheme,
)
}

args := []string{
"--image-bundle", bundleFile,
"--to-registry", registryHostWithOptionalScheme,
}
if registryInsecure {
args = append(args, "--to-registry-insecure-skip-tls-verify")
} else if registryCACertFile != "" {
args = append(args, "--to-registry-ca-cert-file", registryCACertFile)
}

cmd.SetArgs(args)

Expect(cmd.Execute()).To(Succeed())

testRoundTripper, err := httputils.TLSConfiguredRoundTripper(
remote.DefaultTransport,
net.JoinHostPort(registryHost, strconv.Itoa(port)),
registryCACertFile != "",
registryCACertFile,
)
Expect(err).NotTo(HaveOccurred())

helpers.ValidateImageIsAvailable(
GinkgoT(),
registryHost,
port,
"stefanprodan/podinfo",
"6.2.0",
[]*v1.Platform{{
OS: "linux",
Architecture: runtime.GOARCH,
}},
remote.WithTransport(testRoundTripper),
)

Expect(reg.Shutdown(context.Background())).To((Succeed()))

Eventually(done).Should(BeClosed())
},

Entry("Without TLS", "localhost", "", true),

Entry("With TLS", helpers.GetFirstNonLoopbackIP(GinkgoT()).String(), "", true),

Entry("With Insecure TLS", helpers.GetFirstNonLoopbackIP(GinkgoT()).String(), "", true),

Entry(
"With http registry",
helpers.GetFirstNonLoopbackIP(GinkgoT()).String(),
"http",
true,
"",
)
Expect(err).NotTo(HaveOccurred())

helpers.ValidateImageIsAvailable(
GinkgoT(),
ipAddr.String(),
port,
"stefanprodan/podinfo",
"6.2.0",
[]*v1.Platform{{
OS: "linux",
Architecture: runtime.GOARCH,
}},
remote.WithTransport(testRoundTripper),
)
),

Expect(reg.Shutdown(context.Background())).To((Succeed()))

Eventually(done).Should(BeClosed())
})
Entry(
"With http registry without TLS skip verify flag",
helpers.GetFirstNonLoopbackIP(GinkgoT()).String(),
"http",
false,
),
)

It("Bundle does not exist", func() {
cmd.SetArgs([]string{
Expand Down

0 comments on commit 8d023e5

Please sign in to comment.