Skip to content

Commit

Permalink
Simplify IsReady function
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-Kalpakchiev committed Nov 8, 2024
1 parent 814aa97 commit 32f0a81
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/backend/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ func (m *Manager) GetClient(namespace string) (Client, error) {
return nil, ErrNamespaceNotFound
}

// IsReady returns whether the backends are ready (reachable).
// CheckReadiness returns whether the backends are ready (by trying to download a file).
// A backend must be explicitly configured as required for readiness to be checked.
func (m *Manager) IsReady() (bool, error) {
func (m *Manager) CheckReadiness() error {
for _, backend := range m.backends {
if !backend.mustReady {
continue
}
err := backend.client.Download(ReadinessNamespace, ReadinessName, bytes.NewBuffer([]byte{}))
if err != nil {
return false, fmt.Errorf("backend for namespace %s not ready: %s", backend.regexp.String(), err)
return fmt.Errorf("backend for namespace %s not ready: %s", backend.regexp.String(), err)
}
}
return true, nil
return nil
}
7 changes: 1 addition & 6 deletions lib/backend/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func TestManagerIsReady(t *testing.T) {
mustReady2 bool
mockDownload1Err error
mockDownload2Err error
expectedRes bool
expectedErr error
}{
{
Expand All @@ -178,7 +177,6 @@ func TestManagerIsReady(t *testing.T) {
mustReady2: true,
mockDownload1Err: nil,
mockDownload2Err: nil,
expectedRes: true,
expectedErr: nil,
},
{
Expand All @@ -187,7 +185,6 @@ func TestManagerIsReady(t *testing.T) {
mustReady2: true,
mockDownload1Err: nil,
mockDownload2Err: errors.New("network error"),
expectedRes: false,
expectedErr: errors.New("backend for namespace bar/* not ready: network error"),
},
{
Expand All @@ -196,7 +193,6 @@ func TestManagerIsReady(t *testing.T) {
mustReady2: true,
mockDownload1Err: backenderrors.ErrBlobNotFound,
mockDownload2Err: nil,
expectedRes: true,
expectedErr: nil,
},
}
Expand All @@ -218,8 +214,7 @@ func TestManagerIsReady(t *testing.T) {
require.NoError(m.Register(n1, c1, tc.mustReady1))
require.NoError(m.Register(n2, c2, tc.mustReady2))

res, err := m.IsReady()
require.Equal(tc.expectedRes, res)
err := m.CheckReadiness()
if tc.expectedErr == nil {
require.NoError(err)
} else {
Expand Down

0 comments on commit 32f0a81

Please sign in to comment.