Skip to content

Commit

Permalink
add tests, die if inputfiles not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
realgam3 committed Dec 16, 2023
1 parent f445590 commit 452b4d3
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ func Convert(opt kobject.ConvertOptions) ([]runtime.Object, error) {

komposeObject.Namespace = opt.Namespace

// Check if input files are specified
if len(opt.InputFiles) <= 0 {
log.Fatal("No input files specified")
}

// convert env_file from absolute to relative path
for _, service := range komposeObject.ServiceConfigs {
if len(service.EnvFile) <= 0 {
Expand All @@ -245,7 +250,7 @@ func Convert(opt kobject.ConvertOptions) ([]runtime.Object, error) {
log.Fatalf(err.Error())
}

service.EnvFile[i] = strings.Replace(relPath, "\\", "/", -1)
service.EnvFile[i] = filepath.ToSlash(relPath)
}
}

Expand Down
8 changes: 8 additions & 0 deletions script/test/cmd/tests_new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ os_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-volume/output-os-withlab
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1
convert::expect_success "$os_cmd" "$os_output" || exit 1

# test configmap pod generation
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/configmap-pod/docker-compose.yml convert --stdout --with-kompose-annotation=false"
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-pod/output-k8s.yaml"
os_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-pod/output-os.yaml"
os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/configmap-pod/docker-compose.yml convert --stdout --with-kompose-annotation=false"
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
convert::expect_success "$os_cmd" "$os_output" || exit 1

# Test that emptyDir works
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml convert --with-kompose-annotation=false --stdout --volumes emptyDir"
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-k8s-empty-vols-template.yaml"
Expand Down
3 changes: 3 additions & 0 deletions script/test/fixtures/configmap-pod/bar.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Multi-line test
FOO=BAR
BAR=FOO
16 changes: 16 additions & 0 deletions script/test/fixtures/configmap-pod/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3'

services:
redis:
image: 'bitnami/redis:latest'
environment:
- ALLOW_EMPTY_PASSWORD=no
# Env file will override environment / warn!
env_file:
- "foo.env"
- bar.env
labels:
kompose.service.type: nodeport
ports:
- '6379:6379'
restart: "no"
2 changes: 2 additions & 0 deletions script/test/fixtures/configmap-pod/foo.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Test comment!
ALLOW_EMPTY_PASSWORD=yes
76 changes: 76 additions & 0 deletions script/test/fixtures/configmap-pod/output-k8s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
io.kompose.service: redis
name: redis
spec:
ports:
- name: "6379"
port: 6379
targetPort: 6379
selector:
io.kompose.service: redis
type: NodePort

---
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
io.kompose.network/configmap-pod-default: "true"
io.kompose.service: redis
name: redis
spec:
containers:
- env:
- name: ALLOW_EMPTY_PASSWORD
valueFrom:
configMapKeyRef:
key: ALLOW_EMPTY_PASSWORD
name: foo-env
- name: BAR
valueFrom:
configMapKeyRef:
key: BAR
name: bar-env
- name: FOO
valueFrom:
configMapKeyRef:
key: FOO
name: bar-env
image: bitnami/redis:latest
name: redis
ports:
- containerPort: 6379
hostPort: 6379
protocol: TCP
resources: {}
restartPolicy: Never

---
apiVersion: v1
data:
ALLOW_EMPTY_PASSWORD: "yes"
kind: ConfigMap
metadata:
creationTimestamp: null
labels:
io.kompose.service: redis-foo-env
name: foo-env

---
apiVersion: v1
data:
BAR: FOO
FOO: BAR
kind: ConfigMap
metadata:
creationTimestamp: null
labels:
io.kompose.service: redis-bar-env
name: bar-env

53 changes: 53 additions & 0 deletions script/test/fixtures/configmap-pod/output-os.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
io.kompose.service: redis
name: redis
spec:
ports:
- name: "6379"
port: 6379
targetPort: 6379
selector:
io.kompose.service: redis
type: NodePort

---
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
io.kompose.network/configmap-pod-default: "true"
io.kompose.service: redis
name: redis
spec:
containers:
- env:
- name: ALLOW_EMPTY_PASSWORD
valueFrom:
configMapKeyRef:
key: ALLOW_EMPTY_PASSWORD
name: foo-env
- name: BAR
valueFrom:
configMapKeyRef:
key: BAR
name: bar-env
- name: FOO
valueFrom:
configMapKeyRef:
key: FOO
name: bar-env
image: bitnami/redis:latest
name: redis
ports:
- containerPort: 6379
hostPort: 6379
protocol: TCP
resources: {}
restartPolicy: Never

0 comments on commit 452b4d3

Please sign in to comment.