From 49baf5524bde45d2586c90e7cd72c11809a6e423 Mon Sep 17 00:00:00 2001 From: gedi Date: Wed, 1 Jul 2015 16:56:37 +0300 Subject: [PATCH] update byte comparison --- examples/api/README.md | 6 +++++- examples/api/api_test.go | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/api/README.md b/examples/api/README.md index 5897404..ab16da6 100644 --- a/examples/api/README.md +++ b/examples/api/README.md @@ -92,6 +92,7 @@ Now we can implemented steps, since we know what behavior we expect: package main import ( + "bytes" "encoding/json" "fmt" "net/http" @@ -151,7 +152,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *gherkin.DocString) (err er return } 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)) } 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. 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 uses a standard http package. diff --git a/examples/api/api_test.go b/examples/api/api_test.go index 1ce43eb..7c34851 100644 --- a/examples/api/api_test.go +++ b/examples/api/api_test.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "encoding/json" "fmt" "net/http" @@ -60,7 +61,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *gherkin.DocString) (err er return } 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)) } return