2020-04-21 22:05:11 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2022-03-04 00:13:46 +08:00
|
|
|
"github.com/mainflux/mainflux/internal/apiutil"
|
2020-06-03 21:16:19 +08:00
|
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
2020-04-21 22:05:11 +08:00
|
|
|
"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": {
|
2022-03-04 00:13:46 +08:00
|
|
|
err: apiutil.ErrMissingID,
|
2020-04-21 22:05:11 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for desc, tc := range cases {
|
2020-09-29 16:25:26 +08:00
|
|
|
req := provisionReq{
|
2020-04-21 22:05:11 +08:00
|
|
|
ExternalID: tc.ExternalID,
|
|
|
|
ExternalKey: tc.ExternalKey,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := req.validate()
|
2020-09-29 16:25:26 +08:00
|
|
|
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected `%v` got `%v`", desc, tc.err, err))
|
2020-04-21 22:05:11 +08:00
|
|
|
}
|
|
|
|
}
|