Skip to content

Commit

Permalink
Fix parametrized integration tests (#5826)
Browse files Browse the repository at this point in the history
* Fix parametrized integration tests

Signed-off-by: Parthvi Vala <[email protected]>

* Fix test failure
  • Loading branch information
valaparthvi authored Jun 20, 2022
1 parent d567784 commit bf71fa3
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
commands:
- exec:
commandLine: npm install
component: runtime
group:
isDefault: true
kind: build
workingDir: /project
id: install
- exec:
commandLine: npm start
component: runtime
group:
isDefault: true
kind: run
workingDir: /project
id: run
- exec:
commandLine: npm run debug
component: runtime
group:
isDefault: true
kind: debug
workingDir: /project
id: debug
- exec:
commandLine: npm test
component: runtime
group:
isDefault: true
kind: test
workingDir: /project
id: test
- id: build-image
apply:
component: outerloop-build
- id: deployk8s
apply:
component: outerloop-deploy
- id: deployservice
apply:
component: outerloop-deploy-2
- id: deploy
composite:
commands:
- build-image
- deployk8s
- deployservice
group:
kind: deploy
isDefault: true
components:
- container:
endpoints:
- name: http-3000
targetPort: 3000
image: registry.access.redhat.com/ubi8/nodejs-14:latest
memoryLimit: 1024Mi
mountSources: true
sourceMapping: /project
name: runtime
- name: outerloop-build
image:
imageName: "{{CONTAINER_IMAGE}}"
dockerfile:
uri: ./Dockerfile
buildContext: ${PROJECTS_ROOT}
rootRequired: false

- name: outerloop-deploy
kubernetes:
inlined: |
kind: Deployment
apiVersion: apps/v1
metadata:
name: my-component
spec:
replicas: 1
selector:
matchLabels:
app: node-app
template:
metadata:
labels:
app: node-app
spec:
containers:
- name: main
image: {{CONTAINER_IMAGE}}
resources:
limits:
memory: "128Mi"
cpu: "500m"
- name: outerloop-deploy-2
kubernetes:
inlined: |
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: my-cs
name: my-cs
spec:
ports:
- name: 5678-8080
port: 5678
protocol: TCP
targetPort: 8080
selector:
app: my-cs
type: ClusterIP
status:
loadBalancer: {}
metadata:
description: Stack with Node.js 14
displayName: Node.js Runtime
icon: https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg
language: javascript
name: mynodejs
projectType: nodejs
tags:
- NodeJS
- Express
- ubi8
version: 1.0.1
schemaVersion: 2.2.0
starterProjects:
- git:
remotes:
origin: https://github.com/odo-devfiles/nodejs-ex.git
name: nodejs-starter
variables:
CONTAINER_IMAGE: quay.io/unknown-account/myimage
6 changes: 3 additions & 3 deletions tests/integration/cmd_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ var _ = Describe("odo create/delete/list/set namespace/project tests", func() {
AfterEach(func() {
helper.CommonAfterEach(commonVar)
})

for _, commandName := range []string{"namespace", "project"} {

// this is a workaround to ensure that the for loop works with `It` blocks
commandName := commandName
Describe("create "+commandName, func() {

namespace := fmt.Sprintf("%s-%s", helper.RandString(4), commandName)

// TODO: Remove for loop; find a way to use DescribeTable
It(fmt.Sprintf("should successfully create the %s", commandName), func() {
helper.Cmd("odo", "create", commandName, namespace, "--wait").ShouldPass()
defer func(ns string) {
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/devfile/cmd_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = Describe("odo delete command tests", func() {
}{
{
title: "a component is bootstrapped",
devfileName: "devfile-deploy-with-multiple-resources",
devfileName: "devfile-deploy-with-multiple-resources.yaml",
},
{
title: "a component is bootstrapped using a devfile.yaml with URI-referenced Kubernetes components",
Expand All @@ -48,6 +48,8 @@ var _ = Describe("odo delete command tests", func() {
},
},
} {
// this is a workaround to ensure that the for loop works with `It` blocks
ctx := ctx
When(ctx.title, func() {
BeforeEach(func() {
// Hardcoded names from `ctx.devfileName`
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/devfile/cmd_describe_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ var _ = Describe("odo describe binding command tests", func() {
},
},
} {
// this is a workaround to ensure that for loop works well with `It` blocks
ctx := ctx
When(ctx.title, func() {
cmpName := "my-nodejs-app"
BeforeEach(func() {
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/devfile/cmd_devfile_build_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ var _ = Describe("odo devfile build-images command tests", func() {
},
},
} {
// this is a workaround to ensure that the for loop works with `It` blocks
scope := scope
It(fmt.Sprintf("should build image via %s if build context references PROJECT_SOURCE env var", scope.name), func() {
stdout := helper.Cmd("odo", "build-images").AddEnv(scope.envvars...).ShouldPass().Out()
lines, err := helper.ExtractLines(stdout)
Expand Down Expand Up @@ -144,6 +146,8 @@ var _ = Describe("odo devfile build-images command tests", func() {
},
},
} {
// this is a workaround to ensure that the for loop works with `It` blocks
scope := scope
It(fmt.Sprintf("should build image via %s by defaulting build context to devfile path", scope.name), func() {
stdout := helper.Cmd("odo", "build-images").AddEnv(scope.envvars...).ShouldPass().Out()
lines, err := helper.ExtractLines(stdout)
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/devfile/cmd_devfile_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ var _ = Describe("odo devfile deploy command tests", func() {
},
},
} {
// this is a workaround to ensure that the for loop works with `It` blocks
ctx := ctx

When(ctx.title, func() {
// from devfile
Expand Down Expand Up @@ -214,6 +216,9 @@ var _ = Describe("odo devfile deploy command tests", func() {
},
},
} {
// this is a workaround to ensure that the for loop works with `It` blocks
scope := scope

It(fmt.Sprintf("should build image via %s if build context references PROJECT_SOURCE env var", scope.name), func() {
stdout := helper.Cmd("odo", "deploy").AddEnv(scope.envvars...).ShouldPass().Out()
lines, err := helper.ExtractLines(stdout)
Expand Down Expand Up @@ -258,6 +263,9 @@ var _ = Describe("odo devfile deploy command tests", func() {
},
},
} {
// this is a workaround to ensure that the for loop works with `It` blocks
scope := scope

It(fmt.Sprintf("should build image via %s by defaulting build context to devfile path", scope.name), func() {
stdout := helper.Cmd("odo", "deploy").AddEnv(scope.envvars...).ShouldPass().Out()
lines, err := helper.ExtractLines(stdout)
Expand Down

0 comments on commit bf71fa3

Please sign in to comment.