The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/pkg/cmd/grafana-cli/commands/reset_password_command_test.go

55 lines
983 B

package commands
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/services/user/usertest"
)
func TestResetPassword(t *testing.T) {
tests := map[string]struct {
UserID int64
IsAdmin bool
ExpectErr error
}{
"basic success": {
DefaultAdminUserId,
true,
nil,
},
"default user is not an admin": {
DefaultAdminUserId,
false,
ErrMustBeAdmin,
},
"random user is not an admin": {
11,
false,
ErrMustBeAdmin,
},
"random user is an admin": {
11,
true,
nil,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
svc := &usertest.FakeUserService{}
svc.ExpectedUser = &user.User{
IsAdmin: test.IsAdmin,
}
err := resetPassword(test.UserID, "s00pers3cure!", svc)
if test.ExpectErr != nil {
require.EqualError(t, err, test.ExpectErr.Error())
} else {
require.NoError(t, err)
}
})
}
}