Skip to content

Commit

Permalink
Merge bd19d1f into 15f663f
Browse files Browse the repository at this point in the history
  • Loading branch information
rm3l authored Dec 1, 2023
2 parents 15f663f + bd19d1f commit c840252
Show file tree
Hide file tree
Showing 70 changed files with 1,153 additions and 419 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/Xuanwo/go-locale v1.1.0
github.com/blang/semver v3.5.1+incompatible
github.com/devfile/alizer v1.2.1
github.com/devfile/api/v2 v2.2.1-alpha.0.20230413012049-a6c32fca0dbd
github.com/devfile/library/v2 v2.2.1-0.20230524160049-04a8b3fc66c0
github.com/devfile/api/v2 v2.2.1
github.com/devfile/library/v2 v2.2.2-0.20231102090733-57a7da8b8392
github.com/devfile/registry-support/index/generator v0.0.0-20230322155332-33914affc83b
github.com/devfile/registry-support/registry-library v0.0.0-20221201200738-19293ac0b8ab
github.com/fatih/color v1.15.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/apiserver-impl/devstate/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (o *DevfileState) GetContent() (DevfileContent, error) {
if err != nil {
return DevfileContent{}, errors.New("error writing file")
}
result, err := o.FS.ReadFile("/devfile.yaml")
result, err := o.FS.ReadFile(o.Devfile.Ctx.GetAbsPath())
if err != nil {
return DevfileContent{}, errors.New("error reading file")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/apiserver-impl/devstate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/devfile/library/v2/pkg/devfile/parser"
context "github.com/devfile/library/v2/pkg/devfile/parser/context"
"github.com/devfile/library/v2/pkg/testingutil/filesystem"

. "github.com/redhat-developer/odo/pkg/apiserver-gen/go"

"k8s.io/utils/pointer"
Expand Down Expand Up @@ -42,7 +43,7 @@ func (o *DevfileState) SetDevfileContent(content string) (DevfileContent, error)
return DevfileContent{}, fmt.Errorf("error parsing devfile YAML: %w", err)
}
o.Devfile = devfile
o.Devfile.Ctx = context.FakeContext(o.FS, "/devfile.yaml")
o.Devfile.Ctx = context.FakeContext(o.FS, o.Devfile.Ctx.GetAbsPath())
return o.GetContent()
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/devfile/location/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/redhat-developer/odo/pkg/util"
)

// possibleDevfileNames contains possivle devfile name that should be checked in the context dir.
var possibleDevfileNames = [...]string{"devfile.yaml", ".devfile.yaml"}
// possibleDevfileNames contains possible devfile name that should be checked in the context dir.
var possibleDevfileNames = [...]string{"devfile.yaml", ".devfile.yaml", "devfile.yml", ".devfile.yml"}

// DevfileFilenamesProvider checks if the context dir contains devfile with possible names from possibleDevfileNames variable,
// else it returns "devfile.yaml" as default value.
Expand Down
59 changes: 42 additions & 17 deletions tests/integration/cmd_describe_component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,32 +230,57 @@ var _ = Describe("odo describe component command tests", func() {
})
})

