Skip to content

Commit

Permalink
start on edit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Sep 15, 2020
1 parent ada2c56 commit 62f54f0
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions pkg/cmd/gist/edit/edit_test.go
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

0 comments on commit 62f54f0

Please sign in to comment.