|
| 1 | +package codespace |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/cli/cli/v2/internal/codespaces/api" |
| 8 | + "github.com/cli/cli/v2/pkg/iostreams" |
| 9 | +) |
| 10 | + |
| 11 | +func TestPendingOperationDisallowsLogs(t *testing.T) { |
| 12 | + app := testingLogsApp() |
| 13 | + |
| 14 | + if err := app.Logs(context.Background(), "disabledCodespace", false); err != nil { |
| 15 | + if err.Error() != "codespace is disabled while it has a pending operation: Some pending operation" { |
| 16 | + t.Errorf("expected pending operation error, but got: %v", err) |
| 17 | + } |
| 18 | + } else { |
| 19 | + t.Error("expected pending operation error, but got nothing") |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +func testingLogsApp() *App { |
| 24 | + user := &api.User{Login: "monalisa"} |
| 25 | + disabledCodespace := &api.Codespace{ |
| 26 | + Name: "disabledCodespace", |
| 27 | + PendingOperation: true, |
| 28 | + PendingOperationDisabledReason: "Some pending operation", |
| 29 | + } |
| 30 | + apiMock := &apiClientMock{ |
| 31 | + GetCodespaceFunc: func(_ context.Context, name string, _ bool) (*api.Codespace, error) { |
| 32 | + if name == "disabledCodespace" { |
| 33 | + return disabledCodespace, nil |
| 34 | + } |
| 35 | + return nil, nil |
| 36 | + }, |
| 37 | + GetUserFunc: func(_ context.Context) (*api.User, error) { |
| 38 | + return user, nil |
| 39 | + }, |
| 40 | + AuthorizedKeysFunc: func(_ context.Context, _ string) ([]byte, error) { |
| 41 | + return []byte{}, nil |
| 42 | + }, |
| 43 | + } |
| 44 | + |
| 45 | + io, _, _, _ := iostreams.Test() |
| 46 | + return NewApp(io, nil, apiMock, nil) |
| 47 | +} |
0 commit comments