diff options
Diffstat (limited to 'internal/command/healthcheck')
-rw-r--r-- | internal/command/healthcheck/healthcheck.go | 9 | ||||
-rw-r--r-- | internal/command/healthcheck/healthcheck_test.go | 7 |
2 files changed, 9 insertions, 7 deletions
diff --git a/internal/command/healthcheck/healthcheck.go b/internal/command/healthcheck/healthcheck.go index bbc73dc..b04eb0d 100644 --- a/internal/command/healthcheck/healthcheck.go +++ b/internal/command/healthcheck/healthcheck.go @@ -1,6 +1,7 @@ package healthcheck import ( + "context" "fmt" "gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter" @@ -18,8 +19,8 @@ type Command struct { ReadWriter *readwriter.ReadWriter } -func (c *Command) Execute() error { - response, err := c.runCheck() +func (c *Command) Execute(ctx context.Context) error { + response, err := c.runCheck(ctx) if err != nil { return fmt.Errorf("%v: FAILED - %v", apiMessage, err) } @@ -34,13 +35,13 @@ func (c *Command) Execute() error { return nil } -func (c *Command) runCheck() (*healthcheck.Response, error) { +func (c *Command) runCheck(ctx context.Context) (*healthcheck.Response, error) { client, err := healthcheck.NewClient(c.Config) if err != nil { return nil, err } - response, err := client.Check() + response, err := client.Check(ctx) if err != nil { return nil, err } diff --git a/internal/command/healthcheck/healthcheck_test.go b/internal/command/healthcheck/healthcheck_test.go index 7479bcb..d05e563 100644 --- a/internal/command/healthcheck/healthcheck_test.go +++ b/internal/command/healthcheck/healthcheck_test.go @@ -2,6 +2,7 @@ package healthcheck import ( "bytes" + "context" "encoding/json" "net/http" "testing" @@ -53,7 +54,7 @@ func TestExecute(t *testing.T) { ReadWriter: &readwriter.ReadWriter{Out: buffer}, } - err := cmd.Execute() + err := cmd.Execute(context.Background()) require.NoError(t, err) require.Equal(t, "Internal API available: OK\nRedis available via internal API: OK\n", buffer.String()) @@ -69,7 +70,7 @@ func TestFailingRedisExecute(t *testing.T) { ReadWriter: &readwriter.ReadWriter{Out: buffer}, } - err := cmd.Execute() + err := cmd.Execute(context.Background()) require.Error(t, err, "Redis available via internal API: FAILED") require.Equal(t, "Internal API available: OK\n", buffer.String()) } @@ -84,7 +85,7 @@ func TestFailingAPIExecute(t *testing.T) { ReadWriter: &readwriter.ReadWriter{Out: buffer}, } - err := cmd.Execute() + err := cmd.Execute(context.Background()) require.Empty(t, buffer.String()) require.EqualError(t, err, "Internal API available: FAILED - Internal API error (500)") } |