From b16cdef598526bdbcb9511b49125e7126c45b77a Mon Sep 17 00:00:00 2001 From: yuefanxiao <591649725@qq.com> Date: Wed, 14 May 2025 22:46:46 +0800 Subject: [PATCH] Add test cases for loading .env file --- script/test/cmd/tests.sh | 8 ++ script/test/fixtures/env-dotenv/.env | 5 + script/test/fixtures/env-dotenv/compose.yaml | 12 +++ .../test/fixtures/env-dotenv/output-k8s.yaml | 68 +++++++++++++ .../test/fixtures/env-dotenv/output-os.yaml | 96 +++++++++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 script/test/fixtures/env-dotenv/.env create mode 100644 script/test/fixtures/env-dotenv/compose.yaml create mode 100644 script/test/fixtures/env-dotenv/output-k8s.yaml create mode 100644 script/test/fixtures/env-dotenv/output-os.yaml diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index ccb185ff..d1a9bc2d 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -228,6 +228,14 @@ os_output="$KOMPOSE_ROOT/script/test/fixtures/envvars-interpolation/output-os.ya convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1 convert::expect_success_and_warning "$os_cmd" "$os_output" || exit 1 +# Test load .env file by default +k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/env-dotenv/compose.yaml convert --stdout --with-kompose-annotation=false" +os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/env-dotenv/compose.yaml convert --stdout --with-kompose-annotation=false" +k8s_output="$KOMPOSE_ROOT/script/test/fixtures/env-dotenv/output-k8s.yaml" +os_output="$KOMPOSE_ROOT/script/test/fixtures/env-dotenv/output-os.yaml" +convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1 +convert::expect_success_and_warning "$os_cmd" "$os_output" || exit 1 + # Test single file output feature k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/single-file-output/compose.yaml convert --stdout --with-kompose-annotation=false" k8s_output="$KOMPOSE_ROOT/script/test/fixtures/single-file-output/output-k8s.yaml" diff --git a/script/test/fixtures/env-dotenv/.env b/script/test/fixtures/env-dotenv/.env new file mode 100644 index 00000000..b5e0badb --- /dev/null +++ b/script/test/fixtures/env-dotenv/.env @@ -0,0 +1,5 @@ +MINIO_USER=rag_flow +MINIO_PASSWORD=infini_rag_flow +TIMEZONE=Asia/Shanghai +MINIO_PORT=9000 +MINIO_CONSOLE_PORT=9001 \ No newline at end of file diff --git a/script/test/fixtures/env-dotenv/compose.yaml b/script/test/fixtures/env-dotenv/compose.yaml new file mode 100644 index 00000000..665044de --- /dev/null +++ b/script/test/fixtures/env-dotenv/compose.yaml @@ -0,0 +1,12 @@ +version: '3' +services: + minio: + image: quay.io/minio/minio:RELEASE.2023-12-20T01-00-02Z + env_file: .env + environment: + - MINIO_ROOT_USER=${MINIO_USER} + - MINIO_ROOT_PASSWORD=${MINIO_PASSWORD} + - TZ=${TIMEZONE} + ports: + - ${MINIO_PORT}:9000 + - ${MINIO_CONSOLE_PORT}:9001 \ No newline at end of file diff --git a/script/test/fixtures/env-dotenv/output-k8s.yaml b/script/test/fixtures/env-dotenv/output-k8s.yaml new file mode 100644 index 00000000..9dcb24eb --- /dev/null +++ b/script/test/fixtures/env-dotenv/output-k8s.yaml @@ -0,0 +1,68 @@ +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: minio + name: minio +spec: + ports: + - name: "9000" + port: 9000 + targetPort: 9000 + - name: "9001" + port: 9001 + targetPort: 9001 + selector: + io.kompose.service: minio + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: minio + name: minio +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: minio + template: + metadata: + labels: + io.kompose.service: minio + spec: + containers: + - env: + - name: MINIO_ROOT_PASSWORD + value: infini_rag_flow + - name: MINIO_ROOT_USER + value: rag_flow + - name: TZ + value: Asia/Shanghai + envFrom: + - configMapRef: + name: env + image: quay.io/minio/minio:RELEASE.2023-12-20T01-00-02Z + name: minio + ports: + - containerPort: 9000 + protocol: TCP + - containerPort: 9001 + protocol: TCP + restartPolicy: Always + +--- +apiVersion: v1 +data: + MINIO_CONSOLE_PORT: "9001" + MINIO_PASSWORD: infini_rag_flow + MINIO_PORT: "9000" + MINIO_USER: rag_flow + TIMEZONE: Asia/Shanghai +kind: ConfigMap +metadata: + labels: + io.kompose.service: minio-env + name: env \ No newline at end of file diff --git a/script/test/fixtures/env-dotenv/output-os.yaml b/script/test/fixtures/env-dotenv/output-os.yaml new file mode 100644 index 00000000..89ad3ca6 --- /dev/null +++ b/script/test/fixtures/env-dotenv/output-os.yaml @@ -0,0 +1,96 @@ +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: minio + name: minio +spec: + ports: + - name: "9000" + port: 9000 + targetPort: 9000 + - name: "9001" + port: 9001 + targetPort: 9001 + selector: + io.kompose.service: minio + +--- +apiVersion: v1 +data: + MINIO_CONSOLE_PORT: "9001" + MINIO_PASSWORD: infini_rag_flow + MINIO_PORT: "9000" + MINIO_USER: rag_flow + TIMEZONE: Asia/Shanghai +kind: ConfigMap +metadata: + labels: + io.kompose.service: minio-env + name: env + +--- +apiVersion: apps.openshift.io/v1 +kind: DeploymentConfig +metadata: + labels: + io.kompose.service: minio + name: minio +spec: + replicas: 1 + selector: + io.kompose.service: minio + template: + metadata: + labels: + io.kompose.service: minio + spec: + containers: + - env: + - name: MINIO_ROOT_PASSWORD + value: infini_rag_flow + - name: MINIO_ROOT_USER + value: rag_flow + - name: TZ + value: Asia/Shanghai + envFrom: + - configMapRef: + name: env + image: ' ' + name: minio + ports: + - containerPort: 9000 + protocol: TCP + - containerPort: 9001 + protocol: TCP + restartPolicy: Always + test: false + triggers: + - type: ConfigChange + - imageChangeParams: + automatic: true + containerNames: + - minio + from: + kind: ImageStreamTag + name: minio:RELEASE.2023-12-20T01-00-02Z + type: ImageChange + +--- +apiVersion: image.openshift.io/v1 +kind: ImageStream +metadata: + labels: + io.kompose.service: minio + name: minio +spec: + lookupPolicy: + local: false + tags: + - from: + kind: DockerImage + name: quay.io/minio/minio:RELEASE.2023-12-20T01-00-02Z + name: RELEASE.2023-12-20T01-00-02Z + referencePolicy: + type: "" \ No newline at end of file