-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vilmibm
committed
Sep 15, 2020
1 parent
ada2c56
commit 62f54f0
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package edit | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/cli/cli/pkg/cmdutil" | ||
"github.com/google/shlex" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewCmdEdit(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cli string | ||
wants EditOptions | ||
}{ | ||
{ | ||
name: "no flags", | ||
cli: "123", | ||
wants: EditOptions{ | ||
Selector: "123", | ||
}, | ||
}, | ||
{ | ||
name: "filename", | ||
cli: "123 --filename cool.md", | ||
wants: EditOptions{ | ||
Selector: "123", | ||
Filename: "cool.md", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
f := &cmdutil.Factory{} | ||
|
||
argv, err := shlex.Split(tt.cli) | ||
assert.NoError(t, err) | ||
|
||
var gotOpts *EditOptions | ||
cmd := NewCmdEdit(f, func(opts *EditOptions) error { | ||
gotOpts = opts | ||
return nil | ||
}) | ||
cmd.SetArgs(argv) | ||
cmd.SetIn(&bytes.Buffer{}) | ||
cmd.SetOut(&bytes.Buffer{}) | ||
cmd.SetErr(&bytes.Buffer{}) | ||
|
||
_, err = cmd.ExecuteC() | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, tt.wants.Filename, gotOpts.Filename) | ||
assert.Equal(t, tt.wants.Selector, gotOpts.Selector) | ||
}) | ||
} | ||
} | ||
|
||
// TODO execution tests | ||
// TODO no such gist | ||
// TODO one files | ||
// TODO multiple files, submit | ||
// TODO multiple files, cancel |