Add create test
This commit is contained in:
parent
e7c2f973ae
commit
1ea26f33d8
1 changed files with 50 additions and 0 deletions
|
|
@ -69,6 +69,56 @@ func TestApp_Create(t *testing.T) {
|
|||
},
|
||||
wantStdout: "monalisa-dotfiles-abcd1234\n",
|
||||
},
|
||||
{
|
||||
name: "create codespace that requires accepting additional permissions",
|
||||
fields: fields{
|
||||
apiClient: &apiClientMock{
|
||||
GetCodespaceRegionLocationFunc: func(ctx context.Context) (string, error) {
|
||||
return "EUROPE", nil
|
||||
},
|
||||
GetRepositoryFunc: func(ctx context.Context, nwo string) (*api.Repository, error) {
|
||||
return &api.Repository{
|
||||
ID: 1234,
|
||||
FullName: nwo,
|
||||
DefaultBranch: "main",
|
||||
}, nil
|
||||
},
|
||||
GetCodespacesMachinesFunc: func(ctx context.Context, repoID int, branch, location string) ([]*api.Machine, error) {
|
||||
return []*api.Machine{
|
||||
{
|
||||
Name: "GIGA",
|
||||
DisplayName: "Gigabits of a machine",
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
CreateCodespaceFunc: func(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error) {
|
||||
if params.Branch != "main" {
|
||||
return nil, fmt.Errorf("got branch %q, want %q", params.Branch, "main")
|
||||
}
|
||||
if params.IdleTimeoutMinutes != 30 {
|
||||
return nil, fmt.Errorf("idle timeout minutes was %v", params.IdleTimeoutMinutes)
|
||||
}
|
||||
return &api.Codespace{}, api.AcceptPermissionsRequiredError{
|
||||
AllowPermissionsURL: "https://example.com/permissions",
|
||||
}
|
||||
},
|
||||
GetCodespaceRepoSuggestionsFunc: func(ctx context.Context, partialSearch string, params api.RepoSearchParameters) ([]string, error) {
|
||||
return nil, nil // We can't ask for suggestions without a terminal.
|
||||
},
|
||||
},
|
||||
},
|
||||
opts: createOptions{
|
||||
repo: "monalisa/dotfiles",
|
||||
branch: "",
|
||||
machine: "GIGA",
|
||||
showStatus: false,
|
||||
idleTimeout: 30 * time.Minute,
|
||||
},
|
||||
wantStdout: `You must accept or deny additional permissions requested by the repository before you can create a codespace.
|
||||
Open this URL to continue in your web browser to accept: example.com/permissions
|
||||
Alternatively, you can run "create" with the "--skip-permissions" option to create the codespace without these additional permissions.
|
||||
`,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue