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
|
|
|
)
|
|
|
|
|
|
2015-02-24 16:22:31 +01:00
|
|
|
type testRecorder struct {
|
2014-08-03 19:50:39 +02:00
|
|
|
err error
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 20:18:00 +02:00
|
|
|
func (r *testRecorder) Record(path, command, title string, maxWait float64, assumeYes bool, env map[string]string) error {
|
2015-02-24 16:22:31 +01:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-12 12:31:46 +01:00
|
|
|
func (a *testAPI) AuthUrl() string {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-09 12:18:15 +01:00
|
|
|
func (a *testAPI) UploadAsciicast(path string) (string, string, error) {
|
2014-08-03 19:50:39 +02:00
|
|
|
if a.err != nil {
|
2015-03-09 12:18:15 +01:00
|
|
|
return "", "", a.err
|
2014-08-03 19:50:39 +02:00
|
|
|
}
|
|
|
|
|
|
2015-03-09 12:18:15 +01: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 {
|
2015-02-24 16:22:31 +01:00
|
|
|
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{
|
2015-02-24 16:22:31 +01:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|