mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +08:00

* add provision service Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix code style Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix test for provision Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * extra line Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * return map[string]interface instead of interface Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
38 lines
713 B
Go
38 lines
713 B
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestValidate(t *testing.T) {
|
|
|
|
cases := map[string]struct {
|
|
ExternalID string
|
|
ExternalKey string
|
|
err error
|
|
}{
|
|
"mac address for device": {
|
|
ExternalID: "11:22:33:44:55:66",
|
|
ExternalKey: "key12345678",
|
|
err: nil,
|
|
},
|
|
"external id for device empty": {
|
|
err: errMalformedEntity,
|
|
},
|
|
}
|
|
|
|
for desc, tc := range cases {
|
|
req := provisionReq{
|
|
ExternalID: tc.ExternalID,
|
|
ExternalKey: tc.ExternalKey,
|
|
}
|
|
|
|
err := req.validate()
|
|
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected `%v` got `%v`", desc, tc.err, err))
|
|
}
|
|
}
|