Document possible values of schema fields (#455)

* Document possible values of schema fields

* Change from possible to supported
This commit is contained in:
João Palet 2024-07-09 13:14:38 +01:00 committed by GitHub
parent 846a2ba181
commit 3fb28d1248
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 76 additions and 15 deletions

View file

@ -76,3 +76,17 @@ func SimplifyBackupSchedule(schedule string) string {
})
return simplifiedSchedule
}
func SupportedValuesDocumentation(values []string) string {
if len(values) == 0 {
return ""
}
return "Supported values are: " + strings.Join(quoteValues(values), ", ") + "."
}
func quoteValues(values []string) []string {
for i, value := range values {
values[i] = fmt.Sprintf("`%s`", value)
}
return values
}

View file

@ -192,3 +192,36 @@ func TestSimplifyBackupSchedule(t *testing.T) {
})
}
}
func TestSupportedValuesDocumentation(t *testing.T) {
tests := []struct {
description string
values []string
expected string
}{
{
"empty values",
[]string{},
"",
},
{
"single value",
[]string{"value"},
"Supported values are: `value`.",
},
{
"multiple values",
[]string{"value1", "value2", "value3"},
"Supported values are: `value1`, `value2`, `value3`.",
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
output := SupportedValuesDocumentation(tt.values)
if output != tt.expected {
t.Fatalf("Data does not match: %s", output)
}
})
}
}