-
Notifications
You must be signed in to change notification settings - Fork 674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MF-1357 - Add new endpoint for searching things #1383
Changes from all commits
f207638
1f58de4
745a2b4
3d13624
b8e692c
05e6d75
20e5f8e
a6e7f5f
0f01811
758fd5a
ee1ffb6
eac2b1f
0e85f10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import ( | |
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"strconv" | ||
"testing" | ||
|
||
sdk "github.com/mainflux/mainflux/pkg/sdk/go" | ||
|
@@ -36,7 +35,7 @@ const ( | |
var ( | ||
metadata = map[string]interface{}{"meta": "data"} | ||
metadata2 = map[string]interface{}{"meta": "data2"} | ||
thing = sdk.Thing{ID: "1", Name: "test_device", Metadata: metadata} | ||
thing = sdk.Thing{ID: "001", Name: "test_device", Metadata: metadata} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to use UUID There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Point is that here we mock id so we can test "order by id" functionalities. |
||
emptyThing = sdk.Thing{} | ||
) | ||
|
||
|
@@ -86,14 +85,14 @@ func TestCreateThing(t *testing.T) { | |
thing: thing, | ||
token: token, | ||
err: nil, | ||
location: "1", | ||
location: "001", | ||
}, | ||
{ | ||
desc: "create new empty thing", | ||
thing: emptyThing, | ||
token: token, | ||
err: nil, | ||
location: "2", | ||
location: "002", | ||
}, | ||
{ | ||
desc: "create new thing with empty token", | ||
|
@@ -136,8 +135,8 @@ func TestCreateThings(t *testing.T) { | |
mainfluxSDK := sdk.NewSDK(sdkConf) | ||
|
||
things := []sdk.Thing{ | ||
sdk.Thing{ID: "1", Name: "1", Key: "1"}, | ||
sdk.Thing{ID: "2", Name: "2", Key: "2"}, | ||
sdk.Thing{ID: "001", Name: "1", Key: "1"}, | ||
sdk.Thing{ID: "002", Name: "2", Key: "2"}, | ||
} | ||
|
||
cases := []struct { | ||
|
@@ -262,7 +261,7 @@ func TestThings(t *testing.T) { | |
mainfluxSDK := sdk.NewSDK(sdkConf) | ||
for i := 1; i < 101; i++ { | ||
|
||
th := sdk.Thing{ID: strconv.Itoa(i), Name: "test_device", Metadata: metadata} | ||
th := sdk.Thing{ID: fmt.Sprintf("%03d", i), Name: "test_device", Metadata: metadata} | ||
mainfluxSDK.CreateThing(th, token) | ||
th.Key = fmt.Sprintf("%s%012d", keyPrefix, 2*i) | ||
things = append(things, th) | ||
|
@@ -306,8 +305,8 @@ func TestThings(t *testing.T) { | |
token: token, | ||
offset: 0, | ||
limit: 0, | ||
err: createError(sdk.ErrFailedFetch, http.StatusBadRequest), | ||
response: nil, | ||
err: nil, | ||
response: things[0:10], | ||
}, | ||
{ | ||
desc: "get a list of things with limit greater than max", | ||
|
@@ -325,14 +324,6 @@ func TestThings(t *testing.T) { | |
err: nil, | ||
response: []sdk.Thing{}, | ||
}, | ||
{ | ||
desc: "get a list of things with invalid args (zero limit) and invalid token", | ||
token: wrongValue, | ||
offset: 0, | ||
limit: 0, | ||
err: createError(sdk.ErrFailedFetch, http.StatusBadRequest), | ||
response: nil, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
page, err := mainfluxSDK.Things(tc.token, tc.offset, tc.limit, tc.name) | ||
|
@@ -366,7 +357,7 @@ func TestThingsByChannel(t *testing.T) { | |
var things []sdk.Thing | ||
for i := 1; i < n+1; i++ { | ||
th := sdk.Thing{ | ||
ID: strconv.Itoa(i), | ||
ID: fmt.Sprintf("%03d", i), | ||
Name: "test_device", | ||
Metadata: metadata, | ||
Key: fmt.Sprintf("%s%012d", keyPrefix, 2*i+1), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use UUID?