2021-07-21 17:03:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2021-09-14 12:11:07 +00:00
|
|
|
"context"
|
2021-07-21 17:03:10 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestUserDelete(t *testing.T) {
|
2021-09-15 19:27:53 +00:00
|
|
|
_, ds := runServerWithMockedDS(t)
|
2021-07-21 17:03:10 +00:00
|
|
|
|
2021-09-14 12:11:07 +00:00
|
|
|
ds.UserByEmailFunc = func(ctx context.Context, email string) (*fleet.User, error) {
|
2021-07-21 17:03:10 +00:00
|
|
|
return &fleet.User{
|
|
|
|
|
ID: 42,
|
|
|
|
|
Name: "test1",
|
|
|
|
|
Email: "user1@test.com",
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deletedUser := uint(0)
|
|
|
|
|
|
2021-09-14 12:11:07 +00:00
|
|
|
ds.DeleteUserFunc = func(ctx context.Context, id uint) error {
|
2021-07-21 17:03:10 +00:00
|
|
|
deletedUser = id
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, "", runAppForTest(t, []string{"user", "delete", "--email", "user1@test.com"}))
|
|
|
|
|
assert.Equal(t, uint(42), deletedUser)
|
|
|
|
|
}
|