Add sqlserverflex instance (#381)
* Draft implementation sqlserverflex instance * Finish implementation * Fix acc test * Changes after review
This commit is contained in:
parent
6db3a550e6
commit
335e1cabb6
18 changed files with 2400 additions and 104 deletions
|
|
@ -2,6 +2,8 @@ package utils
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
|
||||
|
|
@ -60,3 +62,17 @@ func ListValuetoStringSlice(list basetypes.ListValue) ([]string, error) {
|
|||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Remove leading 0s from backup schedule numbers (e.g. "00 00 * * *" becomes "0 0 * * *")
|
||||
// Needed as the API does it internally and would otherwise cause inconsistent result in Terraform
|
||||
func SimplifyBackupSchedule(schedule string) string {
|
||||
regex := regexp.MustCompile(`0+\d+`) // Matches series of one or more zeros followed by a series of one or more digits
|
||||
simplifiedSchedule := regex.ReplaceAllStringFunc(schedule, func(match string) string {
|
||||
simplified := strings.TrimLeft(match, "0")
|
||||
if simplified == "" {
|
||||
simplified = "0"
|
||||
}
|
||||
return simplified
|
||||
})
|
||||
return simplifiedSchedule
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,3 +120,75 @@ func TestListValuetoStrSlice(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimplifyBackupSchedule(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
"simple schedule",
|
||||
"0 0 * * *",
|
||||
"0 0 * * *",
|
||||
},
|
||||
{
|
||||
"schedule with leading zeros",
|
||||
"00 00 * * *",
|
||||
"0 0 * * *",
|
||||
},
|
||||
{
|
||||
"schedule with leading zeros 2",
|
||||
"00 001 * * *",
|
||||
"0 1 * * *",
|
||||
},
|
||||
{
|
||||
"schedule with leading zeros 3",
|
||||
"00 0010 * * *",
|
||||
"0 10 * * *",
|
||||
},
|
||||
{
|
||||
"simple schedule with slash",
|
||||
"0 0/6 * * *",
|
||||
"0 0/6 * * *",
|
||||
},
|
||||
{
|
||||
"schedule with leading zeros and slash",
|
||||
"00 00/6 * * *",
|
||||
"0 0/6 * * *",
|
||||
},
|
||||
{
|
||||
"schedule with leading zeros and slash 2",
|
||||
"00 001/06 * * *",
|
||||
"0 1/6 * * *",
|
||||
},
|
||||
{
|
||||
"simple schedule with comma",
|
||||
"0 10,15 * * *",
|
||||
"0 10,15 * * *",
|
||||
},
|
||||
{
|
||||
"schedule with leading zeros and comma",
|
||||
"0 010,0015 * * *",
|
||||
"0 10,15 * * *",
|
||||
},
|
||||
{
|
||||
"simple schedule with comma and slash",
|
||||
"0 0-11/10 * * *",
|
||||
"0 0-11/10 * * *",
|
||||
},
|
||||
{
|
||||
"schedule with leading zeros, comma, and slash",
|
||||
"00 000-011/010 * * *",
|
||||
"0 0-11/10 * * *",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
output := SimplifyBackupSchedule(tt.input)
|
||||
if output != tt.expected {
|
||||
t.Fatalf("Data does not match: %s", output)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue