(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestParseScaffoldArgs(t *testing.T) { |
| 16 | tests := []struct { |
| 17 | name string |
| 18 | args []string |
| 19 | want scaffoldOptions |
| 20 | wantErr string |
| 21 | }{ |
| 22 | { |
| 23 | name: "request name", |
| 24 | args: []string{"graphql IssueByNumber"}, |
| 25 | want: scaffoldOptions{name: "graphql IssueByNumber"}, |
| 26 | }, |
| 27 | { |
| 28 | name: "--missing", |
| 29 | args: []string{"--missing"}, |
| 30 | want: scaffoldOptions{missing: true}, |
| 31 | }, |
| 32 | { |
| 33 | name: "neither", |
| 34 | wantErr: `pass a request name, such as "graphql IssueByNumber", or --missing`, |
| 35 | }, |
| 36 | { |
| 37 | name: "both", |
| 38 | args: []string{"GET /", "--missing"}, |
| 39 | wantErr: "use either a request name or --missing, not both", |
| 40 | }, |
| 41 | { |
| 42 | name: "lowercase method", |
| 43 | args: []string{"get /repos"}, |
| 44 | wantErr: `request name "get /repos" must start with an uppercase HTTP method or "graphql"`, |
| 45 | }, |
| 46 | { |
| 47 | name: "unquoted REST name", |
| 48 | args: []string{"GET", "/repos/octo/hello"}, |
| 49 | wantErr: "unexpected arguments: /repos/octo/hello; quote the request name, such as 'GET /repos/octo/hello'", |
| 50 | }, |
| 51 | { |
| 52 | name: "unknown flag", |
| 53 | args: []string{"--nope"}, |
| 54 | wantErr: "flag provided but not defined: -nope", |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | for _, tt := range tests { |
| 59 | t.Run(tt.name, func(t *testing.T) { |
| 60 | got, err := parseScaffoldArgs(tt.args) |
| 61 | if tt.wantErr != "" { |
| 62 | require.EqualError(t, err, tt.wantErr) |
| 63 | var ue usageError |
| 64 | assert.True(t, errors.As(err, &ue), "want a usage error") |
| 65 | return |
| 66 | } |
| 67 | require.NoError(t, err) |
| 68 | assert.Equal(t, tt.want, got) |
| 69 | }) |
| 70 | } |
| 71 | } |
| 72 |
nothing calls this directly
no test coverage detected