Skip to content

Commit

Permalink
add namespace acceptance tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Bond <danbond@protonmail.com>
  • Loading branch information
loshz committed Jun 2, 2023
1 parent 647006b commit b10fa5a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
53 changes: 53 additions & 0 deletions acceptance/tests/config-entries/config_entries_namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,41 @@ func TestControllerNamespaces(t *testing.T) {
require.Equal(r, "certFile", terminatingGatewayEntry.Services[0].CertFile)
require.Equal(r, "keyFile", terminatingGatewayEntry.Services[0].KeyFile)
require.Equal(r, "sni", terminatingGatewayEntry.Services[0].SNI)

// control-plane-request-limit
entry, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "control-plane-request-limit", nil)
require.NoError(r, err)
rateLimitIPConfigEntry, ok := entry.(*api.RateLimitIPConfigEntry)
require.True(r, ok, "could not cast to RateLimitIPConfigEntry")
require.Equal(t, "permissive", rateLimitIPConfigEntry.Mode)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ACL.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ACL.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Catalog.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Catalog.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ConfigEntry.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ConfigEntry.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ConnectCA.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ConnectCA.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Coordinate.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Coordinate.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.DiscoveryChain.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.DiscoveryChain.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Health.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Health.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Intention.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Intention.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.KV.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.KV.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Tenancy.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Tenancy.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.PreparedQuery.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.PreparedQuery.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Session.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Session.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Txn.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Txn.WriteRate, 100.0)
})
}

Expand Down Expand Up @@ -258,6 +293,9 @@ func TestControllerNamespaces(t *testing.T) {
patchSNI := "patch-sni"
k8s.RunKubectl(t, ctx.KubectlOptions(t), "patch", "-n", KubeNS, "terminatinggateway", "terminating-gateway", "-p", fmt.Sprintf(`{"spec": {"services": [{"name":"name","caFile":"caFile","certFile":"certFile","keyFile":"keyFile","sni":"%s"}]}}`, patchSNI), "--type=merge")

logger.Log(t, "patching control-plane-request-limit custom resource")
k8s.RunKubectl(t, ctx.KubectlOptions(t), "patch", "-n", KubeNS, "controlplanerequestlimit", "control-plane-request-limit", "-p", `{"spec": {"mode": "disabled"}}`, "--type=merge")

counter := &retry.Counter{Count: 20, Wait: 2 * time.Second}
retry.RunWith(counter, t, func(r *retry.R) {
// service-defaults
Expand Down Expand Up @@ -331,6 +369,13 @@ func TestControllerNamespaces(t *testing.T) {
terminatingGatewayEntry, ok := entry.(*api.TerminatingGatewayConfigEntry)
require.True(r, ok, "could not cast to TerminatingGatewayConfigEntry")
require.Equal(r, patchSNI, terminatingGatewayEntry.Services[0].SNI)

// control-plane-request-limit
entry, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "control-plane-request-limit", nil)
require.NoError(r, err)
rateLimitIPConfigEntry, ok := entry.(*api.RateLimitIPConfigEntry)
require.True(r, ok, "could not cast to RateLimitIPConfigEntry")
require.Equal(r, rateLimitIPConfigEntry.Mode, "disabled")
})
}

Expand Down Expand Up @@ -366,6 +411,9 @@ func TestControllerNamespaces(t *testing.T) {
logger.Log(t, "deleting terminating-gateway custom resource")
k8s.RunKubectl(t, ctx.KubectlOptions(t), "delete", "-n", KubeNS, "terminatinggateway", "terminating-gateway")

logger.Log(t, "deleting control-plane-request-limit custom resource")
k8s.RunKubectl(t, ctx.KubectlOptions(t), "delete", "-n", KubeNS, "controlplanerequestlimit", "control-plane-request-limit")

counter := &retry.Counter{Count: 20, Wait: 2 * time.Second}
retry.RunWith(counter, t, func(r *retry.R) {
// service-defaults
Expand Down Expand Up @@ -417,6 +465,11 @@ func TestControllerNamespaces(t *testing.T) {
_, _, err = consulClient.ConfigEntries().Get(api.IngressGateway, "terminating-gateway", queryOpts)
require.Error(r, err)
require.Contains(r, err.Error(), "404 (Config entry not found")

// control-plane-request-limit
_, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "control-plane-request-limit", nil)
require.Error(r, err)
require.Contains(r, err.Error(), "404 (Config entry not found")
})
}
})
Expand Down
5 changes: 5 additions & 0 deletions acceptance/tests/config-entries/config_entries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ func TestController(t *testing.T) {
_, _, err = consulClient.ConfigEntries().Get(api.TerminatingGateway, "terminating-gateway", nil)
require.Error(r, err)
require.Contains(r, err.Error(), "404 (Config entry not found")

// control-plane-request-limit
_, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "control-plane-request-limit", nil)
require.Error(r, err)
require.Contains(r, err.Error(), "404 (Config entry not found")
})
}
})
Expand Down
2 changes: 2 additions & 0 deletions acceptance/tests/fixtures/bases/crds-oss/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ resources:
- servicerouter.yaml
- servicesplitter.yaml
- terminatinggateway.yaml
- jwtprovider.yaml
- controlplanerequestlimit.yaml

0 comments on commit b10fa5a

Please sign in to comment.