Commit 592823d5 authored by Patrick Bajao's avatar Patrick Bajao

Rename CommandArgs to Shell

Other functions are still expecting for `CommandArgs` instead
of `Shell`. They should be expecting `commandargs.Shell` now
since it has been renamed.
parent 3b0176df
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
type Command struct { type Command struct {
Config *config.Config Config *config.Config
Args *commandargs.CommandArgs Args *commandargs.Shell
ReadWriter *readwriter.ReadWriter ReadWriter *readwriter.ReadWriter
} }
......
...@@ -49,27 +49,27 @@ func TestExecute(t *testing.T) { ...@@ -49,27 +49,27 @@ func TestExecute(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
arguments *commandargs.CommandArgs arguments *commandargs.Shell
expectedOutput string expectedOutput string
}{ }{
{ {
desc: "With a known username", desc: "With a known username",
arguments: &commandargs.CommandArgs{GitlabUsername: "alex-doe"}, arguments: &commandargs.Shell{GitlabUsername: "alex-doe"},
expectedOutput: "Welcome to GitLab, @alex-doe!\n", expectedOutput: "Welcome to GitLab, @alex-doe!\n",
}, },
{ {
desc: "With a known key id", desc: "With a known key id",
arguments: &commandargs.CommandArgs{GitlabKeyId: "1"}, arguments: &commandargs.Shell{GitlabKeyId: "1"},
expectedOutput: "Welcome to GitLab, @alex-doe!\n", expectedOutput: "Welcome to GitLab, @alex-doe!\n",
}, },
{ {
desc: "With an unknown key", desc: "With an unknown key",
arguments: &commandargs.CommandArgs{GitlabKeyId: "-1"}, arguments: &commandargs.Shell{GitlabKeyId: "-1"},
expectedOutput: "Welcome to GitLab, Anonymous!\n", expectedOutput: "Welcome to GitLab, Anonymous!\n",
}, },
{ {
desc: "With an unknown username", desc: "With an unknown username",
arguments: &commandargs.CommandArgs{GitlabUsername: "unknown"}, arguments: &commandargs.Shell{GitlabUsername: "unknown"},
expectedOutput: "Welcome to GitLab, Anonymous!\n", expectedOutput: "Welcome to GitLab, Anonymous!\n",
}, },
} }
...@@ -97,22 +97,22 @@ func TestFailingExecute(t *testing.T) { ...@@ -97,22 +97,22 @@ func TestFailingExecute(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
arguments *commandargs.CommandArgs arguments *commandargs.Shell
expectedError string expectedError string
}{ }{
{ {
desc: "With missing arguments", desc: "With missing arguments",
arguments: &commandargs.CommandArgs{}, arguments: &commandargs.Shell{},
expectedError: "Failed to get username: who='' is invalid", expectedError: "Failed to get username: who='' is invalid",
}, },
{ {
desc: "When the API returns an error", desc: "When the API returns an error",
arguments: &commandargs.CommandArgs{GitlabUsername: "broken_message"}, arguments: &commandargs.Shell{GitlabUsername: "broken_message"},
expectedError: "Failed to get username: Forbidden!", expectedError: "Failed to get username: Forbidden!",
}, },
{ {
desc: "When the API fails", desc: "When the API fails",
arguments: &commandargs.CommandArgs{GitlabUsername: "broken"}, arguments: &commandargs.Shell{GitlabUsername: "broken"},
expectedError: "Failed to get username: Internal API error (500)", expectedError: "Failed to get username: Internal API error (500)",
}, },
} }
......
...@@ -20,7 +20,7 @@ const ( ...@@ -20,7 +20,7 @@ const (
type Command struct { type Command struct {
Config *config.Config Config *config.Config
Args *commandargs.CommandArgs Args *commandargs.Shell
ReadWriter *readwriter.ReadWriter ReadWriter *readwriter.ReadWriter
} }
......
...@@ -25,22 +25,22 @@ func TestFailedRequests(t *testing.T) { ...@@ -25,22 +25,22 @@ func TestFailedRequests(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
arguments *commandargs.CommandArgs arguments *commandargs.Shell
expectedOutput string expectedOutput string
}{ }{
{ {
desc: "With missing arguments", desc: "With missing arguments",
arguments: &commandargs.CommandArgs{}, arguments: &commandargs.Shell{},
expectedOutput: "> GitLab: Disallowed command", expectedOutput: "> GitLab: Disallowed command",
}, },
{ {
desc: "With disallowed command", desc: "With disallowed command",
arguments: &commandargs.CommandArgs{GitlabKeyId: "1", SshArgs: []string{"git-lfs-authenticate", "group/repo", "unknown"}}, arguments: &commandargs.Shell{GitlabKeyId: "1", SshArgs: []string{"git-lfs-authenticate", "group/repo", "unknown"}},
expectedOutput: "> GitLab: Disallowed command", expectedOutput: "> GitLab: Disallowed command",
}, },
{ {
desc: "With disallowed user", desc: "With disallowed user",
arguments: &commandargs.CommandArgs{GitlabKeyId: "disallowed", SshArgs: []string{"git-lfs-authenticate", "group/repo", "download"}}, arguments: &commandargs.Shell{GitlabKeyId: "disallowed", SshArgs: []string{"git-lfs-authenticate", "group/repo", "download"}},
expectedOutput: "Disallowed by API call", expectedOutput: "Disallowed by API call",
}, },
} }
...@@ -140,7 +140,7 @@ func TestLfsAuthenticateRequests(t *testing.T) { ...@@ -140,7 +140,7 @@ func TestLfsAuthenticateRequests(t *testing.T) {
output := &bytes.Buffer{} output := &bytes.Buffer{}
cmd := &Command{ cmd := &Command{
Config: &config.Config{GitlabUrl: url}, Config: &config.Config{GitlabUrl: url},
Args: &commandargs.CommandArgs{GitlabUsername: tc.username, SshArgs: []string{"git-lfs-authenticate", "group/repo", "upload"}}, Args: &commandargs.Shell{GitlabUsername: tc.username, SshArgs: []string{"git-lfs-authenticate", "group/repo", "upload"}},
ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output}, ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output},
} }
......
...@@ -92,7 +92,7 @@ func TestCustomReceivePack(t *testing.T) { ...@@ -92,7 +92,7 @@ func TestCustomReceivePack(t *testing.T) {
cmd := &Command{ cmd := &Command{
Config: &config.Config{GitlabUrl: url}, Config: &config.Config{GitlabUrl: url},
Args: &commandargs.CommandArgs{GitlabKeyId: keyId, CommandType: commandargs.ReceivePack, SshArgs: []string{"git-receive-pack", repo}}, Args: &commandargs.Shell{GitlabKeyId: keyId, CommandType: commandargs.ReceivePack, SshArgs: []string{"git-receive-pack", repo}},
ReadWriter: &readwriter.ReadWriter{ErrOut: errBuf, Out: outBuf, In: input}, ReadWriter: &readwriter.ReadWriter{ErrOut: errBuf, Out: outBuf, In: input},
} }
......
...@@ -29,7 +29,7 @@ func TestReceivePack(t *testing.T) { ...@@ -29,7 +29,7 @@ func TestReceivePack(t *testing.T) {
cmd := &Command{ cmd := &Command{
Config: &config.Config{GitlabUrl: url}, Config: &config.Config{GitlabUrl: url},
Args: &commandargs.CommandArgs{GitlabKeyId: userId, CommandType: commandargs.ReceivePack, SshArgs: []string{"git-receive-pack", repo}}, Args: &commandargs.Shell{GitlabKeyId: userId, CommandType: commandargs.ReceivePack, SshArgs: []string{"git-receive-pack", repo}},
ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input}, ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input},
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
type Command struct { type Command struct {
Config *config.Config Config *config.Config
Args *commandargs.CommandArgs Args *commandargs.Shell
ReadWriter *readwriter.ReadWriter ReadWriter *readwriter.ReadWriter
} }
......
...@@ -23,7 +23,7 @@ func TestForbiddenAccess(t *testing.T) { ...@@ -23,7 +23,7 @@ func TestForbiddenAccess(t *testing.T) {
cmd := &Command{ cmd := &Command{
Config: &config.Config{GitlabUrl: url}, Config: &config.Config{GitlabUrl: url},
Args: &commandargs.CommandArgs{GitlabKeyId: "disallowed", SshArgs: []string{"git-receive-pack", "group/repo"}}, Args: &commandargs.Shell{GitlabKeyId: "disallowed", SshArgs: []string{"git-receive-pack", "group/repo"}},
ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input}, ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input},
} }
......
...@@ -14,7 +14,7 @@ type Response = accessverifier.Response ...@@ -14,7 +14,7 @@ type Response = accessverifier.Response
type Command struct { type Command struct {
Config *config.Config Config *config.Config
Args *commandargs.CommandArgs Args *commandargs.Shell
ReadWriter *readwriter.ReadWriter ReadWriter *readwriter.ReadWriter
} }
......
...@@ -64,7 +64,7 @@ func TestMissingUser(t *testing.T) { ...@@ -64,7 +64,7 @@ func TestMissingUser(t *testing.T) {
cmd, _, _, cleanup := setup(t) cmd, _, _, cleanup := setup(t)
defer cleanup() defer cleanup()
cmd.Args = &commandargs.CommandArgs{GitlabKeyId: "2"} cmd.Args = &commandargs.Shell{GitlabKeyId: "2"}
_, err := cmd.Verify(action, repo) _, err := cmd.Verify(action, repo)
require.Equal(t, "missing user", err.Error()) require.Equal(t, "missing user", err.Error())
...@@ -74,7 +74,7 @@ func TestConsoleMessages(t *testing.T) { ...@@ -74,7 +74,7 @@ func TestConsoleMessages(t *testing.T) {
cmd, errBuf, outBuf, cleanup := setup(t) cmd, errBuf, outBuf, cleanup := setup(t)
defer cleanup() defer cleanup()
cmd.Args = &commandargs.CommandArgs{GitlabKeyId: "1"} cmd.Args = &commandargs.Shell{GitlabKeyId: "1"}
cmd.Verify(action, repo) cmd.Verify(action, repo)
require.Equal(t, "> GitLab: console\n> GitLab: message\n", errBuf.String()) require.Equal(t, "> GitLab: console\n> GitLab: message\n", errBuf.String())
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
type Command struct { type Command struct {
Config *config.Config Config *config.Config
Args *commandargs.CommandArgs Args *commandargs.Shell
ReadWriter *readwriter.ReadWriter ReadWriter *readwriter.ReadWriter
} }
......
...@@ -69,13 +69,13 @@ func TestExecute(t *testing.T) { ...@@ -69,13 +69,13 @@ func TestExecute(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
arguments *commandargs.CommandArgs arguments *commandargs.Shell
answer string answer string
expectedOutput string expectedOutput string
}{ }{
{ {
desc: "With a known key id", desc: "With a known key id",
arguments: &commandargs.CommandArgs{GitlabKeyId: "1"}, arguments: &commandargs.Shell{GitlabKeyId: "1"},
answer: "yes\n", answer: "yes\n",
expectedOutput: question + expectedOutput: question +
"Your two-factor authentication recovery codes are:\n\nrecovery\ncodes\n\n" + "Your two-factor authentication recovery codes are:\n\nrecovery\ncodes\n\n" +
...@@ -85,31 +85,31 @@ func TestExecute(t *testing.T) { ...@@ -85,31 +85,31 @@ func TestExecute(t *testing.T) {
}, },
{ {
desc: "With bad response", desc: "With bad response",
arguments: &commandargs.CommandArgs{GitlabKeyId: "-1"}, arguments: &commandargs.Shell{GitlabKeyId: "-1"},
answer: "yes\n", answer: "yes\n",
expectedOutput: question + errorHeader + "Parsing failed\n", expectedOutput: question + errorHeader + "Parsing failed\n",
}, },
{ {
desc: "With API returns an error", desc: "With API returns an error",
arguments: &commandargs.CommandArgs{GitlabKeyId: "forbidden"}, arguments: &commandargs.Shell{GitlabKeyId: "forbidden"},
answer: "yes\n", answer: "yes\n",
expectedOutput: question + errorHeader + "Forbidden!\n", expectedOutput: question + errorHeader + "Forbidden!\n",
}, },
{ {
desc: "With API fails", desc: "With API fails",
arguments: &commandargs.CommandArgs{GitlabKeyId: "broken"}, arguments: &commandargs.Shell{GitlabKeyId: "broken"},
answer: "yes\n", answer: "yes\n",
expectedOutput: question + errorHeader + "Internal API error (500)\n", expectedOutput: question + errorHeader + "Internal API error (500)\n",
}, },
{ {
desc: "With missing arguments", desc: "With missing arguments",
arguments: &commandargs.CommandArgs{}, arguments: &commandargs.Shell{},
answer: "yes\n", answer: "yes\n",
expectedOutput: question + errorHeader + "who='' is invalid\n", expectedOutput: question + errorHeader + "who='' is invalid\n",
}, },
{ {
desc: "With negative answer", desc: "With negative answer",
arguments: &commandargs.CommandArgs{}, arguments: &commandargs.Shell{},
answer: "no\n", answer: "no\n",
expectedOutput: question + expectedOutput: question +
"New recovery codes have *not* been generated. Existing codes will remain valid.\n", "New recovery codes have *not* been generated. Existing codes will remain valid.\n",
......
...@@ -29,7 +29,7 @@ func TestUploadPack(t *testing.T) { ...@@ -29,7 +29,7 @@ func TestUploadPack(t *testing.T) {
cmd := &Command{ cmd := &Command{
Config: &config.Config{GitlabUrl: url}, Config: &config.Config{GitlabUrl: url},
Args: &commandargs.CommandArgs{GitlabKeyId: userId, CommandType: commandargs.UploadArchive, SshArgs: []string{"git-upload-archive", repo}}, Args: &commandargs.Shell{GitlabKeyId: userId, CommandType: commandargs.UploadArchive, SshArgs: []string{"git-upload-archive", repo}},
ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input}, ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input},
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
type Command struct { type Command struct {
Config *config.Config Config *config.Config
Args *commandargs.CommandArgs Args *commandargs.Shell
ReadWriter *readwriter.ReadWriter ReadWriter *readwriter.ReadWriter
} }
......
...@@ -22,7 +22,7 @@ func TestForbiddenAccess(t *testing.T) { ...@@ -22,7 +22,7 @@ func TestForbiddenAccess(t *testing.T) {
cmd := &Command{ cmd := &Command{
Config: &config.Config{GitlabUrl: url}, Config: &config.Config{GitlabUrl: url},
Args: &commandargs.CommandArgs{GitlabKeyId: "disallowed", SshArgs: []string{"git-upload-archive", "group/repo"}}, Args: &commandargs.Shell{GitlabKeyId: "disallowed", SshArgs: []string{"git-upload-archive", "group/repo"}},
ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output}, ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output},
} }
......
...@@ -29,7 +29,7 @@ func TestUploadPack(t *testing.T) { ...@@ -29,7 +29,7 @@ func TestUploadPack(t *testing.T) {
cmd := &Command{ cmd := &Command{
Config: &config.Config{GitlabUrl: url}, Config: &config.Config{GitlabUrl: url},
Args: &commandargs.CommandArgs{GitlabKeyId: userId, CommandType: commandargs.UploadPack, SshArgs: []string{"git-upload-pack", repo}}, Args: &commandargs.Shell{GitlabKeyId: userId, CommandType: commandargs.UploadPack, SshArgs: []string{"git-upload-pack", repo}},
ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input}, ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input},
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
type Command struct { type Command struct {
Config *config.Config Config *config.Config
Args *commandargs.CommandArgs Args *commandargs.Shell
ReadWriter *readwriter.ReadWriter ReadWriter *readwriter.ReadWriter
} }
......
...@@ -22,7 +22,7 @@ func TestForbiddenAccess(t *testing.T) { ...@@ -22,7 +22,7 @@ func TestForbiddenAccess(t *testing.T) {
cmd := &Command{ cmd := &Command{
Config: &config.Config{GitlabUrl: url}, Config: &config.Config{GitlabUrl: url},
Args: &commandargs.CommandArgs{GitlabKeyId: "disallowed", SshArgs: []string{"git-upload-pack", "group/repo"}}, Args: &commandargs.Shell{GitlabKeyId: "disallowed", SshArgs: []string{"git-upload-pack", "group/repo"}},
ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output}, ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output},
} }
......
...@@ -71,7 +71,7 @@ func NewClient(config *config.Config) (*Client, error) { ...@@ -71,7 +71,7 @@ func NewClient(config *config.Config) (*Client, error) {
return &Client{client: client}, nil return &Client{client: client}, nil
} }
func (c *Client) Verify(args *commandargs.CommandArgs, action commandargs.CommandType, repo string) (*Response, error) { func (c *Client) Verify(args *commandargs.Shell, action commandargs.CommandType, repo string) (*Response, error) {
request := &Request{Action: action, Repo: repo, Protocol: protocol, Changes: anyChanges} request := &Request{Action: action, Repo: repo, Protocol: protocol, Changes: anyChanges}
if args.GitlabUsername != "" { if args.GitlabUsername != "" {
...@@ -89,7 +89,7 @@ func (c *Client) Verify(args *commandargs.CommandArgs, action commandargs.Comman ...@@ -89,7 +89,7 @@ func (c *Client) Verify(args *commandargs.CommandArgs, action commandargs.Comman
return parse(response, args) return parse(response, args)
} }
func parse(hr *http.Response, args *commandargs.CommandArgs) (*Response, error) { func parse(hr *http.Response, args *commandargs.Shell) (*Response, error) {
response := &Response{} response := &Response{}
if err := gitlabnet.ParseJSON(hr, response); err != nil { if err := gitlabnet.ParseJSON(hr, response); err != nil {
return nil, err return nil, err
......
...@@ -57,16 +57,16 @@ func TestSuccessfulResponses(t *testing.T) { ...@@ -57,16 +57,16 @@ func TestSuccessfulResponses(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
args *commandargs.CommandArgs args *commandargs.Shell
who string who string
}{ }{
{ {
desc: "Provide key id within the request", desc: "Provide key id within the request",
args: &commandargs.CommandArgs{GitlabKeyId: "1"}, args: &commandargs.Shell{GitlabKeyId: "1"},
who: "key-1", who: "key-1",
}, { }, {
desc: "Provide username within the request", desc: "Provide username within the request",
args: &commandargs.CommandArgs{GitlabUsername: "first"}, args: &commandargs.Shell{GitlabUsername: "first"},
who: "user-1", who: "user-1",
}, },
} }
...@@ -86,7 +86,7 @@ func TestGetCustomAction(t *testing.T) { ...@@ -86,7 +86,7 @@ func TestGetCustomAction(t *testing.T) {
client, cleanup := setup(t) client, cleanup := setup(t)
defer cleanup() defer cleanup()
args := &commandargs.CommandArgs{GitlabUsername: "custom"} args := &commandargs.Shell{GitlabUsername: "custom"}
result, err := client.Verify(args, action, repo) result, err := client.Verify(args, action, repo)
require.NoError(t, err) require.NoError(t, err)
...@@ -134,7 +134,7 @@ func TestErrorResponses(t *testing.T) { ...@@ -134,7 +134,7 @@ func TestErrorResponses(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
args := &commandargs.CommandArgs{GitlabKeyId: tc.fakeId} args := &commandargs.Shell{GitlabKeyId: tc.fakeId}
resp, err := client.Verify(args, action, repo) resp, err := client.Verify(args, action, repo)
require.EqualError(t, err, tc.expectedError) require.EqualError(t, err, tc.expectedError)
......
...@@ -30,7 +30,7 @@ func NewClient(config *config.Config) (*Client, error) { ...@@ -30,7 +30,7 @@ func NewClient(config *config.Config) (*Client, error) {
return &Client{config: config, client: client}, nil return &Client{config: config, client: client}, nil
} }
func (c *Client) GetByCommandArgs(args *commandargs.CommandArgs) (*Response, error) { func (c *Client) GetByCommandArgs(args *commandargs.Shell) (*Response, error) {
params := url.Values{} params := url.Values{}
if args.GitlabUsername != "" { if args.GitlabUsername != "" {
params.Add("username", args.GitlabUsername) params.Add("username", args.GitlabUsername)
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
type Client struct { type Client struct {
config *config.Config config *config.Config
client *gitlabnet.GitlabClient client *gitlabnet.GitlabClient
args *commandargs.CommandArgs args *commandargs.Shell
} }
type Request struct { type Request struct {
...@@ -30,7 +30,7 @@ type Response struct { ...@@ -30,7 +30,7 @@ type Response struct {
ExpiresIn int `json:"expires_in"` ExpiresIn int `json:"expires_in"`
} }
func NewClient(config *config.Config, args *commandargs.CommandArgs) (*Client, error) { func NewClient(config *config.Config, args *commandargs.Shell) (*Client, error) {
client, err := gitlabnet.GetClient(config) client, err := gitlabnet.GetClient(config)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error creating http client: %v", err) return nil, fmt.Errorf("Error creating http client: %v", err)
......
...@@ -59,22 +59,22 @@ func TestFailedRequests(t *testing.T) { ...@@ -59,22 +59,22 @@ func TestFailedRequests(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
args *commandargs.CommandArgs args *commandargs.Shell
expectedOutput string expectedOutput string
}{ }{
{ {
desc: "With bad response", desc: "With bad response",
args: &commandargs.CommandArgs{GitlabKeyId: "-1", CommandType: commandargs.UploadPack}, args: &commandargs.Shell{GitlabKeyId: "-1", CommandType: commandargs.UploadPack},
expectedOutput: "Parsing failed", expectedOutput: "Parsing failed",
}, },
{ {
desc: "With API returns an error", desc: "With API returns an error",
args: &commandargs.CommandArgs{GitlabKeyId: "forbidden", CommandType: commandargs.UploadPack}, args: &commandargs.Shell{GitlabKeyId: "forbidden", CommandType: commandargs.UploadPack},
expectedOutput: "Internal API error (403)", expectedOutput: "Internal API error (403)",
}, },
{ {
desc: "With API fails", desc: "With API fails",
args: &commandargs.CommandArgs{GitlabKeyId: "broken", CommandType: commandargs.UploadPack}, args: &commandargs.Shell{GitlabKeyId: "broken", CommandType: commandargs.UploadPack},
expectedOutput: "Internal API error (500)", expectedOutput: "Internal API error (500)",
}, },
} }
...@@ -99,7 +99,7 @@ func TestSuccessfulRequests(t *testing.T) { ...@@ -99,7 +99,7 @@ func TestSuccessfulRequests(t *testing.T) {
url, cleanup := testserver.StartHttpServer(t, requests) url, cleanup := testserver.StartHttpServer(t, requests)
defer cleanup() defer cleanup()
args := &commandargs.CommandArgs{GitlabKeyId: keyId, CommandType: commandargs.LfsAuthenticate} args := &commandargs.Shell{GitlabKeyId: keyId, CommandType: commandargs.LfsAuthenticate}
client, err := NewClient(&config.Config{GitlabUrl: url}, args) client, err := NewClient(&config.Config{GitlabUrl: url}, args)
require.NoError(t, err) require.NoError(t, err)
......
...@@ -36,7 +36,7 @@ func NewClient(config *config.Config) (*Client, error) { ...@@ -36,7 +36,7 @@ func NewClient(config *config.Config) (*Client, error) {
return &Client{config: config, client: client}, nil return &Client{config: config, client: client}, nil
} }
func (c *Client) GetRecoveryCodes(args *commandargs.CommandArgs) ([]string, error) { func (c *Client) GetRecoveryCodes(args *commandargs.Shell) ([]string, error) {
requestBody, err := c.getRequestBody(args) requestBody, err := c.getRequestBody(args)
if err != nil { if err != nil {
...@@ -65,7 +65,7 @@ func parse(hr *http.Response) ([]string, error) { ...@@ -65,7 +65,7 @@ func parse(hr *http.Response) ([]string, error) {
return response.RecoveryCodes, nil return response.RecoveryCodes, nil
} }
func (c *Client) getRequestBody(args *commandargs.CommandArgs) (*RequestBody, error) { func (c *Client) getRequestBody(args *commandargs.Shell) (*RequestBody, error) {
client, err := discover.NewClient(c.config) client, err := discover.NewClient(c.config)
if err != nil { if err != nil {
......
...@@ -85,7 +85,7 @@ func TestGetRecoveryCodesByKeyId(t *testing.T) { ...@@ -85,7 +85,7 @@ func TestGetRecoveryCodesByKeyId(t *testing.T) {
client, cleanup := setup(t) client, cleanup := setup(t)
defer cleanup() defer cleanup()
args := &commandargs.CommandArgs{GitlabKeyId: "0"} args := &commandargs.Shell{GitlabKeyId: "0"}
result, err := client.GetRecoveryCodes(args) result, err := client.GetRecoveryCodes(args)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, []string{"recovery 1", "codes 1"}, result) assert.Equal(t, []string{"recovery 1", "codes 1"}, result)
...@@ -95,7 +95,7 @@ func TestGetRecoveryCodesByUsername(t *testing.T) { ...@@ -95,7 +95,7 @@ func TestGetRecoveryCodesByUsername(t *testing.T) {
client, cleanup := setup(t) client, cleanup := setup(t)
defer cleanup() defer cleanup()
args := &commandargs.CommandArgs{GitlabUsername: "jane-doe"} args := &commandargs.Shell{GitlabUsername: "jane-doe"}
result, err := client.GetRecoveryCodes(args) result, err := client.GetRecoveryCodes(args)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, []string{"recovery 2", "codes 2"}, result) assert.Equal(t, []string{"recovery 2", "codes 2"}, result)
...@@ -105,7 +105,7 @@ func TestMissingUser(t *testing.T) { ...@@ -105,7 +105,7 @@ func TestMissingUser(t *testing.T) {
client, cleanup := setup(t) client, cleanup := setup(t)
defer cleanup() defer cleanup()
args := &commandargs.CommandArgs{GitlabKeyId: "1"} args := &commandargs.Shell{GitlabKeyId: "1"}
_, err := client.GetRecoveryCodes(args) _, err := client.GetRecoveryCodes(args)
assert.Equal(t, "missing user", err.Error()) assert.Equal(t, "missing user", err.Error())
} }
...@@ -138,7 +138,7 @@ func TestErrorResponses(t *testing.T) { ...@@ -138,7 +138,7 @@ func TestErrorResponses(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
args := &commandargs.CommandArgs{GitlabKeyId: tc.fakeId} args := &commandargs.Shell{GitlabKeyId: tc.fakeId}
resp, err := client.GetRecoveryCodes(args) resp, err := client.GetRecoveryCodes(args)
assert.EqualError(t, err, tc.expectedError) assert.EqualError(t, err, tc.expectedError)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment