cli/pkg/cmd/codespace/logs_test.go
Caleb Brose 57c73e8239
Add --repo filter to more gh codespaces commands (#6669)
* Add --repo flag to commands

* Example of using common args

* Add -r to stop

* Add validation to the add helper

* Skip prompt for single option

* Migrate (mostly) everything to addGetOrChooseCodespaceCommandArgs

* Fix typo in logsCmd

* Use R instead of r

* Update a couple -r usages

* Refactor to codespace_selector

* Clean up selector, apply it in a couple examples

* Use apiClient instead in constructor

* Restore addDeprecatedRepoShorthand

* Finish implementing the commands

* Update existing tests to use the selector

* Add tests for selector

* linter

* Catch case where there's no conflict

* Make the flag persistent for ports

* Add support to stop
2023-02-22 17:16:36 -06:00

41 lines
1.1 KiB
Go

package codespace
import (
"context"
"testing"
"github.com/cli/cli/v2/internal/codespaces/api"
"github.com/cli/cli/v2/pkg/iostreams"
)
func TestPendingOperationDisallowsLogs(t *testing.T) {
app := testingLogsApp()
selector := &CodespaceSelector{api: app.apiClient, codespaceName: "disabledCodespace"}
if err := app.Logs(context.Background(), selector, false); err != nil {
if err.Error() != "codespace is disabled while it has a pending operation: Some pending operation" {
t.Errorf("expected pending operation error, but got: %v", err)
}
} else {
t.Error("expected pending operation error, but got nothing")
}
}
func testingLogsApp() *App {
disabledCodespace := &api.Codespace{
Name: "disabledCodespace",
PendingOperation: true,
PendingOperationDisabledReason: "Some pending operation",
}
apiMock := &apiClientMock{
GetCodespaceFunc: func(_ context.Context, name string, _ bool) (*api.Codespace, error) {
if name == "disabledCodespace" {
return disabledCodespace, nil
}
return nil, nil
},
}
ios, _, _, _ := iostreams.Test()
return NewApp(ios, nil, apiMock, nil, nil)
}