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,9 +78,11 @@ 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])
if _, ok := os.LookupEnv("NOMOCK"); !ok {
j.Translator = func(t *trans.Translation) (string, error) { j.Translator = func(t *trans.Translation) (string, error) {
return data.transOutput, nil return data.transOutput, nil
} }
}
r := j.Translate() r := j.Translate()
if (!reflect.DeepEqual(r, data.expectedResults)) { if (!reflect.DeepEqual(r, data.expectedResults)) {
t.Errorf("\nExpected: '%v'\nActual: '%v'", data.expectedResults, r) t.Errorf("\nExpected: '%v'\nActual: '%v'", data.expectedResults, r)