Skip to content

Commit

Permalink
fix(tests): wait for registry to accept connections before running tests
Browse files Browse the repository at this point in the history
Signed-off-by: alacuku <[email protected]>
  • Loading branch information
alacuku committed Nov 3, 2023
1 parent ae7f565 commit 4762487
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/artifact/config/config_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions cmd/artifact/install/install_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
16 changes: 16 additions & 0 deletions cmd/registry/auth/basic/basic_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions cmd/registry/auth/oauth/oauth_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions cmd/registry/pull/pull_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions cmd/registry/push/push_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions pkg/oci/pusher/pusher_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
})

0 comments on commit 4762487

Please sign in to comment.