-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76f90be
commit e07d4ed
Showing
5 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package gocosmosdb | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestEscapeSQL(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
sql := escapeSQL("SELECT * FROM root \n\r\x00\x1a\" \\ r") | ||
assert.Equal("SELECT * FROM root \\n\\r\\0\\Z\\\" \\\\ r", sql) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package gocosmosdb | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCallOptions(t *testing.T) { | ||
assert := assert.New(t) | ||
opts := []CallOption{} | ||
opts = append(opts, PartitionKey("test")) | ||
opts = append(opts, Upsert()) | ||
opts = append(opts, Limit(100)) | ||
opts = append(opts, Continuation("continueToken")) | ||
opts = append(opts, ConsistencyLevel("Strong")) | ||
opts = append(opts, SessionToken("sessionToken")) | ||
opts = append(opts, CrossPartition()) | ||
opts = append(opts, IfMatch("eTag")) | ||
opts = append(opts, IfNoneMatch("eTag")) | ||
opts = append(opts, IfModifiedSince("someDate")) | ||
opts = append(opts, ChangeFeed()) | ||
opts = append(opts, ThroughputRUs(400)) | ||
opts = append(opts, PartitionKeyRangeID(0)) | ||
opts = append(opts, EnableQueryScan()) | ||
opts = append(opts, EnableParallelizeCrossPartitionQuery()) | ||
ctx := context.WithValue(context.Background(), "foo", "bar") | ||
opts = append(opts, WithContext(ctx)) | ||
|
||
link := "http://localhost:8080" | ||
req, err := http.NewRequest("POST", link, nil) | ||
if err != nil { | ||
assert.Nil(err) | ||
} | ||
r := ResourceRequest(link, req) | ||
for i := 0; i < len(opts); i++ { | ||
if err := opts[i](r); err != nil { | ||
assert.Nil(err) | ||
} | ||
} | ||
|
||
assert.Equal([]string{"[\"test\"]"}, r.Header[HeaderPartitionKey]) | ||
assert.Equal([]string{"true"}, r.Header[HeaderUpsert]) | ||
assert.Equal([]string{"100"}, r.Header[HeaderMaxItemCount]) | ||
assert.Equal([]string{"continueToken"}, r.Header[HeaderContinuation]) | ||
assert.Equal([]string{"Strong"}, r.Header[HeaderConsistencyLevel]) | ||
assert.Equal([]string{"sessionToken"}, r.Header[HeaderSessionToken]) | ||
assert.Equal([]string{"true"}, r.Header[HeaderCrossPartition]) | ||
assert.Equal([]string{"eTag"}, r.Header[HeaderIfMatch]) | ||
assert.Equal([]string{"eTag"}, r.Header[HeaderIfNonMatch]) | ||
assert.Equal([]string{"someDate"}, r.Header[HeaderIfModifiedSince]) | ||
//assert.Equal([]string{"Incremental feed"}, r.Header[HeaderAIM]) | ||
assert.Equal([]string{"400"}, r.Header[HeaderOfferThroughput]) | ||
assert.Equal([]string{"0"}, r.Header[HeaderPartitionKeyRangeID]) | ||
assert.Equal([]string{"true"}, r.Header[HeaderEnableScan]) | ||
assert.Equal([]string{"true"}, r.Header[HeaderParalelizeCrossPartition]) | ||
assert.Equal(ctx, r.rContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package gocosmosdb | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPagable(t *testing.T) { | ||
assert := assert.New(t) | ||
resp1 := `{ | ||
"_rid": "d9RzAJRFKgw=", | ||
"Documents": [ | ||
{ | ||
"id": "SalesOrder1", | ||
"ponumber": "PO18009186470", | ||
"_rid": "d9RzAJRFKgwBAAAAAAAAAA==", | ||
"_self": "dbs/d9RzAA==/colls/d9RzAJRFKgw=/docs/d9RzAJRFKgwBAAAAAAAAAA==/", | ||
"_etag": "\"0000d986-0000-0000-0000-56f9e25b0000\"", | ||
"_ts": 1459216987, | ||
"_attachments": "attachments/" | ||
} | ||
], | ||
"_count": 2 | ||
}` | ||
resp2 := `{ | ||
"_rid": "d9RzAJRFKgw=", | ||
"Documents": [ | ||
{ | ||
"id": "SalesOrder2", | ||
"ponumber": "PO15428132599", | ||
"_rid": "d9RzAJRFKgwCAAAAAAAAAA==", | ||
"_self": "dbs/d9RzAA==/colls/d9RzAJRFKgw=/docs/d9RzAJRFKgwCAAAAAAAAAA==/", | ||
"_etag": "\"0000da86-0000-0000-0000-56f9e25b0000\"", | ||
"_ts": 1459216987, | ||
"_attachments": "attachments/" | ||
} | ||
], | ||
"_count": 2 | ||
}` | ||
s := ServerFactory(resp1, resp2) | ||
defer s.Close() | ||
client := New(s.URL, Config{MasterKey: "YXJpZWwNCg=="}, log) | ||
docs := []testDoc{} | ||
query := &QueryWithParameters{ | ||
Query: "SELECT * FROM root r WHERE r._ts > @_ts", | ||
Parameters: []QueryParameter{ | ||
QueryParameter{ | ||
Name: "@_ts", | ||
Value: 1459216957, | ||
}, | ||
}, | ||
} | ||
pg := client.NewPagableQuery("dbs/d9RzAA==/colls/d9RzAJRFKgw=", query, 1, &docs) | ||
assert.NotNil(pg) | ||
assert.IsType(&PagableQuery{}, pg) | ||
pg.Next() | ||
assert.Equal("SalesOrder1", docs[0].Id) | ||
pg.Next() | ||
assert.Equal("SalesOrder2", docs[0].Id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package gocosmosdb | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestExpectStatusCodes(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
st1 := expectStatusCode(200) | ||
assert.Equal(true, st1(200)) | ||
|
||
st2 := expectStatusCodeXX(400) | ||
assert.Equal(true, st2(499)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package gocosmosdb | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUtils(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
uuid := genId() | ||
assert.Equal(36, len(uuid)) | ||
|
||
exp := Expirable{} | ||
exp.SetTTL(100 * time.Second) | ||
assert.Equal(int64(100), exp.TTL) | ||
|
||
b, err := stringify([]byte("foo")) | ||
assert.Nil(err) | ||
assert.Equal([]byte("foo"), b) | ||
} |