Validate trail fallback list options · Entire

Validate trail fallback list options

1b5ab1e→main·

evjan·1mo ago·2 files·+27 added/-2 removed

Sessions

401ea2801a5bView transcript

Changes

2

94 unmodified lines

95
96
97
98
99
100
101
102
103
104
105
101
106
107
108
109
6 unmodified lines

116
117
118
114
119
120
121
122
66 unmodified lines

189
190
191
192
193
194
195
196
197
198

94 unmodified lines

// runTrailShow shows the trail for the current branch, or falls through to list.
func runTrailShow(ctx context.Context, w, errW io.Writer, insecureHTTP bool) error {
    listOpts := defaultTrailListOptions(insecureHTTP)
    if err := validateTrailListOptions(listOpts); err != nil {
        return err
    }

return runAuthenticatedDataAPI(ctx, errW, insecureHTTP, func(ctx context.Context, client *api.Client) error {
        branch, err := GetCurrentBranch(ctx)
        if err != nil {
            return runTrailListAllWithClient(ctx, w, client, defaultTrailListOptions(insecureHTTP))
            return runTrailListAllWithClient(ctx, w, client, listOpts)
        }

forge, owner, repo, err := resolveTrailRemote(ctx)
6 unmodified lines

return err
        }
        if found == nil {
            return runTrailListAllWithClient(ctx, w, client, defaultTrailListOptions(insecureHTTP))
            return runTrailListAllWithClient(ctx, w, client, listOpts)
        }

printTrailDetails(w, found.ToMetadata())
66 unmodified lines

}

func runTrailListAllWithClient(ctx context.Context, w io.Writer, client *api.Client, opts trailListOptions) error {
    if err := validateTrailListOptions(opts); err != nil {
        return err
    }

statusFilters, err := parseTrailStatusFilter(opts.Status)
    if err != nil {
        return err

Mcmd/entire/cli/trail_cmd.go+11/-2

80 unmodified lines

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

80 unmodified lines

}

func TestRunTrailListAllWithClient_ValidatesOptionsBeforeRepoLookup(t *testing.T) {
    t.Parallel()

opts := defaultTrailListOptions(false)
    opts.Limit = 0

var out bytes.Buffer
    err := runTrailListAllWithClient(t.Context(), &out, nil, opts)
    if err == nil {
        t.Fatal("expected validation error")
    }
    if got, want := err.Error(), "limit must be greater than 0"; got != want {
        t.Fatalf("error = %q, want %q", got, want)
    }
}

func TestTrailsBasePath(t *testing.T) {
    t.Parallel()
    tests := []struct {