2018-08-20 08:53:13 +02:00
|
|
|
package i18n
|
|
|
|
|
|
|
|
import (
|
2018-08-20 21:04:04 +02:00
|
|
|
"fmt"
|
2018-08-26 07:46:18 +02:00
|
|
|
"io/ioutil"
|
2018-08-20 08:53:13 +02:00
|
|
|
"testing"
|
|
|
|
|
2018-08-23 14:22:03 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-08-20 08:53:13 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2018-08-26 07:46:18 +02:00
|
|
|
func getDummyLog() *logrus.Entry {
|
|
|
|
log := logrus.New()
|
|
|
|
log.Out = ioutil.Discard
|
|
|
|
return log.WithField("test", "test")
|
|
|
|
}
|
2018-11-30 02:47:14 +02:00
|
|
|
|
|
|
|
// TestDetectLanguage is a function.
|
2018-08-20 21:04:04 +02:00
|
|
|
func TestDetectLanguage(t *testing.T) {
|
2018-08-20 08:53:13 +02:00
|
|
|
type scenario struct {
|
2018-08-20 21:04:04 +02:00
|
|
|
langDetector func() (string, error)
|
|
|
|
expected string
|
2018-08-20 08:53:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
scenarios := []scenario{
|
|
|
|
{
|
2018-08-20 21:04:04 +02:00
|
|
|
func() (string, error) {
|
|
|
|
return "", fmt.Errorf("An error occurred")
|
2018-08-20 08:53:13 +02:00
|
|
|
},
|
2018-08-20 21:04:04 +02:00
|
|
|
"C",
|
2018-08-20 08:53:13 +02:00
|
|
|
},
|
|
|
|
{
|
2018-08-20 21:04:04 +02:00
|
|
|
func() (string, error) {
|
|
|
|
return "en", nil
|
2018-08-20 08:53:13 +02:00
|
|
|
},
|
2018-08-20 21:04:04 +02:00
|
|
|
"en",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range scenarios {
|
|
|
|
assert.EqualValues(t, s.expected, detectLanguage(s.langDetector))
|
|
|
|
}
|
|
|
|
}
|