update byte comparison
Этот коммит содержится в:
родитель
42524a12f8
коммит
49baf5524b
2 изменённых файлов: 7 добавлений и 2 удалений
|
@ -92,6 +92,7 @@ Now we can implemented steps, since we know what behavior we expect:
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -151,7 +152,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *gherkin.DocString) (err er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
actual = a.resp.Body.Bytes()
|
actual = a.resp.Body.Bytes()
|
||||||
if string(actual) != string(expected) {
|
if !bytes.Equal(actual, expected) {
|
||||||
err = fmt.Errorf("expected json, does not match actual: %s", string(actual))
|
err = fmt.Errorf("expected json, does not match actual: %s", string(actual))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -171,6 +172,9 @@ func featureContext(s godog.Suite) {
|
||||||
**NOTE:** the `getVersion` handler call on **/version** endpoint. We actually need to implement it now.
|
**NOTE:** the `getVersion` handler call on **/version** endpoint. We actually need to implement it now.
|
||||||
If we made some mistakes in step implementations, we will know about it when we run the tests.
|
If we made some mistakes in step implementations, we will know about it when we run the tests.
|
||||||
|
|
||||||
|
Though, we could also improve our **JSON** comparison function to range through the interfaces and
|
||||||
|
match their types and values.
|
||||||
|
|
||||||
In case if some router is used, you may search the handler based on the endpoint. Current example
|
In case if some router is used, you may search the handler based on the endpoint. Current example
|
||||||
uses a standard http package.
|
uses a standard http package.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -60,7 +61,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *gherkin.DocString) (err er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
actual = a.resp.Body.Bytes()
|
actual = a.resp.Body.Bytes()
|
||||||
if string(actual) != string(expected) {
|
if !bytes.Equal(actual, expected) {
|
||||||
err = fmt.Errorf("expected json, does not match actual: %s", string(actual))
|
err = fmt.Errorf("expected json, does not match actual: %s", string(actual))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче