1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-28 13:48:49 +08:00

Fix blinker tests (#193)

* Fix blinker tests

Signed-off-by: Dušan Borovčanin <borovcanindusan1@gmail.com>

* Add protobuf generated files to .gitignore

Signed-off-by: Dušan Borovčanin <borovcanindusan1@gmail.com>
This commit is contained in:
Dušan Borovčanin 2018-03-20 09:14:54 +01:00 committed by Dejan Mijić
parent 2c1c94af9b
commit 924f6f120a
4 changed files with 31 additions and 26 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
build build
*.pb.go

View File

@ -30,17 +30,18 @@ func newService() manager.Service {
func TestRegister(t *testing.T) { func TestRegister(t *testing.T) {
svc := newService() svc := newService()
cases := map[string]struct { cases := []struct {
desc string
user manager.User user manager.User
err error err error
}{ }{
"register new user": {user, nil}, {"register new user", user, nil},
"register existing user": {user, manager.ErrConflict}, {"register existing user", user, manager.ErrConflict},
} }
for desc, tc := range cases { for _, tc := range cases {
err := svc.Register(tc.user) err := svc.Register(tc.user)
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err)) assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
} }
} }
@ -311,22 +312,23 @@ func TestDisconnect(t *testing.T) {
svc.Connect(key, chanId, clientId) svc.Connect(key, chanId, clientId)
cases := map[string]struct { cases := []struct {
desc string
key string key string
chanId string chanId string
clientId string clientId string
err error err error
}{ }{
"disconnect connected client": {key, chanId, clientId, nil}, {"disconnect connected client", key, chanId, clientId, nil},
"disconnect disconnected client": {key, chanId, clientId, manager.ErrNotFound}, {"disconnect disconnected client", key, chanId, clientId, manager.ErrNotFound},
"disconnect client with wrong credentials": {wrong, chanId, clientId, manager.ErrUnauthorizedAccess}, {"disconnect client with wrong credentials", wrong, chanId, clientId, manager.ErrUnauthorizedAccess},
"disconnect client from non-existing channel": {key, wrong, clientId, manager.ErrNotFound}, {"disconnect client from non-existing channel", key, wrong, clientId, manager.ErrNotFound},
"disconnect non-existing client": {key, chanId, wrong, manager.ErrNotFound}, {"disconnect non-existing client", key, chanId, wrong, manager.ErrNotFound},
} }
for desc, tc := range cases { for _, tc := range cases {
err := svc.Disconnect(tc.key, tc.chanId, tc.clientId) err := svc.Disconnect(tc.key, tc.chanId, tc.clientId)
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err)) assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
} }
} }

View File

@ -192,22 +192,23 @@ func TestChannelDisconnect(t *testing.T) {
chanRepo.Connect(email, chanId, client.ID) chanRepo.Connect(email, chanId, client.ID)
cases := map[string]struct { cases := []struct {
desc string
owner string owner string
chanId string chanId string
clientId string clientId string
err error err error
}{ }{
"connected client": {email, chanId, client.ID, nil}, {"connected client", email, chanId, client.ID, nil},
"non-connected client": {email, chanId, client.ID, manager.ErrNotFound}, {"non-connected client", email, chanId, client.ID, manager.ErrNotFound},
"non-existing user": {wrong, chanId, client.ID, manager.ErrNotFound}, {"non-existing user", wrong, chanId, client.ID, manager.ErrNotFound},
"non-existing channel": {email, wrong, client.ID, manager.ErrNotFound}, {"non-existing channel", email, wrong, client.ID, manager.ErrNotFound},
"non-existing client": {email, chanId, wrong, manager.ErrNotFound}, {"non-existing client", email, chanId, wrong, manager.ErrNotFound},
} }
for desc, tc := range cases { for _, tc := range cases {
err := chanRepo.Disconnect(tc.owner, tc.chanId, tc.clientId) err := chanRepo.Disconnect(tc.owner, tc.chanId, tc.clientId)
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err)) assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
} }
} }

View File

@ -12,19 +12,20 @@ import (
func TestUserSave(t *testing.T) { func TestUserSave(t *testing.T) {
email := "user-save@example.com" email := "user-save@example.com"
cases := map[string]struct { cases := []struct {
desc string
user manager.User user manager.User
err error err error
}{ }{
"new user": {manager.User{email, "pass"}, nil}, {"new user", manager.User{email, "pass"}, nil},
"duplicate user": {manager.User{email, "pass"}, manager.ErrConflict}, {"duplicate user", manager.User{email, "pass"}, manager.ErrConflict},
} }
repo := postgres.NewUserRepository(db) repo := postgres.NewUserRepository(db)
for desc, tc := range cases { for _, tc := range cases {
err := repo.Save(tc.user) err := repo.Save(tc.user)
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err)) assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
} }
} }