Start tests
This commit is contained in:
parent
86e16cc7c4
commit
c6f89d3c17
1 changed files with 112 additions and 0 deletions
112
pkg/cmd/repo/sync/sync_test.go
Normal file
112
pkg/cmd/repo/sync/sync_test.go
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
package sync
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cli/cli/pkg/cmdutil"
|
||||
"github.com/cli/cli/pkg/iostreams"
|
||||
"github.com/google/shlex"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewCmdSync(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
tty bool
|
||||
input string
|
||||
output SyncOptions
|
||||
wantsErr bool
|
||||
}{
|
||||
{
|
||||
name: "no argument",
|
||||
tty: true,
|
||||
input: "",
|
||||
output: SyncOptions{},
|
||||
},
|
||||
{
|
||||
name: "destination repo",
|
||||
tty: true,
|
||||
input: "cli/cli",
|
||||
output: SyncOptions{
|
||||
DestArg: "cli/cli",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "source repo",
|
||||
tty: true,
|
||||
input: "--source cli/cli",
|
||||
output: SyncOptions{
|
||||
SrcArg: "cli/cli",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "branch",
|
||||
tty: true,
|
||||
input: "--branch trunk",
|
||||
output: SyncOptions{
|
||||
Branch: "trunk",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "force",
|
||||
tty: true,
|
||||
input: "--force",
|
||||
output: SyncOptions{
|
||||
Force: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "confirm",
|
||||
tty: true,
|
||||
input: "--confirm",
|
||||
output: SyncOptions{
|
||||
SkipConfirm: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "notty without confirm",
|
||||
tty: false,
|
||||
input: "",
|
||||
wantsErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
io, _, _, _ := iostreams.Test()
|
||||
io.SetStdinTTY(tt.tty)
|
||||
io.SetStdoutTTY(tt.tty)
|
||||
f := &cmdutil.Factory{
|
||||
IOStreams: io,
|
||||
}
|
||||
argv, err := shlex.Split(tt.input)
|
||||
assert.NoError(t, err)
|
||||
var gotOpts *SyncOptions
|
||||
cmd := NewCmdSync(f, func(opts *SyncOptions) error {
|
||||
gotOpts = opts
|
||||
return nil
|
||||
})
|
||||
cmd.SetArgs(argv)
|
||||
cmd.SetIn(&bytes.Buffer{})
|
||||
cmd.SetOut(&bytes.Buffer{})
|
||||
cmd.SetErr(&bytes.Buffer{})
|
||||
|
||||
_, err = cmd.ExecuteC()
|
||||
if tt.wantsErr {
|
||||
assert.Error(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.output.DestArg, gotOpts.DestArg)
|
||||
assert.Equal(t, tt.output.SrcArg, gotOpts.SrcArg)
|
||||
assert.Equal(t, tt.output.Branch, gotOpts.Branch)
|
||||
assert.Equal(t, tt.output.Force, gotOpts.Force)
|
||||
assert.Equal(t, tt.output.SkipConfirm, gotOpts.SkipConfirm)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_SyncRun(t *testing.T) {
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue