-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azurerm_postgresql_flexible_server_virtual_endpoint - validate with P…
…ostgresqlFlexibleServerVirtualEndpointIDInsensitively
- Loading branch information
1 parent
76b7ef2
commit 7af13d3
Showing
3 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
internal/services/postgres/validate/postgresql_flexible_server_virtual_endpoint_id.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package validate | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2023-06-01-preview/virtualendpoints" | ||
) | ||
|
||
func PostgresqlFlexibleServerVirtualEndpointIDInsensitively(input interface{}, key string) (warnings []string, errors []error) { | ||
v, ok := input.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected %q to be a string", key)) | ||
return | ||
} | ||
|
||
if _, err := virtualendpoints.ParseVirtualEndpointIDInsensitively(v); err != nil { | ||
errors = append(errors, err) | ||
} | ||
|
||
return | ||
} |
67 changes: 67 additions & 0 deletions
67
internal/services/postgres/validate/postgresql_flexible_server_virtual_endpoint_id_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package validate | ||
|
||
import "testing" | ||
|
||
func TestPostgresqlFlexibleServerVirtualEndpointID(t *testing.T) { | ||
cases := []struct { | ||
Input string | ||
Valid bool | ||
}{ | ||
{ | ||
Input: "", | ||
Valid: false, | ||
}, | ||
{ | ||
Input: "/", | ||
Valid: false, | ||
}, | ||
{ | ||
Input: "/subscriptions/", | ||
Valid: false, | ||
}, | ||
{ | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", | ||
Valid: false, | ||
}, | ||
{ | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", | ||
Valid: false, | ||
}, | ||
{ | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/", | ||
Valid: false, | ||
}, | ||
{ | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/flexibleServers/", | ||
Valid: false, | ||
}, | ||
{ | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/flexibleServers/server1", | ||
Valid: false, | ||
}, | ||
{ | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/flexibleServers/server1/virtualEndpoints/endpoint1", | ||
Valid: true, | ||
}, | ||
{ | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DBforPostgreSQL/flexibleServers/server1/virtualendpoints/endpoint1", | ||
Valid: true, | ||
}, | ||
{ | ||
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.DBFORPOSTGRESQL/FLEXIBLESERVERS/SERVER1/VIRTUALENDPOINTS/ENDPOINT1", | ||
Valid: true, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Logf("[DEBUG] Testing Value %s", tc.Input) | ||
_, errors := PostgresqlFlexibleServerVirtualEndpointIDInsensitively(tc.Input, "test") | ||
valid := len(errors) == 0 | ||
|
||
if tc.Valid != valid { | ||
t.Fatalf("Expected %t but got %t", tc.Valid, valid) | ||
} | ||
} | ||
} |