Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/config/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (u *ConfigUpdater) UpdateDbConfig(ctx context.Context, projectRef string, c
}

func (u *ConfigUpdater) UpdateDbNetworkRestrictionsConfig(ctx context.Context, projectRef string, n networkRestrictions, filter ...func(string) bool) error {
if !n.Enabled {
return nil
}
networkRestrictionsConfig, err := u.client.V1GetNetworkRestrictionsWithResponse(ctx, projectRef)
if err != nil {
return errors.Errorf("failed to read network restrictions config: %w", err)
Expand Down
35 changes: 35 additions & 0 deletions pkg/config/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,41 @@ func TestUpdateDbConfig(t *testing.T) {
})
}

func TestUpdateDbNetworkRestrictionsConfig(t *testing.T) {
server := "http://localhost"
client, err := v1API.NewClientWithResponses(server)
require.NoError(t, err)

t.Run("skips update if disabled locally", func(t *testing.T) {
updater := NewConfigUpdater(*client)
// Run test
err := updater.UpdateDbNetworkRestrictionsConfig(context.Background(), "test-project", networkRestrictions{})
// Check result
assert.NoError(t, err)
assert.False(t, gock.HasUnmatchedRequest())
})

t.Run("returns error on 400 when enabled locally", func(t *testing.T) {
updater := NewConfigUpdater(*client)
// Setup mock server
defer gock.Off()
gock.New(server).
Get("/v1/projects/test-project/network-restrictions").
Reply(http.StatusBadRequest).
JSON(map[string]any{
"message": "project not allowed to set up network restrictions",
})
// Run test
err := updater.UpdateDbNetworkRestrictionsConfig(context.Background(), "test-project", networkRestrictions{
Enabled: true,
})
// Check result
assert.Error(t, err)
assert.Contains(t, err.Error(), "unexpected status 400")
assert.True(t, gock.IsDone())
})
}

func TestUpdateExperimentalConfig(t *testing.T) {
server := "http://localhost"
client, err := v1API.NewClientWithResponses(server)
Expand Down