Skip to content

Commit

Permalink
Add integration test to verify old CR versions of the API
Browse files Browse the repository at this point in the history
  • Loading branch information
pubudu538 committed Mar 21, 2024
1 parent 550ba22 commit a0e6f15
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
#
# WSO2 LLC. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

apiVersion: dp.wso2.com/v1alpha1
kind: API
metadata:
name: verify-old-apis
namespace: gateway-integration-test-infra
spec:
apiName: Backend with no basepath
apiType: REST
apiVersion: v1
basePath: /verify-old-apis/v1
#definitionFileRef: definition-file
production:
- httpRouteRefs:
- prod-httproute-1
organization: wso2-org
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: prod-httproute-1
namespace: gateway-integration-test-infra
spec:
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: wso2-apk-default
namespace: apk-integration-test
sectionName: httpslistener
hostnames:
- prod-api.test.gw.wso2.com
rules:
- matches:
- path:
type: PathPrefix
value: /
method: GET
backendRefs:
- group: dp.wso2.com
kind: Backend
name: infra-backend-v1
---
apiVersion: dp.wso2.com/v1alpha1
kind: Authentication
metadata:
name: disable-sand-api-security
namespace: gateway-integration-test-infra
spec:
override:
disabled: true
targetRef:
group: gateway.networking.k8s.io
kind: API
namespace: gateway-integration-test-infra
name: prod-and-sand-apis
---
apiVersion: dp.wso2.com/v1alpha1
kind: Backend
metadata:
name: infra-backend-v1
namespace: gateway-integration-test-infra
spec:
services:
- host: infra-backend-v1.gateway-integration-test-infra
port: 8080
68 changes: 68 additions & 0 deletions test/integration/integration/tests/verify-old-apis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package tests

import (
"testing"

"github.com/wso2/apk/test/integration/integration/utils/http"
"github.com/wso2/apk/test/integration/integration/utils/suite"
)

func init() {
IntegrationTests = append(IntegrationTests, VerifyOldAPIs)
}

// VerifyOldAPIs test
var VerifyOldAPIs = suite.IntegrationTest{
ShortName: "VerifyOldAPIs",
Description: "Verify Old APIs with different CR versions",
Manifests: []string{"tests/verify-old-apis.yaml"},
Test: func(t *testing.T, suite *suite.IntegrationTestSuite) {
ns := "gateway-integration-test-infra"
gwAddr1 := "prod-api.test.gw.wso2.com:9095"
token := http.GetTestToken(t)

testCases1 := []http.ExpectedResponse{
// invoke prod api using prod domain name, invokes prod backend
{
Request: http.Request{
Host: "prod-api.test.gw.wso2.com",
Path: "/verify-old-apis/v1",
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Path: "/",
},
},
Backend: "infra-backend-v1",
Namespace: ns,
},
}

for i := range testCases1 {
tc := testCases1[i]
tc.Request.Headers = http.AddBearerTokenToHeader(token, tc.Request.Headers)
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
t.Parallel()
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr1, tc)
})
}

},
}

0 comments on commit a0e6f15

Please sign in to comment.