(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestParseSetArgs(t *testing.T) { |
| 21 | tests := []struct { |
| 22 | name string |
| 23 | args []string |
| 24 | want setOptions |
| 25 | wantErr string |
| 26 | }{ |
| 27 | { |
| 28 | name: "name first, then flags", |
| 29 | args: []string{"GET /repos/octo/hello", "--status", "404", "--header", "X-A: 1", "--header", "X-B:"}, |
| 30 | want: setOptions{name: "GET /repos/octo/hello", status: 404, headers: []string{"X-A: 1", "X-B:"}}, |
| 31 | }, |
| 32 | { |
| 33 | name: "flags first, then name", |
| 34 | args: []string{"--body", `{"a":1}`, "graphql IssueByNumber"}, |
| 35 | want: setOptions{name: "graphql IssueByNumber", body: `{"a":1}`, bodySet: true}, |
| 36 | }, |
| 37 | { |
| 38 | name: "empty body clears it", |
| 39 | args: []string{"GET /", "--body", ""}, |
| 40 | want: setOptions{name: "GET /", bodySet: true}, |
| 41 | }, |
| 42 | { |
| 43 | name: "raw response file", |
| 44 | args: []string{"GET /archive", "--raw-file", "response.bin"}, |
| 45 | want: setOptions{name: "GET /archive", rawFile: "response.bin"}, |
| 46 | }, |
| 47 | { |
| 48 | name: "ZIP response directory", |
| 49 | args: []string{"GET /archive", "--zip-dir", "logs"}, |
| 50 | want: setOptions{name: "GET /archive", zipDir: "logs"}, |
| 51 | }, |
| 52 | { |
| 53 | name: "empty raw file path", |
| 54 | args: []string{"GET /binary", "--raw-file", "", "--status", "200"}, |
| 55 | wantErr: "--raw-file needs a file path", |
| 56 | }, |
| 57 | { |
| 58 | name: "empty ZIP directory path", |
| 59 | args: []string{"GET /archive", "--zip-dir", ""}, |
| 60 | wantErr: "--zip-dir needs a directory path", |
| 61 | }, |
| 62 | { |
| 63 | name: "raw and JSON bodies conflict", |
| 64 | args: []string{"GET /archive", "--raw-file", "response.bin", "--body", "{}"}, |
| 65 | wantErr: "--raw-file and --zip-dir cannot be combined with JSON body flags", |
| 66 | }, |
| 67 | { |
| 68 | name: "ZIP and JSON edits conflict", |
| 69 | args: []string{"GET /archive", "--zip-dir", "logs", "--at", "title", "--json", `"x"`}, |
| 70 | wantErr: "--raw-file and --zip-dir cannot be combined with JSON body flags", |
| 71 | }, |
| 72 | { |
| 73 | name: "raw and ZIP bodies conflict", |
| 74 | args: []string{"GET /archive", "--raw-file", "response.bin", "--zip-dir", "logs"}, |
| 75 | wantErr: "use either --raw-file or --zip-dir, not both", |
| 76 | }, |
| 77 | { |
nothing calls this directly
no test coverage detected