Skip to content

Commit

Permalink
Add more test cases to check the priority order when searching for de…
Browse files Browse the repository at this point in the history
…fault devfiles

Signed-off-by: Armel Soro <asoro@redhat.com>
  • Loading branch information
rm3l committed Oct 31, 2023
1 parent 6bc14e6 commit 02f8362
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 0 deletions.
112 changes: 112 additions & 0 deletions pkg/devfile/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,118 @@ spec:
StarterProjects: map[string][]string{},
},
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to devfile.yaml",
args: args{
args: parser.ParserArgs{
ExternalVariables: map[string]string{
"PARAMS": "from devfile.yaml based on priority",
},
Path: "./testdata",
},
},
wantCommandLine: "./main from devfile.yaml based on priority",
wantVariables: map[string]string{
"PARAMS": "from devfile.yaml based on priority",
},
wantVarWarning: variables.VariableWarning{
Commands: map[string][]string{},
Components: map[string][]string{},
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
additionalChecks: func(devfileObj parser.DevfileObj) error {
if devfileObj.Data.GetMetadata().DisplayName != "Go Runtime (devfile.yaml)" {
return fmt.Errorf("expected 'Go Runtime (devfile.yaml)' as metadata.displayName in devfile, but got %q",
devfileObj.Data.GetMetadata().DisplayName)
}
return nil
},
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to .devfile.yaml",
args: args{
args: parser.ParserArgs{
ExternalVariables: map[string]string{
"PARAMS": "from .devfile.yaml based on priority",
},
Path: "./testdata/priority-for-dot_devfile_yaml",
},
},
wantCommandLine: "./main from .devfile.yaml based on priority",
wantVariables: map[string]string{
"PARAMS": "from .devfile.yaml based on priority",
},
wantVarWarning: variables.VariableWarning{
Commands: map[string][]string{},
Components: map[string][]string{},
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
additionalChecks: func(devfileObj parser.DevfileObj) error {
if devfileObj.Data.GetMetadata().DisplayName != "Go Runtime (.devfile.yaml)" {
return fmt.Errorf("expected 'Go Runtime (.devfile.yaml)' as metadata.displayName in devfile, but got %q",
devfileObj.Data.GetMetadata().DisplayName)
}
return nil
},
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to devfile.yml",
args: args{
args: parser.ParserArgs{
ExternalVariables: map[string]string{
"PARAMS": "from devfile.yml based on priority",
},
Path: "./testdata/priority-for-devfile_yml",
},
},
wantCommandLine: "./main from devfile.yml based on priority",
wantVariables: map[string]string{
"PARAMS": "from devfile.yml based on priority",
},
wantVarWarning: variables.VariableWarning{
Commands: map[string][]string{},
Components: map[string][]string{},
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
additionalChecks: func(devfileObj parser.DevfileObj) error {
if devfileObj.Data.GetMetadata().DisplayName != "Test stack (devfile.yml)" {
return fmt.Errorf("expected 'Test stack (devfile.yml)' as metadata.displayName in devfile, but got %q",
devfileObj.Data.GetMetadata().DisplayName)
}
return nil
},
},
{
name: "parsing devfile with context path containing multiple devfiles => priority to .devfile.yml",
args: args{
args: parser.ParserArgs{
ExternalVariables: map[string]string{
"PARAMS": "from .devfile.yml based on priority",
},
Path: "./testdata/priority-for-dot_devfile_yml",
},
},
wantCommandLine: "./main from .devfile.yml based on priority",
wantVariables: map[string]string{
"PARAMS": "from .devfile.yml based on priority",
},
wantVarWarning: variables.VariableWarning{
Commands: map[string][]string{},
Components: map[string][]string{},
Projects: map[string][]string{},
StarterProjects: map[string][]string{},
},
additionalChecks: func(devfileObj parser.DevfileObj) error {
if devfileObj.Data.GetMetadata().DisplayName != "Test stack (.devfile.yml)" {
return fmt.Errorf("expected 'Test stack (.devfile.yml)' as metadata.displayName in devfile, but got %q",
devfileObj.Data.GetMetadata().DisplayName)
}
return nil
},
},
{
name: "parsing devfile with .yml extension",
args: args{
Expand Down
28 changes: 28 additions & 0 deletions pkg/devfile/testdata/priority-for-devfile_yml/.devfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
commands:
- exec:
commandLine: ./main {{ PARAMS }}
component: runtime
group:
isDefault: true
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
components:
- container:
image: busybox:latest
command: [tail]
args: [ -f, /dev/null ]
mountSources: true
name: runtime
- kubernetes:
uri: http://127.0.0.1:8080/outerloop-deploy.yaml
name: outerloop-deploy
- openshift:
uri: http://127.0.0.1:8080/outerloop-service.yaml
name: outerloop-deploy2
metadata:
description: Test stack (Busybox)
displayName: Test stack (.devfile.yml)
name: my-test-app
version: 0.1.0
schemaVersion: 2.2.0
28 changes: 28 additions & 0 deletions pkg/devfile/testdata/priority-for-devfile_yml/devfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
commands:
- exec:
commandLine: ./main {{ PARAMS }}
component: runtime
group:
isDefault: true
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
components:
- container:
image: busybox:latest
command: [tail]
args: [ -f, /dev/null ]
mountSources: true
name: runtime
- kubernetes:
uri: http://127.0.0.1:8080/outerloop-deploy.yaml
name: outerloop-deploy
- openshift:
uri: http://127.0.0.1:8080/outerloop-service.yaml
name: outerloop-deploy2
metadata:
description: Test stack (Busybox)
displayName: Test stack (devfile.yml)
name: my-test-app
version: 0.1.0
schemaVersion: 2.2.0
35 changes: 35 additions & 0 deletions pkg/devfile/testdata/priority-for-dot_devfile_yaml/.devfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
commands:
- exec:
commandLine: ./main {{ PARAMS }}
component: runtime
group:
isDefault: true
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
components:
- container:
endpoints:
- name: http
targetPort: 8080
image: golang:latest
memoryLimit: 1024Mi
mountSources: true
name: runtime
- kubernetes:
uri: http://127.0.0.1:8080/outerloop-deploy.yaml
name: outerloop-deploy
- openshift:
uri: http://127.0.0.1:8080/outerloop-service.yaml
name: outerloop-deploy2
metadata:
description: Stack with the latest Go version
displayName: Go Runtime (.devfile.yaml)
icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/golang.svg
language: go
name: my-go-app
projectType: go
tags:
- Go
version: 1.0.0
schemaVersion: 2.2.0
28 changes: 28 additions & 0 deletions pkg/devfile/testdata/priority-for-dot_devfile_yaml/.devfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
commands:
- exec:
commandLine: ./main {{ PARAMS }}
component: runtime
group:
isDefault: true
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
components:
- container:
image: busybox:latest
command: [tail]
args: [ -f, /dev/null ]
mountSources: true
name: runtime
- kubernetes:
uri: http://127.0.0.1:8080/outerloop-deploy.yaml
name: outerloop-deploy
- openshift:
uri: http://127.0.0.1:8080/outerloop-service.yaml
name: outerloop-deploy2
metadata:
description: Test stack (Busybox)
displayName: Test stack (.devfile.yml)
name: my-test-app
version: 0.1.0
schemaVersion: 2.2.0
28 changes: 28 additions & 0 deletions pkg/devfile/testdata/priority-for-dot_devfile_yaml/devfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
commands:
- exec:
commandLine: ./main {{ PARAMS }}
component: runtime
group:
isDefault: true
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
components:
- container:
image: busybox:latest
command: [tail]
args: [ -f, /dev/null ]
mountSources: true
name: runtime
- kubernetes:
uri: http://127.0.0.1:8080/outerloop-deploy.yaml
name: outerloop-deploy
- openshift:
uri: http://127.0.0.1:8080/outerloop-service.yaml
name: outerloop-deploy2
metadata:
description: Test stack (Busybox)
displayName: Test stack (devfile.yml)
name: my-test-app
version: 0.1.0
schemaVersion: 2.2.0
28 changes: 28 additions & 0 deletions pkg/devfile/testdata/priority-for-dot_devfile_yml/.devfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
commands:
- exec:
commandLine: ./main {{ PARAMS }}
component: runtime
group:
isDefault: true
kind: run
workingDir: ${PROJECT_SOURCE}
id: run
components:
- container:
image: busybox:latest
command: [tail]
args: [ -f, /dev/null ]
mountSources: true
name: runtime
- kubernetes:
uri: http://127.0.0.1:8080/outerloop-deploy.yaml
name: outerloop-deploy
- openshift:
uri: http://127.0.0.1:8080/outerloop-service.yaml
name: outerloop-deploy2
metadata:
description: Test stack (Busybox)
displayName: Test stack (.devfile.yml)
name: my-test-app
version: 0.1.0
schemaVersion: 2.2.0

0 comments on commit 02f8362

Please sign in to comment.