Make the mocking of Google API configurable in unit tests
This commit is contained in:
parent
3ad5e57d84
commit
80eb2de872
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user