(t *testing.T)
| 84 | } |
| 85 | |
| 86 | func TestCreateRun(t *testing.T) { |
| 87 | tests := []struct { |
| 88 | name string |
| 89 | tty bool |
| 90 | opts *createOptions |
| 91 | httpStubs func(*httpmock.Registry) |
| 92 | wantStdout string |
| 93 | }{ |
| 94 | { |
| 95 | name: "creates label", |
| 96 | tty: true, |
| 97 | opts: &createOptions{Name: "test", Description: "some description"}, |
| 98 | httpStubs: func(reg *httpmock.Registry) { |
| 99 | reg.Register( |
| 100 | httpmock.REST("POST", "repos/OWNER/REPO/labels"), |
| 101 | httpmock.StatusStringResponse(201, "{}"), |
| 102 | ) |
| 103 | }, |
| 104 | wantStdout: "✓ Label \"test\" created in OWNER/REPO\n", |
| 105 | }, |
| 106 | { |
| 107 | name: "creates label notty", |
| 108 | tty: false, |
| 109 | opts: &createOptions{Name: "test", Description: "some description"}, |
| 110 | httpStubs: func(reg *httpmock.Registry) { |
| 111 | reg.Register( |
| 112 | httpmock.REST("POST", "repos/OWNER/REPO/labels"), |
| 113 | httpmock.StatusStringResponse(201, "{}"), |
| 114 | ) |
| 115 | }, |
| 116 | wantStdout: "", |
| 117 | }, |
| 118 | { |
| 119 | name: "creates existing label", |
| 120 | opts: &createOptions{Name: "test", Description: "some description", Force: true}, |
| 121 | httpStubs: func(reg *httpmock.Registry) { |
| 122 | reg.Register( |
| 123 | httpmock.REST("POST", "repos/OWNER/REPO/labels"), |
| 124 | httpmock.WithHeader( |
| 125 | httpmock.StatusStringResponse(422, `{"message":"Validation Failed","errors":[{"resource":"Label","code":"already_exists","field":"name"}]}`), |
| 126 | "Content-Type", |
| 127 | "application/json", |
| 128 | ), |
| 129 | ) |
| 130 | reg.Register( |
| 131 | httpmock.REST("PATCH", "repos/OWNER/REPO/labels/test"), |
| 132 | httpmock.StatusStringResponse(201, "{}"), |
| 133 | ) |
| 134 | }, |
| 135 | }, |
| 136 | } |
| 137 | |
| 138 | for _, tt := range tests { |
| 139 | t.Run(tt.name, func(t *testing.T) { |
| 140 | reg := &httpmock.Registry{} |
| 141 | if tt.httpStubs != nil { |
| 142 | tt.httpStubs(reg) |
| 143 | } |
nothing calls this directly
no test coverage detected