|
| 1 | +package postgres |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/conductorone/baton-postgresql/pkg/testutil" |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | +) |
| 10 | + |
| 11 | +func TestFunctionGrantRevoke(t *testing.T) { |
| 12 | + ctx := context.Background() |
| 13 | + |
| 14 | + container := testutil.SetupPostgresContainer(ctx, t) |
| 15 | + |
| 16 | + client, err := New(ctx, container.Dsn()) |
| 17 | + assert.NoError(t, err) |
| 18 | + |
| 19 | + // Is grant true |
| 20 | + err = client.GrantFunction(ctx, "public", "get_test_item_count", container.Role(), Execute.Name(), true) |
| 21 | + assert.NoError(t, err) |
| 22 | + |
| 23 | + err = client.RevokeFunction(ctx, "public", "get_test_item_count", container.Role(), Execute.Name(), true) |
| 24 | + assert.NoError(t, err) |
| 25 | + |
| 26 | + // is grant false |
| 27 | + err = client.GrantFunction(ctx, "public", "get_test_item_count", container.Role(), Execute.Name(), false) |
| 28 | + assert.NoError(t, err) |
| 29 | + |
| 30 | + err = client.RevokeFunction(ctx, "public", "get_test_item_count", container.Role(), Execute.Name(), false) |
| 31 | + assert.NoError(t, err) |
| 32 | + |
| 33 | + // revoke without grant |
| 34 | + err = client.RevokeFunction(ctx, "public", "get_test_item_count", container.Role(), Execute.Name(), false) |
| 35 | + assert.NoError(t, err) |
| 36 | + |
| 37 | + err = client.RevokeFunction(ctx, "public", "get_test_item_count", container.Role(), Execute.Name(), true) |
| 38 | + assert.NoError(t, err) |
| 39 | +} |
0 commit comments