From 476248736337a23f742bf8a3969d9cccd12d4253 Mon Sep 17 00:00:00 2001 From: alacuku Date: Thu, 2 Nov 2023 15:20:07 +0100 Subject: [PATCH] fix(tests): wait for registry to accept connections before running tests Signed-off-by: alacuku --- cmd/artifact/config/config_suite_test.go | 10 ++++++++++ cmd/artifact/install/install_suite_test.go | 10 ++++++++++ cmd/registry/auth/basic/basic_suite_test.go | 16 ++++++++++++++++ cmd/registry/auth/oauth/oauth_suite_test.go | 10 ++++++++++ cmd/registry/pull/pull_suite_test.go | 10 ++++++++++ cmd/registry/push/push_suite_test.go | 10 ++++++++++ pkg/oci/pusher/pusher_suite_test.go | 10 ++++++++++ 7 files changed, 76 insertions(+) diff --git a/cmd/artifact/config/config_suite_test.go b/cmd/artifact/config/config_suite_test.go index ae57d27d..95d90774 100644 --- a/cmd/artifact/config/config_suite_test.go +++ b/cmd/artifact/config/config_suite_test.go @@ -18,7 +18,9 @@ package config_test import ( "context" "fmt" + "net/http" "testing" + "time" "github.com/distribution/distribution/v3/configuration" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" @@ -79,6 +81,14 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(BeNil()) }() + // Check that the registry is up and accepting connections. + Eventually(func(g Gomega) error { + res, err := http.Get(fmt.Sprintf("http://%s", config.HTTP.Addr)) + g.Expect(err).ShouldNot(HaveOccurred()) + g.Expect(res.StatusCode).Should(Equal(http.StatusOK)) + return err + }).WithTimeout(time.Second * 5).ShouldNot(HaveOccurred()) + // Initialize options for command. opt = commonoptions.NewOptions() opt.Initialize(commonoptions.WithWriter(output)) diff --git a/cmd/artifact/install/install_suite_test.go b/cmd/artifact/install/install_suite_test.go index f1ba2dbf..bad5877b 100644 --- a/cmd/artifact/install/install_suite_test.go +++ b/cmd/artifact/install/install_suite_test.go @@ -18,9 +18,11 @@ package install_test import ( "context" "fmt" + "net/http" "os" "path/filepath" "testing" + "time" "github.com/distribution/distribution/v3/configuration" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" @@ -82,6 +84,14 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(BeNil()) }() + // Check that the registry is up and accepting connections. + Eventually(func(g Gomega) error { + res, err := http.Get(fmt.Sprintf("http://%s", config.HTTP.Addr)) + g.Expect(err).ShouldNot(HaveOccurred()) + g.Expect(res.StatusCode).Should(Equal(http.StatusOK)) + return err + }).WithTimeout(time.Second * 5).ShouldNot(HaveOccurred()) + // Create temporary directory used to save the configuration file. configFile, err = testutils.CreateEmptyFile("falcoctl.yaml") Expect(err).Should(Succeed()) diff --git a/cmd/registry/auth/basic/basic_suite_test.go b/cmd/registry/auth/basic/basic_suite_test.go index 8d0dadec..58b7fb82 100644 --- a/cmd/registry/auth/basic/basic_suite_test.go +++ b/cmd/registry/auth/basic/basic_suite_test.go @@ -109,12 +109,28 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(BeNil()) }() + // Check that the registry is up and accepting connections. + Eventually(func(g Gomega) error { + res, err := http.Get(fmt.Sprintf("http://%s", config.HTTP.Addr)) + g.Expect(err).ShouldNot(HaveOccurred()) + g.Expect(res.StatusCode).Should(Equal(http.StatusOK)) + return err + }).WithTimeout(time.Second * 5).ShouldNot(HaveOccurred()) + // Start the local registry with basic authentication. go func() { err := testutils.StartRegistry(context.Background(), configBasic) Expect(err).ToNot(BeNil()) }() + // Check that the registry is up and accepting connections. + Eventually(func(g Gomega) error { + res, err := http.Get(fmt.Sprintf("https://%s", configBasic.HTTP.Addr)) + g.Expect(err).ShouldNot(HaveOccurred()) + g.Expect(res.StatusCode).Should(Equal(http.StatusOK)) + return err + }).WithTimeout(time.Second * 5).ShouldNot(HaveOccurred()) + // Create temporary directory used to save the configuration file. configFile, err = testutils.CreateEmptyFile("falcoctl.yaml") Expect(err).Should(Succeed()) diff --git a/cmd/registry/auth/oauth/oauth_suite_test.go b/cmd/registry/auth/oauth/oauth_suite_test.go index e7977654..abc99de2 100644 --- a/cmd/registry/auth/oauth/oauth_suite_test.go +++ b/cmd/registry/auth/oauth/oauth_suite_test.go @@ -18,10 +18,12 @@ package oauth_test import ( "context" "fmt" + "net/http" "os" "os/user" "path/filepath" "testing" + "time" "github.com/distribution/distribution/v3/configuration" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" @@ -95,6 +97,14 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(BeNil()) }() + // Check that the registry is up and accepting connections. + Eventually(func(g Gomega) error { + res, err := http.Get(fmt.Sprintf("http://%s", config.HTTP.Addr)) + g.Expect(err).ShouldNot(HaveOccurred()) + g.Expect(res.StatusCode).Should(Equal(http.StatusOK)) + return err + }).WithTimeout(time.Second * 5).ShouldNot(HaveOccurred()) + go func() { err := testutils.StartOAuthServer(context.Background(), oauthPort) Expect(err).ToNot(BeNil()) diff --git a/cmd/registry/pull/pull_suite_test.go b/cmd/registry/pull/pull_suite_test.go index d057e488..2b846fd8 100644 --- a/cmd/registry/pull/pull_suite_test.go +++ b/cmd/registry/pull/pull_suite_test.go @@ -18,9 +18,11 @@ package pull_test import ( "context" "fmt" + "net/http" "os" "path/filepath" "testing" + "time" "github.com/distribution/distribution/v3/configuration" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" @@ -81,6 +83,14 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(BeNil()) }() + // Check that the registry is up and accepting connections. + Eventually(func(g Gomega) error { + res, err := http.Get(fmt.Sprintf("http://%s", config.HTTP.Addr)) + g.Expect(err).ShouldNot(HaveOccurred()) + g.Expect(res.StatusCode).Should(Equal(http.StatusOK)) + return err + }).WithTimeout(time.Second * 5).ShouldNot(HaveOccurred()) + // Create temporary directory used to save the configuration file. configFile, err = testutils.CreateEmptyFile("falcoctl.yaml") Expect(err).Should(Succeed()) diff --git a/cmd/registry/push/push_suite_test.go b/cmd/registry/push/push_suite_test.go index 761973b7..71ac47e0 100644 --- a/cmd/registry/push/push_suite_test.go +++ b/cmd/registry/push/push_suite_test.go @@ -18,9 +18,11 @@ package push_test import ( "context" "fmt" + "net/http" "os" "path/filepath" "testing" + "time" "github.com/distribution/distribution/v3/configuration" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" @@ -82,6 +84,14 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(BeNil()) }() + // Check that the registry is up and accepting connections. + Eventually(func(g Gomega) error { + res, err := http.Get(fmt.Sprintf("http://%s", config.HTTP.Addr)) + g.Expect(err).ShouldNot(HaveOccurred()) + g.Expect(res.StatusCode).Should(Equal(http.StatusOK)) + return err + }).WithTimeout(time.Second * 5).ShouldNot(HaveOccurred()) + // Create temporary directory used to save the configuration file. configFile, err = testutils.CreateEmptyFile("falcoctl.yaml") Expect(err).Should(Succeed()) diff --git a/pkg/oci/pusher/pusher_suite_test.go b/pkg/oci/pusher/pusher_suite_test.go index 559886f8..0c98863d 100644 --- a/pkg/oci/pusher/pusher_suite_test.go +++ b/pkg/oci/pusher/pusher_suite_test.go @@ -18,7 +18,9 @@ package pusher_test import ( "context" "fmt" + "net/http" "testing" + "time" "github.com/distribution/distribution/v3/configuration" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" @@ -62,4 +64,12 @@ var _ = BeforeSuite(func() { err := testutils.StartRegistry(context.Background(), config) Expect(err).ToNot(BeNil()) }() + + // Check that the registry is up and accepting connections. + Eventually(func(g Gomega) error { + res, err := http.Get(fmt.Sprintf("http://%s", config.HTTP.Addr)) + g.Expect(err).ShouldNot(HaveOccurred()) + g.Expect(res.StatusCode).Should(Equal(http.StatusOK)) + return err + }).WithTimeout(time.Second * 5).ShouldNot(HaveOccurred()) })