mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +01:00
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package commands_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/asciinema/asciinema/commands"
|
|
)
|
|
|
|
type testRecorder struct {
|
|
err error
|
|
}
|
|
|
|
func (r *testRecorder) Record(path, command, title string, maxWait float64, assumeYes bool, env map[string]string) error {
|
|
return r.err
|
|
}
|
|
|
|
type testAPI struct {
|
|
err error
|
|
t *testing.T
|
|
}
|
|
|
|
func (a *testAPI) AuthUrl() string {
|
|
return ""
|
|
}
|
|
|
|
func (a *testAPI) UploadAsciicast(path string) (string, string, error) {
|
|
if a.err != nil {
|
|
return "", "", a.err
|
|
}
|
|
|
|
return "http://the/url", "", nil
|
|
}
|
|
|
|
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}
|
|
api := &testAPI{err: test.apiError, t: t}
|
|
|
|
command := &commands.RecordCommand{
|
|
Recorder: recorder,
|
|
API: api,
|
|
}
|
|
|
|
err := command.Execute("ls", "listing", false, 5, "")
|
|
if err != test.expectedError {
|
|
t.Errorf("expected error %v, got %v", test.expectedError, err)
|
|
}
|
|
}
|
|
}
|