(t *testing.T)
| 89 | } |
| 90 | |
| 91 | func TestEditRun(t *testing.T) { |
| 92 | tests := []struct { |
| 93 | name string |
| 94 | tty bool |
| 95 | opts *editOptions |
| 96 | httpStubs func(*httpmock.Registry) |
| 97 | wantStdout string |
| 98 | wantErrMsg string |
| 99 | }{ |
| 100 | { |
| 101 | name: "updates label", |
| 102 | tty: true, |
| 103 | opts: &editOptions{Name: "test", Description: "some description"}, |
| 104 | httpStubs: func(reg *httpmock.Registry) { |
| 105 | reg.Register( |
| 106 | httpmock.REST("PATCH", "repos/OWNER/REPO/labels/test"), |
| 107 | httpmock.StatusStringResponse(201, "{}"), |
| 108 | ) |
| 109 | }, |
| 110 | wantStdout: "✓ Label \"test\" updated in OWNER/REPO\n", |
| 111 | }, |
| 112 | { |
| 113 | name: "updates label notty", |
| 114 | tty: false, |
| 115 | opts: &editOptions{Name: "test", Description: "some description"}, |
| 116 | httpStubs: func(reg *httpmock.Registry) { |
| 117 | reg.Register( |
| 118 | httpmock.REST("PATCH", "repos/OWNER/REPO/labels/test"), |
| 119 | httpmock.StatusStringResponse(201, "{}"), |
| 120 | ) |
| 121 | }, |
| 122 | wantStdout: "", |
| 123 | }, |
| 124 | { |
| 125 | name: "updates missing label", |
| 126 | opts: &editOptions{Name: "invalid", Description: "some description"}, |
| 127 | httpStubs: func(reg *httpmock.Registry) { |
| 128 | reg.Register( |
| 129 | httpmock.REST("PATCH", "repos/OWNER/REPO/labels/invalid"), |
| 130 | httpmock.WithHeader( |
| 131 | httpmock.StatusStringResponse(404, `{"message":"Not Found"}`), |
| 132 | "Content-Type", |
| 133 | "application/json", |
| 134 | ), |
| 135 | ) |
| 136 | }, |
| 137 | wantErrMsg: "HTTP 404: Not Found (https://api.github.com/repos/OWNER/REPO/labels/invalid)", |
| 138 | }, |
| 139 | } |
| 140 | |
| 141 | for _, tt := range tests { |
| 142 | t.Run(tt.name, func(t *testing.T) { |
| 143 | reg := &httpmock.Registry{} |
| 144 | if tt.httpStubs != nil { |
| 145 | tt.httpStubs(reg) |
| 146 | } |
| 147 | tt.opts.HttpClient = func() (*http.Client, error) { |
| 148 | return &http.Client{Transport: reg}, nil |
nothing calls this directly
no test coverage detected