When("renaming to hide devfile.yaml file", Label(label), func() {
for _, devfileName := range []string{".devfile.yaml", "devfile.yml", ".devfile.yml"} {
devfileName := devfileName
When(fmt.Sprintf("renaming devfile.yaml into a recognized file name: %s", devfileName), Label(label), func() {
BeforeEach(func() {
err := os.Rename("devfile.yaml", devfileName)
Expect(err).NotTo(HaveOccurred())
})

It("should describe the component in the current directory using the acceptable devfile filename", func() {
By("running with json output", func() {
res := helper.Cmd("odo", "describe", "component", "-o", "json").ShouldPass()
stdout, stderr := res.Out(), res.Err()
Expect(helper.IsJSON(stdout)).To(BeTrue())
Expect(stderr).To(BeEmpty())
checkDevfileJSONDescription(stdout, devfileName)
helper.JsonPathContentIs(stdout, "runningIn", "")
helper.JsonPathContentIs(stdout, "devForwardedPorts", "")
helper.JsonPathDoesNotExist(stdout, "runningOn") // Deprecated
helper.JsonPathDoesNotExist(stdout, "platform")
})

By("running with default output", func() {
res := helper.Cmd("odo", "describe", "component").ShouldPass()
stdout := res.Out()
checkDevfileDescription(stdout, false)
Expect(stdout).To(ContainSubstring("Running in: None"))
Expect(stdout).ToNot(ContainSubstring("Forwarded ports"))
Expect(stdout).ToNot(ContainSubstring("Running on:"))
})
})
})
}

When("renaming devfile.yaml into a non-recognized file name", Label(label), func() {
BeforeEach(func() {
err := os.Rename("devfile.yaml", ".devfile.yaml")
err := os.Rename("devfile.yaml", "some-random-file-as-devfile")
Expect(err).NotTo(HaveOccurred())
})

It("should describe the component in the current directory using the hidden devfile", func() {
It("should not describe the component in the current directory using the acceptable devfile filename", func() {
By("running with json output", func() {
res := helper.Cmd("odo", "describe", "component", "-o", "json").ShouldPass()
res := helper.Cmd("odo", "describe", "component", "-o", "json").ShouldFail()
stdout, stderr := res.Out(), res.Err()
Expect(helper.IsJSON(stdout)).To(BeTrue())
Expect(stderr).To(BeEmpty())
checkDevfileJSONDescription(stdout, ".devfile.yaml")
helper.JsonPathContentIs(stdout, "runningIn", "")
helper.JsonPathContentIs(stdout, "devForwardedPorts", "")
helper.JsonPathDoesNotExist(stdout, "runningOn") // Deprecated
helper.JsonPathDoesNotExist(stdout, "platform")
Expect(helper.IsJSON(stderr)).To(BeTrue())
Expect(stdout).To(BeEmpty())
helper.JsonPathContentContain(stderr, "message", "The current directory does not represent an odo component")
})

By("running with default output", func() {
res := helper.Cmd("odo", "describe", "component").ShouldPass()
stdout := res.Out()
checkDevfileDescription(stdout, false)
Expect(stdout).To(ContainSubstring("Running in: None"))
Expect(stdout).ToNot(ContainSubstring("Forwarded ports"))
Expect(stdout).ToNot(ContainSubstring("Running on:"))
_, stderr := helper.Cmd("odo", "describe", "component").ShouldFail().OutAndErr()
Expect(stderr).Should(ContainSubstring("The current directory does not represent an odo component"))
})
})
})
Expand Down
34 changes: 14 additions & 20 deletions tests/integration/cmd_devfile_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var _ = Describe("odo devfile init command tests", func() {
label := label
var _ = Context("label "+label, Label(label), func() {

It("should fail", func() {
It("odo init should fail", func() {
By("running odo init with incomplete flags", func() {
helper.Cmd("odo", "init", "--name", "aname").ShouldFail()
})
Expand Down Expand Up @@ -76,25 +76,19 @@ var _ = Describe("odo devfile init command tests", func() {
By("using an invalid devfile name", func() {
helper.Cmd("odo", "init", "--name", "aname", "--devfile", "invalid").ShouldFail()
})
By("running odo init in a directory containing a devfile.yaml", func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfile-registry.yaml"),
filepath.Join(commonVar.Context, "devfile.yaml"),
"")
defer os.Remove(filepath.Join(commonVar.Context, "devfile.yaml"))
err := helper.Cmd("odo", "init").ShouldFail().Err()
Expect(err).To(ContainSubstring("a devfile already exists in the current directory"))
})

By("running odo init in a directory containing a .devfile.yaml", func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfile-registry.yaml"),
filepath.Join(commonVar.Context, ".devfile.yaml"),
"")
defer helper.DeleteFile(filepath.Join(commonVar.Context, ".devfile.yaml"))
err := helper.Cmd("odo", "init").ShouldFail().Err()
Expect(err).To(ContainSubstring("a devfile already exists in the current directory"))
})

for _, devfileName := range []string{"devfile.yaml", ".devfile.yaml", "devfile.yml", ".devfile.yml"} {
devfileName := devfileName
By("running odo init in a directory containing a "+devfileName, func() {
helper.CopyExampleDevFile(
filepath.Join("source", "devfiles", "nodejs", "devfile-registry.yaml"),
filepath.Join(commonVar.Context, devfileName),
"")
defer os.Remove(filepath.Join(commonVar.Context, devfileName))
err := helper.Cmd("odo", "init").ShouldFail().Err()
Expect(err).To(ContainSubstring("a devfile already exists in the current directory"))
})
}

By("running odo init with wrong local file path given to --devfile-path", func() {
err := helper.Cmd("odo", "init", "--name", "aname", "--devfile-path", "/some/path/devfile.yaml").ShouldFail().Err()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c840252

Please sign in to comment.