Skip to content

Commit

Permalink
Add test case for 'odo dev' when a project with no source code is use…
Browse files Browse the repository at this point in the history
…d with no 'metadata.name' in the Devfile

The rationale behind this is to purposely make
the Alizer library unable to detect the project.
Per the requirements, this would force us to use the project
directory name as component name.

This highlights an interesting behavior if the project
directory name is all-numeric (as is the case in our tests);
our sanitization logic automatically prepends an "x" prefix
to the directory name, so it can be used as a valid name
for the component.
  • Loading branch information
rm3l committed Aug 29, 2022
1 parent 88c360b commit 3aa7bc0
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
schemaVersion: 2.0.0
metadata:
projectType: nodejs
language: nodejs
starterProjects:
- name: nodejs-starter
git:
remotes:
origin: "https://github.com/odo-devfiles/nodejs-ex.git"
components:
- name: runtime
container:
image: registry.access.redhat.com/ubi8/nodejs-12:1-36
memoryLimit: 1024Mi
endpoints:
- name: "3000-tcp"
targetPort: 3000
mountSources: true
commands:
- id: devbuild
exec:
component: runtime
commandLine: npm install
workingDir: ${PROJECTS_ROOT}
group:
kind: build
isDefault: true
- id: build
exec:
component: runtime
commandLine: npm install
workingDir: ${PROJECTS_ROOT}
group:
kind: build
- id: devrun
exec:
component: runtime
commandLine: npm start
workingDir: ${PROJECTS_ROOT}
group:
kind: run
isDefault: true
- id: run
exec:
component: runtime
commandLine: npm start
workingDir: ${PROJECTS_ROOT}
group:
kind: run
40 changes: 40 additions & 0 deletions tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2462,4 +2462,44 @@ CMD ["npm", "start"]
})
})
})

Describe("Devfile with no metadata.name", func() {

BeforeEach(func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-no-metadata-name.yaml"),
filepath.Join(commonVar.Context, "devfile.yaml"))
})

When("running odo dev against a component with no source code", func() {
var devSession helper.DevSession
BeforeEach(func() {
var err error
devSession, _, _, _, err = helper.StartDevMode(nil)
Expect(err).ToNot(HaveOccurred())
})

AfterEach(func() {
devSession.Stop()
})

It("should use the directory as component name", func() {
// when no further source code is available, directory name is returned by alizer.DetectName as component name;
// and since it is all-numeric in our tests, an "x" prefix is added by util.GetDNS1123Name (called by alizer.DetectName)
cmpName := "x" + filepath.Base(commonVar.Context)
commonVar.CliRunner.CheckCmdOpInRemoteDevfilePod(
commonVar.CliRunner.GetRunningPodNameByComponent(cmpName, commonVar.Project),
"runtime",
commonVar.Project,
[]string{
remotecmd.ShellExecutable, "-c",
fmt.Sprintf("cat %s/.odo_cmd_devrun.pid", strings.TrimSuffix(storage.SharedDataMountPath, "/")),
},
func(stdout string, err error) bool {
Expect(err).ShouldNot(HaveOccurred())
Expect(stdout).NotTo(BeEmpty())
return err == nil
})
})
})
})
})

0 comments on commit 3aa7bc0

Please sign in to comment.