@@ -69,6 +69,56 @@ func TestApp_Create(t *testing.T) {
6969 },
7070 wantStdout : "monalisa-dotfiles-abcd1234\n " ,
7171 },
72+ {
73+ name : "create codespace that requires accepting additional permissions" ,
74+ fields : fields {
75+ apiClient : & apiClientMock {
76+ GetCodespaceRegionLocationFunc : func (ctx context.Context ) (string , error ) {
77+ return "EUROPE" , nil
78+ },
79+ GetRepositoryFunc : func (ctx context.Context , nwo string ) (* api.Repository , error ) {
80+ return & api.Repository {
81+ ID : 1234 ,
82+ FullName : nwo ,
83+ DefaultBranch : "main" ,
84+ }, nil
85+ },
86+ GetCodespacesMachinesFunc : func (ctx context.Context , repoID int , branch , location string ) ([]* api.Machine , error ) {
87+ return []* api.Machine {
88+ {
89+ Name : "GIGA" ,
90+ DisplayName : "Gigabits of a machine" ,
91+ },
92+ }, nil
93+ },
94+ CreateCodespaceFunc : func (ctx context.Context , params * api.CreateCodespaceParams ) (* api.Codespace , error ) {
95+ if params .Branch != "main" {
96+ return nil , fmt .Errorf ("got branch %q, want %q" , params .Branch , "main" )
97+ }
98+ if params .IdleTimeoutMinutes != 30 {
99+ return nil , fmt .Errorf ("idle timeout minutes was %v" , params .IdleTimeoutMinutes )
100+ }
101+ return & api.Codespace {}, api.AcceptPermissionsRequiredError {
102+ AllowPermissionsURL : "https://example.com/permissions" ,
103+ }
104+ },
105+ GetCodespaceRepoSuggestionsFunc : func (ctx context.Context , partialSearch string , params api.RepoSearchParameters ) ([]string , error ) {
106+ return nil , nil // We can't ask for suggestions without a terminal.
107+ },
108+ },
109+ },
110+ opts : createOptions {
111+ repo : "monalisa/dotfiles" ,
112+ branch : "" ,
113+ machine : "GIGA" ,
114+ showStatus : false ,
115+ idleTimeout : 30 * time .Minute ,
116+ },
117+ wantStdout : `You must accept or deny additional permissions requested by the repository before you can create a codespace.
118+ Open this URL to continue in your web browser to accept: example.com/permissions
119+ Alternatively, you can run "create" with the "--skip-permissions" option to create the codespace without these additional permissions.
120+ ` ,
121+ },
72122 }
73123 for _ , tt := range tests {
74124 t .Run (tt .name , func (t * testing.T ) {
0 commit comments