MCPcopy
hub / github.com/cli/cli / TestApp_Create

Function TestApp_Create

pkg/cmd/codespace/create_test.go:59–667  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func TestApp_Create(t *testing.T) {
60 type fields struct {
61 apiClient apiClient
62 }
63 tests := []struct {
64 name string
65 fields fields
66 opts createOptions
67 wantErr error
68 wantStdout string
69 wantStderr string
70 wantURL string
71 isTTY bool
72 }{
73 {
74 name: "create codespace with default branch and 30m idle timeout",
75 fields: fields{
76 apiClient: apiCreateDefaults(&apiClientMock{
77 CreateCodespaceFunc: func(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error) {
78 if params.Branch != "main" {
79 return nil, fmt.Errorf("got branch %q, want %q", params.Branch, "main")
80 }
81 if params.IdleTimeoutMinutes != 30 {
82 return nil, fmt.Errorf("idle timeout minutes was %v", params.IdleTimeoutMinutes)
83 }
84 if *params.RetentionPeriodMinutes != 2880 {
85 return nil, fmt.Errorf("retention period minutes expected 2880, was %v", params.RetentionPeriodMinutes)
86 }
87 if params.DisplayName != "" {
88 return nil, fmt.Errorf("display name was %q, expected empty", params.DisplayName)
89 }
90 return &api.Codespace{
91 Name: "monalisa-dotfiles-abcd1234",
92 }, nil
93 },
94 }),
95 },
96 opts: createOptions{
97 repo: "monalisa/dotfiles",
98 branch: "",
99 machine: "GIGA",
100 showStatus: false,
101 idleTimeout: 30 * time.Minute,
102 retentionPeriod: NullableDuration{durationPtr(48 * time.Hour)},
103 },
104 wantStdout: "monalisa-dotfiles-abcd1234\n",
105 wantStderr: " ✓ Codespaces usage for this repository is paid for by monalisa\n",
106 },
107 {
108 name: "create with explicit display name",
109 fields: fields{
110 apiClient: apiCreateDefaults(&apiClientMock{
111 CreateCodespaceFunc: func(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error) {
112 if params.DisplayName != "funky flute" {
113 return nil, fmt.Errorf("expected display name %q, got %q", "funky flute", params.DisplayName)
114 }
115 return &api.Codespace{
116 Name: "monalisa-dotfiles-abcd1234",

Callers

nothing calls this directly

Calls 13

CreateMethod · 0.95
VerifyMethod · 0.95
TestFunction · 0.92
apiCreateDefaultsFunction · 0.85
durationPtrFunction · 0.85
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80
ErrorfMethod · 0.65
RunMethod · 0.65
NameMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected