Skip to content

Commit

Permalink
Add support for sdk-testcases
Browse files Browse the repository at this point in the history
Motivation
----------
sdk-testcases is a project for collecting server response JSON
files that can be used across all SDKs to implement tests. We should
use it in our tests.

Changes
-------
Added sdk-testcases as a submodule and updated tests to use it for
one of the fts tests.

Change-Id: Ifc5f508df4b304163427569f87376613fadffd85
Reviewed-on: http://review.couchbase.org/111226
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Charles Dixon <chvckd@gmail.com>
  • Loading branch information
chvck committed Jul 1, 2019
1 parent f1b3cd4 commit b55e585
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "testdata/sdk-testcases"]
path = testdata/sdk-testcases
url = https://github.com/couchbaselabs/sdk-testcases
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ devsetup:
go get "golang.org/x/lint/golint"
go get "github.com/gordonklaus/ineffassign"
go get "github.com/client9/misspell/cmd/misspell"
git submodule update --remote --init --recursive

test:
go test ./
Expand Down Expand Up @@ -36,4 +37,7 @@ check: lint
bench:
go test -bench=. -run=none --disable-logger=true

.PHONY: all test devsetup fasttest lint cover checkerrs checkfmt checkvet checkiea checkspell check bench
updatetestcases:
git submodule update --remote --init --recursive

.PHONY: all test devsetup fasttest lint cover checkerrs checkfmt checkvet checkiea checkspell check bench updatetestcases
16 changes: 0 additions & 16 deletions base_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package gocb

import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"testing"
Expand Down Expand Up @@ -99,20 +97,6 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func loadTestDataset(dataset string, valuePtr interface{}) error {
bytes, err := ioutil.ReadFile("testdata/" + dataset + ".json")
if err != nil {
return err
}

err = json.Unmarshal(bytes, &valuePtr)
if err != nil {
return err
}

return nil
}

type mockAuthenticator struct {
username string
password string
Expand Down
5 changes: 2 additions & 3 deletions cluster_searchquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@ func TestSearchQueryRetries(t *testing.T) {
}
}

func TestSearchQueryObjectError(t *testing.T) {
func TestSearchQueryServerObjectError(t *testing.T) {
q := SearchQuery{
Name: "test",
Query: NewMatchQuery("test"),
}
timeout := 60 * time.Second

dataBytes, err := loadRawTestDataset("searchquery_timeout")
_, dataBytes, err := loadSDKTestDataset("search/alltimeouts")
if err != nil {
t.Fatalf("Could not read test dataset: %v", err)
}
Expand All @@ -281,7 +281,6 @@ func TestSearchQueryObjectError(t *testing.T) {
}

cluster := testGetClusterForHTTP(provider, timeout, 0, 0)
cluster.sb.SearchRetryBehavior = StandardDelayRetryBehavior(3, 1, 100*time.Millisecond, LinearDelayFunction)

res, err := cluster.SearchQuery(q, nil)
if err == nil {
Expand Down
1 change: 1 addition & 0 deletions testdata/sdk-testcases
Submodule sdk-testcases added at 501391
38 changes: 0 additions & 38 deletions testdata/searchquery_timeout.json

This file was deleted.

30 changes: 30 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io/ioutil"
"testing"
"time"

"github.com/pkg/errors"
)

type testBeerDocument struct {
Expand Down Expand Up @@ -42,6 +44,9 @@ type testBreweryDocument struct {
Website string `json:"website,omitempty"`
}

type testMetadata struct {
}

func loadRawTestDataset(dataset string) ([]byte, error) {
return ioutil.ReadFile("testdata/" + dataset + ".json")
}
Expand All @@ -60,6 +65,31 @@ func loadJSONTestDataset(dataset string, valuePtr interface{}) error {
return nil
}

func loadSDKTestDataset(dataset string) (*testMetadata, []byte, error) {
var testdata map[string]interface{}
err := loadJSONTestDataset("sdk-testcases/"+dataset, &testdata)
if err != nil {
return nil, nil, err
}

_, ok := testdata["metadata"]
if !ok {
return nil, nil, errors.New("test dataset missing metadata")
}

data, ok := testdata["data"]
if !ok {
return nil, nil, errors.New("test dataset missing data")
}

b, err := json.Marshal(data)
if err != nil {
return nil, nil, errors.Wrap(err, "could not remarshal test data")
}

return nil, b, nil
}

func marshal(t *testing.T, value interface{}) []byte {
b, err := json.Marshal(value)
if err != nil {
Expand Down

0 comments on commit b55e585

Please sign in to comment.