2016-08-03 09:11:52 +02:00
|
|
|
package bittorrent
|
|
|
|
|
|
|
|
import (
|
2017-12-29 23:44:45 +01:00
|
|
|
"fmt"
|
2016-08-03 09:11:52 +02:00
|
|
|
"testing"
|
|
|
|
|
2017-02-15 06:57:36 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
2016-08-03 09:11:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNew(t *testing.T) {
|
|
|
|
var table = []struct {
|
|
|
|
data string
|
|
|
|
expected Event
|
|
|
|
expectedErr error
|
|
|
|
}{
|
|
|
|
{"", None, nil},
|
|
|
|
{"NONE", None, nil},
|
|
|
|
{"none", None, nil},
|
|
|
|
{"started", Started, nil},
|
|
|
|
{"stopped", Stopped, nil},
|
|
|
|
{"completed", Completed, nil},
|
|
|
|
{"notAnEvent", None, ErrUnknownEvent},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range table {
|
2018-02-02 23:13:13 +01:00
|
|
|
t.Run(fmt.Sprintf("%#v expecting %s", tt.data, nilPrinter(tt.expectedErr)), func(t *testing.T) {
|
2017-12-29 23:44:45 +01:00
|
|
|
got, err := NewEvent(tt.data)
|
|
|
|
require.Equal(t, err, tt.expectedErr, "errors should equal the expected value")
|
|
|
|
require.Equal(t, got, tt.expected, "events should equal the expected value")
|
|
|
|
})
|
2016-08-03 09:11:52 +02:00
|
|
|
}
|
|
|
|
}
|
2018-02-02 23:13:13 +01:00
|
|
|
|
|
|
|
func nilPrinter(err error) string {
|
|
|
|
if err == nil {
|
|
|
|
return "nil"
|
|
|
|
}
|
|
|
|
return err.Error()
|
|
|
|
}
|