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 authored and thisisnotashwin committed Jun 2, 2023
1 parent 725f45b commit bc9dd17
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
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 @@ -236,6 +236,41 @@ func TestControllerNamespaces(t *testing.T) {
require.Equal(r, "partitionName", exportedServicesConfigEntry.Services[0].Consumers[0].Partition)
require.Equal(r, "peerName", exportedServicesConfigEntry.Services[0].Consumers[1].Peer)
require.Equal(r, "groupName", exportedServicesConfigEntry.Services[0].Consumers[2].SamenessGroup)

// 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 @@ -282,6 +317,9 @@ func TestControllerNamespaces(t *testing.T) {
patchPartition := "destination"
k8s.RunKubectl(t, ctx.KubectlOptions(t), "patch", "-n", KubeNS, "exportedservices", "default", "-p", fmt.Sprintf(`{"spec": {"services": [{"name": "frontend", "namespace": "frontend", "consumers": [{"partition": "%s"}, {"peer": "peerName"}, {"samenessGroup": "groupName"}]}]}}`, patchPartition), "--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 @@ -362,6 +400,13 @@ func TestControllerNamespaces(t *testing.T) {
exportedServicesConfigEntry, ok := entry.(*api.ExportedServicesConfigEntry)
require.True(r, ok, "could not cast to ExportedServicesConfigEntry")
require.Equal(r, patchPartition, exportedServicesConfigEntry.Services[0].Consumers[0].Partition)

// 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 @@ -400,6 +445,9 @@ func TestControllerNamespaces(t *testing.T) {
logger.Log(t, "deleting exported-services custom resource")
k8s.RunKubectl(t, ctx.KubectlOptions(t), "delete", "-n", KubeNS, "exportedservices", "default")

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 @@ -456,6 +504,11 @@ func TestControllerNamespaces(t *testing.T) {
_, _, err = consulClient.ConfigEntries().Get(api.ExportedServices, "default", 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
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 @@ -505,6 +505,11 @@ func TestController(t *testing.T) {
_, _, 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")

// 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
3 changes: 2 additions & 1 deletion acceptance/tests/fixtures/bases/crds-oss/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ resources:
- servicesplitter.yaml
- terminatinggateway.yaml
- jwtprovider.yaml
- exportedservices.yaml
- exportedservices.yaml
- controlplanerequestlimit.yaml

0 comments on commit bc9dd17

Please sign in to comment.