Files
asciinema/commands/rec_test.go

64 lines
1.2 KiB
Go
Raw Normal View History

2014-08-03 19:50:39 +02:00
package commands_test
import (
"errors"
"testing"
2015-03-05 15:57:12 +01:00
"github.com/asciinema/asciinema/commands"
2014-08-03 19:50:39 +02:00
)
type testRecorder struct {
2014-08-03 19:50:39 +02:00
err error
}
func (r *testRecorder) Record(path, command, title string, maxWait float64, assumeYes bool, env map[string]string) error {
return r.err
2014-08-03 19:50:39 +02:00
}
2014-11-15 13:33:20 +01:00
type testAPI struct {
2014-08-03 19:50:39 +02:00
err error
t *testing.T
}
func (a *testAPI) AuthUrl() string {
return ""
}
func (a *testAPI) UploadAsciicast(path string) (string, string, error) {
2014-08-03 19:50:39 +02:00
if a.err != nil {
return "", "", a.err
2014-08-03 19:50:39 +02:00
}
return "http://the/url", "", nil
2014-08-03 19:50:39 +02:00
}
func TestRecordCommand_Execute(t *testing.T) {
recErr := errors.New("can't record")
apiErr := errors.New("can't upload")
var tests = []struct {
recordError error
apiError error
expectedError error
}{
{nil, nil, nil},
{recErr, nil, recErr},
{nil, apiErr, apiErr},
}
for _, test := range tests {
recorder := &testRecorder{err: test.recordError}
2014-11-15 13:33:20 +01:00
api := &testAPI{err: test.apiError, t: t}
2014-08-03 19:50:39 +02:00
command := &commands.RecordCommand{
Recorder: recorder,
2014-11-15 13:33:20 +01:00
API: api,
2014-08-03 19:50:39 +02:00
}
2015-03-03 16:13:33 +01:00
err := command.Execute("ls", "listing", false, 5, "")
2014-08-03 19:50:39 +02:00
if err != test.expectedError {
t.Errorf("expected error %v, got %v", test.expectedError, err)
}
}
}