Skip to content

Commit

Permalink
Update to latest gateway API (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
trobert authored Aug 19, 2024
1 parent 04d96e1 commit 351294b
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 337 deletions.
26 changes: 13 additions & 13 deletions client/gateway_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (

var aVClusterResource = resource.Resource{
Version: "gateway/v2",
Kind: "VClusters",
Kind: "VirtualCluster",
Name: "vcluster1",
Metadata: map[string]interface{}{"name": "vcluster1"},
Json: []byte(`{"apiVersion":"v1","kind":"VClusters","metadata":{"name":"vcluster1"},"spec":{"prefix":"vcluster1_"}}`),
Json: []byte(`{"apiVersion":"v1","kind":"VirtualCluster","metadata":{"name":"vcluster1"},"spec":{"prefix":"vcluster1_"}}`),
}

func TestGwApplyShouldWork(t *testing.T) {
Expand All @@ -35,7 +35,7 @@ func TestGwApplyShouldWork(t *testing.T) {

httpmock.RegisterMatcherResponderWithQuery(
"PUT",
"http://baseUrl/gateway/v2/vclusters",
"http://baseUrl/gateway/v2/virtual-cluster",
nil,
httpmock.HeaderIs("Authorization", "Basic YWRtaW46Y29uZHVrdG9y").
And(httpmock.HeaderIs("X-CDK-CLIENT", "CLI/unknown")).
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestGwApplyWithDryModeShouldWork(t *testing.T) {

httpmock.RegisterMatcherResponderWithQuery(
"PUT",
"http://baseUrl/gateway/v2/vclusters",
"http://baseUrl/gateway/v2/virtual-cluster",
"dryMode=true",
httpmock.HeaderIs("Authorization", "Basic YWRtaW46Y29uZHVrdG9y").
And(httpmock.BodyContainsBytes(aVClusterResource.Json)),
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestGwApplyShouldFailIfNo2xx(t *testing.T) {

httpmock.RegisterMatcherResponderWithQuery(
"PUT",
"http://baseUrl/gateway/v2/vclusters",
"http://baseUrl/gateway/v2/virtual-cluster",
nil,
httpmock.HeaderIs("Authorization", "Basic YWRtaW46Y29uZHVrdG9y").
And(httpmock.BodyContainsBytes(aVClusterResource.Json)),
Expand Down Expand Up @@ -145,14 +145,14 @@ func TestGwGetShouldWork(t *testing.T) {

httpmock.RegisterMatcherResponderWithQuery(
"GET",
"http://baseUrl/gateway/v2/vclusters",
"http://baseUrl/gateway/v2/virtual-cluster",
nil,
httpmock.HeaderIs("Authorization", "Basic YWRtaW46Y29uZHVrdG9y").
And(httpmock.HeaderIs("X-CDK-CLIENT", "CLI/unknown")),
responder,
)

vClusterKind := gatewayClient.GetKinds()["VClusters"]
vClusterKind := gatewayClient.GetKinds()["VirtualCluster"]
result, err := gatewayClient.Get(&vClusterKind, []string{}, nil)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -184,13 +184,13 @@ func TestGwGetShouldFailIfN2xx(t *testing.T) {

httpmock.RegisterMatcherResponderWithQuery(
"GET",
"http://baseUrl/gateway/v2/vclusters",
"http://baseUrl/gateway/v2/virtual-cluster",
nil,
httpmock.HeaderIs("Authorization", "Basic changeme"),
responder,
)

vClusterKind := gatewayClient.GetKinds()["VClusters"]
vClusterKind := gatewayClient.GetKinds()["VirtualCluster"]
_, err = gatewayClient.Get(&vClusterKind, []string{}, nil)
if err == nil {
t.Failed()
Expand Down Expand Up @@ -219,14 +219,14 @@ func TestGwDeleteShouldWork(t *testing.T) {

httpmock.RegisterMatcherResponderWithQuery(
"DELETE",
"http://baseUrl/gateway/v2/vclusters/vcluster1",
"http://baseUrl/gateway/v2/virtual-cluster/vcluster1",
nil,
httpmock.HeaderIs("Authorization", "Basic YWRtaW46Y29uZHVrdG9y").
And(httpmock.HeaderIs("X-CDK-CLIENT", "CLI/unknown")),
responder,
)

vClusters := gatewayClient.GetKinds()["VClusters"]
vClusters := gatewayClient.GetKinds()["VirtualCluster"]
err = gatewayClient.Delete(&vClusters, []string{}, "vcluster1")
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -255,13 +255,13 @@ func TestGwDeleteShouldFailOnNot2XX(t *testing.T) {

httpmock.RegisterMatcherResponderWithQuery(
"DELETE",
"http://baseUrl/gateway/v2/vclusters/vcluster1",
"http://baseUrl/gateway/v2/virtual-cluster/vcluster1",
nil,
httpmock.HeaderIs("Authorization", "Basic YWRtaW46Y29uZHVrdG9y"),
responder,
)

vClusterKind := gatewayClient.GetKinds()["VClusters"]
vClusterKind := gatewayClient.GetKinds()["VirtualCluster"]
err = gatewayClient.Delete(&vClusterKind, []string{}, "vcluster1")
if err == nil {
t.Fail()
Expand Down
40 changes: 20 additions & 20 deletions docker/initializerGw.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"httpRequest": {
"method": "Get",
"path": "/gateway/v2/vclusters/vcluster1",
"path": "/gateway/v2/virtual-cluster/vcluster1",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -20,7 +20,7 @@
{
"httpRequest": {
"method": "Get",
"path": "/gateway/v2/gateway-groups",
"path": "/gateway/v2/group",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -38,7 +38,7 @@
{
"httpRequest": {
"method": "Get",
"path": "/gateway/v2/gateway-groups/g1",
"path": "/gateway/v2/group/g1",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -56,7 +56,7 @@
{
"httpRequest": {
"method": "Get",
"path": "/gateway/v2/vclusters",
"path": "/gateway/v2/virtual-cluster",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -74,7 +74,7 @@
{
"httpRequest": {
"method": "Put",
"path": "/gateway/v2/vclusters",
"path": "/gateway/v2/virtual-cluster",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -92,7 +92,7 @@
{
"httpRequest": {
"method": "Delete",
"path": "/gateway/v2/vclusters/vcluster1",
"path": "/gateway/v2/virtual-cluster/vcluster1",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -110,7 +110,7 @@
{
"httpRequest": {
"method": "Put",
"path": "/gateway/v2/alias-topics",
"path": "/gateway/v2/alias-topic",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -128,7 +128,7 @@
{
"httpRequest": {
"method": "Put",
"path": "/gateway/v2/concentration-rules",
"path": "/gateway/v2/concentration-rule",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -146,7 +146,7 @@
{
"httpRequest": {
"method": "Put",
"path": "/gateway/v2/gateway-groups",
"path": "/gateway/v2/group",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -164,7 +164,7 @@
{
"httpRequest": {
"method": "Put",
"path": "/gateway/v2/service-accounts",
"path": "/gateway/v2/service-account",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -182,7 +182,7 @@
{
"httpRequest": {
"method": "Put",
"path": "/gateway/v2/interceptors",
"path": "/gateway/v2/interceptor",
"headers": {
"Authorization": "Basic YWRtaW46Y29uZHVrdG9y"
}
Expand All @@ -200,7 +200,7 @@
{
"httpRequest": {
"method": "GET",
"path": "/gateway/v2/alias-topics",
"path": "/gateway/v2/alias-topic",
"queryStringParameters": {
"vcluster": "mycluster1",
"showDefaults": "true",
Expand All @@ -223,7 +223,7 @@
{
"httpRequest": {
"method": "GET",
"path": "/gateway/v2/concentration-rules",
"path": "/gateway/v2/concentration-rule",
"queryStringParameters": {
"vcluster": "mycluster1",
"showDefaults": "true",
Expand All @@ -246,7 +246,7 @@
{
"httpRequest": {
"method": "GET",
"path": "/gateway/v2/service-accounts",
"path": "/gateway/v2/service-account",
"queryStringParameters": {
"vcluster": "mycluster1",
"showDefaults": "true",
Expand All @@ -269,7 +269,7 @@
{
"httpRequest": {
"method": "GET",
"path": "/gateway/v2/interceptors",
"path": "/gateway/v2/interceptor",
"queryStringParameters": {
"vcluster": "mycluster1",
"username": "me",
Expand All @@ -293,7 +293,7 @@
{
"httpRequest": {
"method": "Delete",
"path": "/gateway/v2/alias-topics",
"path": "/gateway/v2/alias-topic",
"body": {
"name": "aliastopicname",
"vCluster": "v1"
Expand All @@ -315,7 +315,7 @@
{
"httpRequest": {
"method": "Delete",
"path": "/gateway/v2/concentration-rules",
"path": "/gateway/v2/concentration-rule",
"body": {
"name": "cr1",
"vCluster": "v1"
Expand All @@ -337,7 +337,7 @@
{
"httpRequest": {
"method": "Delete",
"path": "/gateway/v2/service-accounts",
"path": "/gateway/v2/service-account",
"body": {
"name": "s1",
"vCluster": "v1"
Expand All @@ -359,7 +359,7 @@
{
"httpRequest": {
"method": "Delete",
"path": "/gateway/v2/service-accounts",
"path": "/gateway/v2/service-account",
"body": {
"name": "s1",
"vCluster": "v1"
Expand All @@ -381,7 +381,7 @@
{
"httpRequest": {
"method": "Delete",
"path": "/gateway/v2/interceptors/i1",
"path": "/gateway/v2/interceptor/i1",
"body": {
"username": "me",
"group": "g1",
Expand Down
Loading

0 comments on commit 351294b

Please sign in to comment.