-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(testsutil): Add function to generate random UUID This commit adds a new function to the `common.go` file in the `testsutil` package. The function `GenerateRandomUUID` generates a random UUID using the `github.com/mainflux/mainflux/pkg/uuid` package. This function will be used in tests to generate unique identifiers for testing purposes. The function is added to the existing `common.go` file in the `testsutil` package, which is used for common utilities in tests. This change improves the testability of the codebase by providing a convenient way to generate random UUIDs for testing purposes. Signed-off-by: Rodney Osodo <[email protected]> * feat(auth): add error constants This commit adds two error constants, InvalidID and InvalidToken, to the auth package. These constants will be used to represent invalid ID and token values in the authentication service. Signed-off-by: Rodney Osodo <[email protected]> * feat(ws): add validation for empty message payload This commit adds a validation check for an empty message payload in the Publish method of the adapterService struct in the ws/adapter.go file. If the payload is empty, the method will now return an ErrFailedMessagePublish error. This validation ensures that only non-empty payloads are published. Signed-off-by: Rodney Osodo <[email protected]> * feat(auth): add constant for invalid value Added a constant named InvalidValue to the auth/mocks/service.go file. This constant is set to "invalid" and will be used to represent an invalid value in the codebase. Signed-off-by: Rodney Osodo <[email protected]> --------- Signed-off-by: Rodney Osodo <[email protected]>
- Loading branch information
1 parent
67276c1
commit e6f34e1
Showing
9 changed files
with
109 additions
and
74 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
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
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 |
---|---|---|
|
@@ -12,7 +12,6 @@ import ( | |
"github.com/mainflux/mainflux/internal/testsutil" | ||
"github.com/mainflux/mainflux/pkg/clients" | ||
"github.com/mainflux/mainflux/pkg/errors" | ||
"github.com/mainflux/mainflux/pkg/uuid" | ||
"github.com/mainflux/mainflux/things/postgres" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
@@ -21,7 +20,6 @@ import ( | |
const maxNameSize = 1024 | ||
|
||
var ( | ||
idProvider = uuid.New() | ||
invalidName = strings.Repeat("m", maxNameSize+10) | ||
clientIdentity = "[email protected]" | ||
clientName = "client name" | ||
|
@@ -34,7 +32,7 @@ func TestClientsSave(t *testing.T) { | |
}) | ||
repo := postgres.NewRepository(database) | ||
|
||
uid := testsutil.GenerateUUID(t, idProvider) | ||
uid := testsutil.GenerateUUID(t) | ||
|
||
cases := []struct { | ||
desc string | ||
|
@@ -48,7 +46,7 @@ func TestClientsSave(t *testing.T) { | |
Name: clientName, | ||
Credentials: clients.Credentials{ | ||
Identity: clientIdentity, | ||
Secret: testsutil.GenerateUUID(t, idProvider), | ||
Secret: testsutil.GenerateUUID(t), | ||
}, | ||
Metadata: clients.Metadata{}, | ||
Status: clients.EnabledStatus, | ||
|
@@ -58,12 +56,12 @@ func TestClientsSave(t *testing.T) { | |
{ | ||
desc: "add new client with an owner", | ||
client: clients.Client{ | ||
ID: testsutil.GenerateUUID(t, idProvider), | ||
ID: testsutil.GenerateUUID(t), | ||
Owner: uid, | ||
Name: clientName, | ||
Credentials: clients.Credentials{ | ||
Identity: "[email protected]", | ||
Secret: testsutil.GenerateUUID(t, idProvider), | ||
Secret: testsutil.GenerateUUID(t), | ||
}, | ||
Metadata: clients.Metadata{}, | ||
Status: clients.EnabledStatus, | ||
|
@@ -77,7 +75,7 @@ func TestClientsSave(t *testing.T) { | |
Name: clientName, | ||
Credentials: clients.Credentials{ | ||
Identity: "[email protected]", | ||
Secret: testsutil.GenerateUUID(t, idProvider), | ||
Secret: testsutil.GenerateUUID(t), | ||
}, | ||
Metadata: clients.Metadata{}, | ||
Status: clients.EnabledStatus, | ||
|
@@ -87,11 +85,11 @@ func TestClientsSave(t *testing.T) { | |
{ | ||
desc: "add client with invalid client name", | ||
client: clients.Client{ | ||
ID: testsutil.GenerateUUID(t, idProvider), | ||
ID: testsutil.GenerateUUID(t), | ||
Name: invalidName, | ||
Credentials: clients.Credentials{ | ||
Identity: "[email protected]", | ||
Secret: testsutil.GenerateUUID(t, idProvider), | ||
Secret: testsutil.GenerateUUID(t), | ||
}, | ||
Metadata: clients.Metadata{}, | ||
Status: clients.EnabledStatus, | ||
|
@@ -101,11 +99,11 @@ func TestClientsSave(t *testing.T) { | |
{ | ||
desc: "add client with invalid client owner", | ||
client: clients.Client{ | ||
ID: testsutil.GenerateUUID(t, idProvider), | ||
ID: testsutil.GenerateUUID(t), | ||
Owner: invalidName, | ||
Credentials: clients.Credentials{ | ||
Identity: "[email protected]", | ||
Secret: testsutil.GenerateUUID(t, idProvider), | ||
Secret: testsutil.GenerateUUID(t), | ||
}, | ||
Metadata: clients.Metadata{}, | ||
Status: clients.EnabledStatus, | ||
|
@@ -115,11 +113,11 @@ func TestClientsSave(t *testing.T) { | |
{ | ||
desc: "add client with invalid client identity", | ||
client: clients.Client{ | ||
ID: testsutil.GenerateUUID(t, idProvider), | ||
ID: testsutil.GenerateUUID(t), | ||
Name: clientName, | ||
Credentials: clients.Credentials{ | ||
Identity: invalidName, | ||
Secret: testsutil.GenerateUUID(t, idProvider), | ||
Secret: testsutil.GenerateUUID(t), | ||
}, | ||
Metadata: clients.Metadata{}, | ||
Status: clients.EnabledStatus, | ||
|
@@ -129,10 +127,10 @@ func TestClientsSave(t *testing.T) { | |
{ | ||
desc: "add client with a missing client identity", | ||
client: clients.Client{ | ||
ID: testsutil.GenerateUUID(t, idProvider), | ||
ID: testsutil.GenerateUUID(t), | ||
Credentials: clients.Credentials{ | ||
Identity: "", | ||
Secret: testsutil.GenerateUUID(t, idProvider), | ||
Secret: testsutil.GenerateUUID(t), | ||
}, | ||
Metadata: clients.Metadata{}, | ||
}, | ||
|
@@ -141,7 +139,7 @@ func TestClientsSave(t *testing.T) { | |
{ | ||
desc: "add client with a missing client secret", | ||
client: clients.Client{ | ||
ID: testsutil.GenerateUUID(t, idProvider), | ||
ID: testsutil.GenerateUUID(t), | ||
Credentials: clients.Credentials{ | ||
Identity: "[email protected]", | ||
Secret: "", | ||
|
@@ -169,11 +167,11 @@ func TestClientsRetrieveBySecret(t *testing.T) { | |
repo := postgres.NewRepository(database) | ||
|
||
client := clients.Client{ | ||
ID: testsutil.GenerateUUID(t, idProvider), | ||
ID: testsutil.GenerateUUID(t), | ||
Name: clientName, | ||
Credentials: clients.Credentials{ | ||
Identity: clientIdentity, | ||
Secret: testsutil.GenerateUUID(t, idProvider), | ||
Secret: testsutil.GenerateUUID(t), | ||
}, | ||
Status: clients.EnabledStatus, | ||
} | ||
|
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 |
---|---|---|
|
@@ -28,7 +28,7 @@ var ( | |
idProvider = uuid.New() | ||
secret = "strongsecret" | ||
validCMetadata = mfclients.Metadata{"role": "client"} | ||
ID = testsutil.GenerateUUID(&testing.T{}, idProvider) | ||
ID = testsutil.GenerateUUID(&testing.T{}) | ||
client = mfclients.Client{ | ||
ID: ID, | ||
Name: "clientname", | ||
|
@@ -218,7 +218,7 @@ func TestRegisterClient(t *testing.T) { | |
{ | ||
desc: "register a new client with empty secret", | ||
client: mfclients.Client{ | ||
Owner: testsutil.GenerateUUID(t, idProvider), | ||
Owner: testsutil.GenerateUUID(t), | ||
Credentials: mfclients.Credentials{ | ||
Identity: "[email protected]", | ||
}, | ||
|
@@ -327,7 +327,7 @@ func TestListClients(t *testing.T) { | |
|
||
nClients := uint64(200) | ||
aClients := []mfclients.Client{} | ||
OwnerID := testsutil.GenerateUUID(t, idProvider) | ||
OwnerID := testsutil.GenerateUUID(t) | ||
for i := uint64(1); i < nClients; i++ { | ||
identity := fmt.Sprintf("TestListClients_%[email protected]", i) | ||
client := mfclients.Client{ | ||
|
@@ -341,7 +341,7 @@ func TestListClients(t *testing.T) { | |
} | ||
if i%50 == 0 { | ||
client.Owner = OwnerID | ||
client.Owner = testsutil.GenerateUUID(t, idProvider) | ||
client.Owner = testsutil.GenerateUUID(t) | ||
} | ||
aClients = append(aClients, client) | ||
} | ||
|
@@ -1089,11 +1089,11 @@ func TestListMembers(t *testing.T) { | |
|
||
nClients := uint64(10) | ||
aClients := []mfclients.Client{} | ||
owner := testsutil.GenerateUUID(t, idProvider) | ||
owner := testsutil.GenerateUUID(t) | ||
for i := uint64(0); i < nClients; i++ { | ||
identity := fmt.Sprintf("member_%[email protected]", i) | ||
client := mfclients.Client{ | ||
ID: testsutil.GenerateUUID(t, idProvider), | ||
ID: testsutil.GenerateUUID(t), | ||
Name: identity, | ||
Credentials: mfclients.Credentials{ | ||
Identity: identity, | ||
|
@@ -1119,7 +1119,7 @@ func TestListMembers(t *testing.T) { | |
{ | ||
desc: "list clients with authorized token", | ||
token: validToken, | ||
groupID: testsutil.GenerateUUID(t, idProvider), | ||
groupID: testsutil.GenerateUUID(t), | ||
page: mfclients.Page{ | ||
Owner: adminEmail, | ||
}, | ||
|
@@ -1136,7 +1136,7 @@ func TestListMembers(t *testing.T) { | |
{ | ||
desc: "list clients with offset and limit", | ||
token: validToken, | ||
groupID: testsutil.GenerateUUID(t, idProvider), | ||
groupID: testsutil.GenerateUUID(t), | ||
page: mfclients.Page{ | ||
Offset: 6, | ||
Limit: nClients, | ||
|
@@ -1153,7 +1153,7 @@ func TestListMembers(t *testing.T) { | |
{ | ||
desc: "list clients with an invalid token", | ||
token: inValidToken, | ||
groupID: testsutil.GenerateUUID(t, idProvider), | ||
groupID: testsutil.GenerateUUID(t), | ||
page: mfclients.Page{ | ||
Owner: adminEmail, | ||
}, | ||
|
@@ -1185,7 +1185,7 @@ func TestListMembers(t *testing.T) { | |
{ | ||
desc: "list clients for an owner", | ||
token: validToken, | ||
groupID: testsutil.GenerateUUID(t, idProvider), | ||
groupID: testsutil.GenerateUUID(t), | ||
page: mfclients.Page{ | ||
Owner: adminEmail, | ||
}, | ||
|
Oops, something went wrong.