Skip to content

Commit

Permalink
MF-249 - Use const
Browse files Browse the repository at this point in the history
Signed-off-by: zzokki81 <zoran.rebic@outlook.com>
  • Loading branch information
zzokki81 committed Aug 4, 2023
1 parent 907d77d commit a959a78
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/sdk/go/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ const (
invalidEmail = "userexample.com"
userEmail = "user@example.com"
validPass = "validPass"
registerUser = "register@example.com"
)

var (
passRegex = regexp.MustCompile("^.{8,}$")
user = users.User{Email: userEmail, ID: "574106f7-030e-4881-8ab0-151195c29f94", Password: validPass, Status: "enabled"}
admin = users.User{Email: adminEmail, ID: "371106m2-131g-5286-2mc1-540295c29f95", Password: validPass, Status: "enabled"}
usersList = []users.User{admin, user}
usersList = []users.User{admin, user}
)

func newUserService() users.Service {
Expand Down Expand Up @@ -62,7 +63,7 @@ func TestCreateUser(t *testing.T) {
TLSVerification: false,
}

sdkUser := sdk.User{Email: "new-user@example.com", Password: "password"}
sdkUser := sdk.User{Email: registerUser, Password: validPass}

token, err := svc.Login(context.Background(), admin)
require.Nil(t, err, fmt.Sprintf("unexpected error login: %s", err))
Expand Down Expand Up @@ -94,13 +95,13 @@ func TestCreateUser(t *testing.T) {
},
{
desc: "create user with empty password",
user: sdk.User{Email: "user2@example.com", Password: ""},
user: sdk.User{Email: registerUser, Password: ""},
token: token,
err: createError(sdk.ErrFailedCreation, http.StatusBadRequest),
},
{
desc: "create user without password",
user: sdk.User{Email: "user2@example.com"},
user: sdk.User{Email: registerUser},
token: token,
err: createError(sdk.ErrFailedCreation, http.StatusBadRequest),
},
Expand Down Expand Up @@ -134,7 +135,7 @@ func TestRegisterUser(t *testing.T) {
TLSVerification: false,
}

sdkUser := sdk.User{Email: "user1@example.com", Password: "password"}
sdkUser := sdk.User{Email: "user_register@example.com", Password: validPass}

mainfluxSDK := sdk.NewSDK(sdkConf)
cases := []struct {
Expand All @@ -159,12 +160,12 @@ func TestRegisterUser(t *testing.T) {
},
{
desc: "register user with empty password",
user: sdk.User{Email: "user2@example.com", Password: ""},
user: sdk.User{Email: registerUser, Password: ""},
err: createError(sdk.ErrFailedCreation, http.StatusBadRequest),
},
{
desc: "register user without password",
user: sdk.User{Email: "user2@example.com"},
user: sdk.User{Email: registerUser},
err: createError(sdk.ErrFailedCreation, http.StatusBadRequest),
},
{
Expand Down Expand Up @@ -215,7 +216,7 @@ func TestCreateToken(t *testing.T) {
},
{
desc: "create token for non existing user",
user: sdk.User{Email: "user2@example.com", Password: "password"},
user: sdk.User{Email: registerUser, Password: "password"},
token: "",
err: createError(sdk.ErrFailedCreation, http.StatusUnauthorized),
},
Expand Down

0 comments on commit a959a78

Please sign in to comment.