mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-26 13:48:53 +08:00

* Refactor Mainflux go SDK Add structures instead of string parameters. Add offset and limit parameters to things and channels methods. Add better configuration support. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add new public errors with better error handling Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update SDK to use uint instread of string id Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update cli to use new SDK API Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove TLS termination from nginx configuration Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update SDK documentation and structures Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Refactor things service Decouple HTTP layer from business logic. Remove ID number validation check. Remove models from HTTP requests and responses. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Reformat tests for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Increase test coverage for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
55 lines
973 B
Go
55 lines
973 B
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package things_test
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/mainflux/mainflux/things"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFromString(t *testing.T) {
|
|
big := fmt.Sprintf("%d", uint64(math.MaxUint64))
|
|
|
|
cases := map[string]struct {
|
|
in string
|
|
out uint64
|
|
err error
|
|
}{
|
|
"from valid number": {
|
|
in: big,
|
|
out: math.MaxUint64,
|
|
err: nil,
|
|
},
|
|
"from negative number": {
|
|
in: "-1",
|
|
out: 0,
|
|
err: things.ErrNotFound,
|
|
},
|
|
"from empty string": {
|
|
in: "",
|
|
out: 0,
|
|
err: things.ErrNotFound,
|
|
},
|
|
"from arbitrary string": {
|
|
in: "dummy",
|
|
out: 0,
|
|
err: things.ErrNotFound,
|
|
},
|
|
}
|
|
|
|
for desc, tc := range cases {
|
|
out, err := things.FromString(tc.in)
|
|
assert.Equal(t, tc.out, out, fmt.Sprintf("%s: expected %d got %d", desc, tc.out, out))
|
|
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s", desc, tc.err, err))
|
|
}
|
|
}
|