Make the mocking of Google API configurable in unit tests

This commit is contained in:
Kristóf Tóth 2019-10-11 22:40:02 +02:00
parent 3ad5e57d84
commit 80eb2de872

View File

@ -4,6 +4,7 @@ import (
"testing" "testing"
"." "."
"reflect" "reflect"
"os"
) )
@ -77,8 +78,10 @@ méltányosság
for _, data := range cases { for _, data := range cases {
j := trans.New(data.job[0], data.job[1], data.job[2]) j := trans.New(data.job[0], data.job[1], data.job[2])
j.Translator = func(t *trans.Translation) (string, error) { if _, ok := os.LookupEnv("NOMOCK"); !ok {
return data.transOutput, nil j.Translator = func(t *trans.Translation) (string, error) {
return data.transOutput, nil
}
} }
r := j.Translate() r := j.Translate()
if (!reflect.DeepEqual(r, data.expectedResults)) { if (!reflect.DeepEqual(r, data.expectedResults)) {