This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new cb8e3ea8a chore(ci): added back openapi trait test
cb8e3ea8a is described below

commit cb8e3ea8a7c20b0bd4daad2e1494f3aa25ca0f70
Author: Pasquale Congiusti <pasquale.congiu...@gmail.com>
AuthorDate: Thu Oct 31 07:14:38 2024 +0100

    chore(ci): added back openapi trait test
    
    Altough the feature is deprecated it is good we verify with testing it 
still works as expected
---
 e2e/common/traits/files/petstore-api.yaml | 128 ++++++++++++++++++++++++++++++
 e2e/common/traits/files/petstore.yaml     |  39 +++++++++
 e2e/common/traits/openapi_test.go         |  70 ++++++++++++++++
 3 files changed, 237 insertions(+)

diff --git a/e2e/common/traits/files/petstore-api.yaml 
b/e2e/common/traits/files/petstore-api.yaml
new file mode 100644
index 000000000..1b6d69cd4
--- /dev/null
+++ b/e2e/common/traits/files/petstore-api.yaml
@@ -0,0 +1,128 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF 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.
+# ---------------------------------------------------------------------------
+
+openapi: "3.0.0"
+info:
+  version: 1.0.0
+  title: Swagger Petstore
+  license:
+    name: MIT
+servers:
+  - url: http://petstore.swagger.io/v1
+paths:
+  /pets:
+    get:
+      summary: List all pets
+      operationId: listPets
+      tags:
+        - pets
+      parameters:
+        - name: limit
+          in: query
+          description: How many items to return at one time (max 100)
+          required: false
+          schema:
+            type: integer
+            format: int32
+      responses:
+        '200':
+          description: A paged array of pets
+          headers:
+            x-next:
+              description: A link to the next page of responses
+              schema:
+                type: string
+          content:
+            application/json:
+              schema:
+                $ref: "#/components/schemas/Pets"
+        default:
+          description: unexpected error
+          content:
+            application/json:
+              schema:
+                $ref: "#/components/schemas/Error"
+    post:
+      summary: Create a pet
+      operationId: createPets
+      tags:
+        - pets
+      responses:
+        '201':
+          description: Null response
+        default:
+          description: unexpected error
+          content:
+            application/json:
+              schema:
+                $ref: "#/components/schemas/Error"
+  /pets/{petId}:
+    get:
+      summary: Info for a specific pet
+      operationId: showPetById
+      tags:
+        - pets
+      parameters:
+        - name: petId
+          in: path
+          required: true
+          description: The id of the pet to retrieve
+          schema:
+            type: string
+      responses:
+        '200':
+          description: Expected response to a valid request
+          content:
+            application/json:
+              schema:
+                $ref: "#/components/schemas/Pet"
+        default:
+          description: unexpected error
+          content:
+            application/json:
+              schema:
+                $ref: "#/components/schemas/Error"
+components:
+  schemas:
+    Pet:
+      type: object
+      required:
+        - id
+        - name
+      properties:
+        id:
+          type: integer
+          format: int64
+        name:
+          type: string
+        tag:
+          type: string
+    Pets:
+      type: array
+      items:
+        $ref: "#/components/schemas/Pet"
+    Error:
+      type: object
+      required:
+        - code
+        - message
+      properties:
+        code:
+          type: integer
+          format: int32
+        message:
+          type: string
diff --git a/e2e/common/traits/files/petstore.yaml 
b/e2e/common/traits/files/petstore.yaml
new file mode 100644
index 000000000..72087814f
--- /dev/null
+++ b/e2e/common/traits/files/petstore.yaml
@@ -0,0 +1,39 @@
+# camel-k: language=yaml
+
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF 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.
+# ---------------------------------------------------------------------------
+
+- from:
+    uri: "direct:listPets"
+    steps:
+      - setBody:
+          simple: "listPets"
+      - to: "log:info"
+
+- from:
+    uri: "direct:createPets"
+    steps:
+      - setBody:
+          simple: "createPets"
+      - to: "log:info"
+
+- from:
+    uri: "direct:showPetById"
+    steps:
+      - setBody:
+          simple: "showPetById"
+      - to: "log:info"
diff --git a/e2e/common/traits/openapi_test.go 
b/e2e/common/traits/openapi_test.go
new file mode 100644
index 000000000..8c61e166b
--- /dev/null
+++ b/e2e/common/traits/openapi_test.go
@@ -0,0 +1,70 @@
+//go:build integration
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go -> 
Vendoring & Build Tags -> Custom Tags" and add "integration"
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF 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.
+*/
+
+package common
+
+import (
+       "context"
+       "fmt"
+       "os"
+       "testing"
+       "time"
+
+       . "github.com/onsi/gomega"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+
+       corev1 "k8s.io/api/core/v1"
+
+       . "github.com/apache/camel-k/v2/e2e/support"
+       v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+)
+
+func TestOpenAPI(t *testing.T) {
+       t.Parallel()
+       WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
+               name := RandomizedSuffixName("petstore")
+               openapiContent, err := os.ReadFile("./files/petstore-api.yaml")
+               require.NoError(t, err)
+               var cmDataProps = make(map[string]string)
+               cmDataProps["petstore-api.yaml"] = string(openapiContent)
+               CreatePlainTextConfigmap(t, ctx, ns, "my-openapi", cmDataProps)
+
+               g.Expect(KamelRun(t, ctx, ns,
+                       "--name", name, "--open-api", "configmap:my-openapi", 
"files/petstore.yaml").
+                       Execute()).To(Succeed())
+
+               g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, 
v1.IntegrationConditionReady), TestTimeoutMedium).
+                       Should(Equal(corev1.ConditionTrue))
+               g.Eventually(IntegrationPodPhase(t, ctx, ns, 
name)).Should(Equal(corev1.PodRunning))
+               // Let's make sure the Integration is ready to receive traffic
+               g.Eventually(IntegrationLogs(t, ctx, ns, 
name)).Should(ContainSubstring("Listening on: http://0.0.0.0:8080";))
+               pod := IntegrationPod(t, ctx, ns, name)()
+               g.Expect(pod).NotTo(BeNil())
+               response, err := TestClient(t).CoreV1().RESTClient().Get().
+                       Timeout(30 * time.Second).
+                       
AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/v1/pets", 
pod.Namespace, pod.Name)).
+                       DoRaw(ctx)
+               require.NoError(t, err)
+               assert.Equal(t, "listPets", string(response))
+       })
+}

Reply via email to