Skip to content

Commit a4cd32d

Browse files
committed
use sentinel error
1 parent cd32acb commit a4cd32d

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

cmd/src/main_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"io"
78
"net/url"
89
"os"
@@ -437,8 +438,8 @@ func TestConfigAPIClientCIAccessTokenGate(t *testing.T) {
437438
client := (&config{endpointURL: endpointURL, inCI: true}).apiClient(nil, io.Discard)
438439

439440
_, err := client.NewHTTPRequest(context.Background(), "GET", ".api/src-cli/version", nil)
440-
if err == nil || err.Error() != errCIAccessTokenRequired.Error() {
441-
t.Fatalf("NewHTTPRequest() error = %v, want %q", err, errCIAccessTokenRequired)
441+
if !errors.Is(err, api.ErrCIAccessTokenRequired) {
442+
t.Fatalf("NewHTTPRequest() error = %v, want %v", err, api.ErrCIAccessTokenRequired)
442443
}
443444
})
444445

internal/api/api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ type ClientOpts struct {
9191
OAuthToken *oauth.Token
9292
}
9393

94+
// ErrCIAccessTokenRequired indicates SRC_ACCESS_TOKEN must be set when CI=true.
95+
var ErrCIAccessTokenRequired = errors.New("SRC_ACCESS_TOKEN must be set when CI=true")
96+
9497
func buildTransport(opts ClientOpts, flags *Flags) http.RoundTripper {
9598
var transport http.RoundTripper
9699
{
@@ -153,7 +156,7 @@ func NewClient(opts ClientOpts) Client {
153156

154157
func (c *client) checkIfCIAccessTokenRequired() error {
155158
if c.opts.RequireAccessTokenInCI && c.opts.AccessToken == "" {
156-
return errors.New("SRC_ACCESS_TOKEN must be set when CI=true")
159+
return ErrCIAccessTokenRequired
157160
}
158161

159162
return nil

0 commit comments

Comments
 (0)