Add a Devfile dependency for commands (#7063)

* Define Devfile dependency for commands

* Remove MarkDevfileNotNeeded

* More commands not using Devfile

* Tests with invalid devfiles
This commit is contained in:
Philippe Martin
2023-09-04 18:12:34 +02:00
committed by GitHub
parent 03c109a6e2
commit a65812143c
22 changed files with 135 additions and 38 deletions

View File

@@ -319,3 +319,15 @@ func AppendToFile(filepath string, s string) error {
}
return nil
}
func CreateInvalidDevfile(dir string) {
devfilePath := filepath.Join(dir, "devfile.yaml")
err := CreateFileWithContent(devfilePath, "invalid")
Expect(err).ToNot(HaveOccurred())
}
func DeleteInvalidDevfile(dir string) {
devfilePath := filepath.Join(dir, "devfile.yaml")
err := os.Remove(devfilePath)
Expect(err).ToNot(HaveOccurred())
}

View File

@@ -149,6 +149,8 @@ var _ = Describe("odo delete command tests", func() {
Eventually(string(commonVar.CliRunner.Run(getSVCArgs...).Out.Contents()), 60, 3).ShouldNot(ContainSubstring(serviceName))
})
It("should output that there are no resources to be deleted", func() {
helper.CreateInvalidDevfile(commonVar.Context)
helper.Chdir(commonVar.Context)
args := []string{"delete", "component", "--name", cmpName, "--namespace", commonVar.Project}
if runningIn != "" {
args = append(args, "--running-in", runningIn)

View File

@@ -69,6 +69,7 @@ var _ = Describe("odo describe component command tests", func() {
It("should fail, with default cluster mode", func() {
By("running odo describe component -o json with an unknown name", func() {
helper.CreateInvalidDevfile(commonVar.Context)
res := helper.Cmd("odo", "describe", "component", "--name", "unknown-name", "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(helper.IsJSON(stderr)).To(BeTrue())
@@ -77,6 +78,7 @@ var _ = Describe("odo describe component command tests", func() {
})
By("running odo describe component with an unknown name", func() {
helper.CreateInvalidDevfile(commonVar.Context)
res := helper.Cmd("odo", "describe", "component", "--name", "unknown-name").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
@@ -86,6 +88,7 @@ var _ = Describe("odo describe component command tests", func() {
It("should fail, with cluster", func() {
By("running odo describe component -o json with an unknown name", func() {
helper.CreateInvalidDevfile(commonVar.Context)
res := helper.Cmd("odo", "describe", "component", "--name", "unknown-name", "--platform", "cluster", "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(helper.IsJSON(stderr)).To(BeTrue())
@@ -94,6 +97,7 @@ var _ = Describe("odo describe component command tests", func() {
})
By("running odo describe component with an unknown name", func() {
helper.CreateInvalidDevfile(commonVar.Context)
res := helper.Cmd("odo", "describe", "component", "--name", "unknown-name", "--platform", "cluster").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
@@ -103,6 +107,7 @@ var _ = Describe("odo describe component command tests", func() {
It("should fail, with podman", Label(helper.LabelPodman), func() {
By("running odo describe component -o json with an unknown name", func() {
helper.CreateInvalidDevfile(commonVar.Context)
res := helper.Cmd("odo", "describe", "component", "--name", "unknown-name", "--platform", "podman", "-o", "json").
ShouldFail()
stdout, stderr := res.Out(), res.Err()
@@ -112,6 +117,7 @@ var _ = Describe("odo describe component command tests", func() {
})
By("running odo describe component with an unknown name", func() {
helper.CreateInvalidDevfile(commonVar.Context)
stderr := helper.Cmd("odo", "describe", "component", "--name", "unknown-name", "--platform", "podman").
ShouldFail().Err()
Expect(stderr).To(ContainSubstring("no component found with name \"unknown-name\""))
@@ -257,8 +263,10 @@ var _ = Describe("odo describe component command tests", func() {
It("should not describe the component from another directory, with default cluster mode", func() {
By("running with json output", func() {
err := os.Chdir("/")
Expect(err).NotTo(HaveOccurred())
otherDir := filepath.Join(commonVar.Context, "tmp")
helper.MakeDir(otherDir)
helper.Chdir(otherDir)
helper.CreateInvalidDevfile(otherDir)
res := helper.Cmd("odo", "describe", "component", "--name", cmpName, "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(helper.IsJSON(stderr)).To(BeTrue())
@@ -267,8 +275,10 @@ var _ = Describe("odo describe component command tests", func() {
})
By("running with default output", func() {
err := os.Chdir("/")
Expect(err).NotTo(HaveOccurred())
otherDir := filepath.Join(commonVar.Context, "tmp")
helper.MakeDir(otherDir)
helper.Chdir(otherDir)
helper.CreateInvalidDevfile(otherDir)
res := helper.Cmd("odo", "describe", "component", "--name", cmpName).ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
@@ -278,8 +288,10 @@ var _ = Describe("odo describe component command tests", func() {
It("should not describe the component from another directory, with cluster", func() {
By("running with json output", func() {
err := os.Chdir("/")
Expect(err).NotTo(HaveOccurred())
otherDir := filepath.Join(commonVar.Context, "tmp")
helper.MakeDir(otherDir)
helper.Chdir(otherDir)
helper.CreateInvalidDevfile(otherDir)
res := helper.Cmd("odo", "describe", "component", "--name", cmpName, "-o", "json", "--platform", "cluster").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(helper.IsJSON(stderr)).To(BeTrue())
@@ -288,8 +300,10 @@ var _ = Describe("odo describe component command tests", func() {
})
By("running with default output", func() {
err := os.Chdir("/")
Expect(err).NotTo(HaveOccurred())
otherDir := filepath.Join(commonVar.Context, "tmp")
helper.MakeDir(otherDir)
helper.Chdir(otherDir)
helper.CreateInvalidDevfile(otherDir)
res := helper.Cmd("odo", "describe", "component", "--name", cmpName, "--platform", "cluster").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(stdout).To(BeEmpty())
@@ -547,10 +561,12 @@ var _ = Describe("odo describe component command tests", func() {
}
})
By("checking the human readable output with component name", func() {
helper.CreateInvalidDevfile(commonVar.Context)
out := helper.Cmd("odo", "describe", "component", "--name", componentName).ShouldPass().Out()
helper.MatchAllInOutput(out, ctx.matchOutput)
})
By("checking the machine readable output with component name", func() {
helper.CreateInvalidDevfile(commonVar.Context)
out := helper.Cmd("odo", "describe", "component", "--name", componentName, "-o", "json").ShouldPass().Out()
for key, value := range ctx.matchJSONOutput {
helper.JsonPathContentContain(out, key, value)

View File

@@ -737,9 +737,11 @@ var _ = Describe("odo describe/list binding command tests", func() {
ctx.assertDescribeAllHumanReadableOutput(stdout, stderr)
})
By("JSON output from another directory with name flag", func() {
err := os.Chdir("/")
Expect(err).ToNot(HaveOccurred())
By("JSON output from another directory with name flag and invalid devfile", func() {
otherDir := filepath.Join(commonVar.Context, "tmp")
helper.MakeDir(otherDir)
helper.Chdir(otherDir)
helper.CreateInvalidDevfile(otherDir)
res := helper.Cmd("odo", "describe", "binding", "--name", "my-nodejs-app-cluster-sample-k8s", "-o", "json").ShouldPass()
stdout, stderr := res.Out(), res.Err()
ctx.assertDescribeNamedJsonOutput(stdout, stderr, "my-nodejs-app-cluster-sample-k8s")
@@ -748,9 +750,11 @@ var _ = Describe("odo describe/list binding command tests", func() {
stdout, stderr = res.Out(), res.Err()
ctx.assertDescribeNamedJsonOutput(stdout, stderr, "my-nodejs-app-cluster-sample-ocp")
})
By("human readable output from another directory with name flag", func() {
err := os.Chdir("/")
Expect(err).ToNot(HaveOccurred())
By("human readable output from another directory with name flag and invalid devfile", func() {
otherDir := filepath.Join(commonVar.Context, "tmp")
helper.MakeDir(otherDir)
helper.Chdir(otherDir)
helper.CreateInvalidDevfile(otherDir)
res := helper.Cmd("odo", "describe", "binding", "--name", "my-nodejs-app-cluster-sample-k8s").ShouldPass()
stdout, stderr := res.Out(), res.Err()
ctx.assertDescribeNamedHumanReadableOutput(stdout, stderr, "my-nodejs-app-cluster-sample-k8s")

View File

@@ -20,6 +20,7 @@ var _ = Describe("odo devfile registry command tests", func() {
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
helper.Chdir(commonVar.Context)
helper.CreateInvalidDevfile(commonVar.Context)
})
// This is run after every Spec (It)
@@ -182,6 +183,7 @@ var _ = Describe("odo devfile registry command tests", func() {
})
It("should pass, when doing odo init with --devfile-registry flag", func() {
helper.DeleteInvalidDevfile(commonVar.Context)
helper.Cmd("odo", "init", "--name", "aname", "--devfile", "nodejs", "--devfile-registry", registryName).ShouldPass()
})
@@ -194,6 +196,7 @@ var _ = Describe("odo devfile registry command tests", func() {
})
It("deleting registry and creating component with registry flag ", func() {
helper.DeleteInvalidDevfile(commonVar.Context)
helper.Cmd("odo", "preference", "remove", "registry", registryName, "-f").ShouldPass()
helper.Cmd("odo", "init", "--name", "aname", "--devfile", "java-maven", "--devfile-registry", registryName).ShouldFail()
})

View File

@@ -36,6 +36,9 @@ var _ = Describe("odo list services tests", func() {
commonVar.CliRunner.EnsurePodIsUp(randomProject, "cluster-sample-1")
Expect(addBindableKind.ExitCode()).To(BeEquivalentTo(0))
helper.Cmd("odo", "set", "project", commonVar.Project).ShouldPass()
helper.CreateInvalidDevfile(commonVar.Context)
helper.Chdir(commonVar.Context)
})
AfterEach(func() {

View File

@@ -26,6 +26,8 @@ var _ = Describe("odo preference and config command tests", func() {
// This is run before every Spec (It)
var _ = BeforeEach(func() {
commonVar = helper.CommonBeforeEach()
helper.CreateInvalidDevfile(commonVar.Context)
helper.Chdir(commonVar.Context)
})
// Clean up after the test
@@ -199,6 +201,7 @@ OdoSettings:
helper.Chdir(workingDir)
})
It("should not prompt the user", func() {
helper.DeleteInvalidDevfile(commonVar.Context)
helper.Cmd("odo", "preference", "set", "ConsentTelemetry", "false", "-f").ShouldPass()
output := helper.Cmd("odo", "init", "--name", "aname", "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-registry.yaml")).ShouldPass().Out()
Expect(output).ToNot(ContainSubstring(promptMessageSubString))