Skip to content

Commit e5820b3

Browse files
Copilottobio
andcommitted
Add namespace validator and fix invalid test namespaces
Co-authored-by: tobio <[email protected]>
1 parent 0b86113 commit e5820b3

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

internal/kibana/synthetics/acc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ resource "elasticstack_kibana_synthetics_monitor" "%s" {
6060
resource "elasticstack_kibana_synthetics_monitor" "%s" {
6161
name = "TestHttpMonitorResource - %s"
6262
space_id = "testacc"
63-
namespace = "test-namespace"
63+
namespace = "testnamespace"
6464
schedule = 5
6565
private_locations = [elasticstack_kibana_synthetics_private_location.%s.label]
6666
enabled = true
@@ -890,7 +890,7 @@ func TestSyntheticMonitorHTTPResourceWithNamespace(t *testing.T) {
890890
resource.TestCheckResourceAttrSet(httpMonitorId, "id"),
891891
resource.TestCheckResourceAttr(httpMonitorId, "name", "TestHttpMonitorResource - "+name),
892892
resource.TestCheckResourceAttr(httpMonitorId, "space_id", "testacc"),
893-
resource.TestCheckResourceAttr(httpMonitorId, "namespace", "test-namespace"),
893+
resource.TestCheckResourceAttr(httpMonitorId, "namespace", "testnamespace"),
894894
resource.TestCheckResourceAttr(httpMonitorId, "schedule", "5"),
895895
resource.TestCheckResourceAttr(httpMonitorId, "enabled", "true"),
896896
resource.TestCheckResourceAttr(httpMonitorId, "http.url", "http://localhost:5601"),

internal/kibana/synthetics/parameter/schema_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Test_roundtrip(t *testing.T) {
1818
{
1919
name: "only required fields",
2020
id: "id-1",
21-
namespaces: []string{"ns-1"},
21+
namespaces: []string{"ns1"},
2222
request: kboapi.SyntheticsParameterRequest{
2323
Key: "key-1",
2424
Value: "value-1",
@@ -39,7 +39,7 @@ func Test_roundtrip(t *testing.T) {
3939
{
4040
name: "only description",
4141
id: "id-3",
42-
namespaces: []string{"ns-3"},
42+
namespaces: []string{"ns3"},
4343
request: kboapi.SyntheticsParameterRequest{
4444
Key: "key-3",
4545
Value: "value-3",
@@ -49,7 +49,7 @@ func Test_roundtrip(t *testing.T) {
4949
{
5050
name: "only tags",
5151
id: "id-4",
52-
namespaces: []string{"ns-4"},
52+
namespaces: []string{"ns4"},
5353
request: kboapi.SyntheticsParameterRequest{
5454
Key: "key-4",
5555
Value: "value-4",
@@ -59,7 +59,7 @@ func Test_roundtrip(t *testing.T) {
5959
{
6060
name: "all namespaces",
6161
id: "id-5",
62-
namespaces: []string{"ns-5"},
62+
namespaces: []string{"ns5"},
6363
request: kboapi.SyntheticsParameterRequest{
6464
Key: "key-5",
6565
Value: "value-5",

internal/kibana/synthetics/schema.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"regexp"
78
"strconv"
89

910
"github.com/disaster37/go-kibana-rest/v8/kbapi"
@@ -159,6 +160,12 @@ func monitorConfigSchema() schema.Schema {
159160
stringplanmodifier.UseStateForUnknown(),
160161
stringplanmodifier.RequiresReplace(),
161162
},
163+
Validators: []validator.String{
164+
stringvalidator.RegexMatches(
165+
regexp.MustCompile(`^[^*\\/?\"<>|\s,#:-]*$`),
166+
"namespace must not contain any of the following characters: *, \\, /, ?, \", <, >, |, whitespace, ,, #, :, or -",
167+
),
168+
},
162169
Computed: true,
163170
},
164171
"schedule": schema.Int64Attribute{

0 commit comments

Comments
 (0)