Skip to content

Commit

Permalink
Fix odo config view (#5234)
Browse files Browse the repository at this point in the history
* fix odo config view

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* add test for odo config view

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* use genericclioptions.New

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* update failcase check

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* remove commented code

Signed-off-by: anandrkskd <anandrkskd@gmail.com>
  • Loading branch information
anandrkskd committed Nov 22, 2021
1 parent 0a41d4d commit 7f8efcc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
22 changes: 5 additions & 17 deletions pkg/odo/cli/config/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import (
"os"
"text/tabwriter"

"github.com/devfile/library/pkg/devfile/parser"
"github.com/openshift/odo/pkg/component"
"github.com/openshift/odo/pkg/devfile/location"
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/machineoutput"
"github.com/openshift/odo/pkg/odo/genericclioptions"
"github.com/openshift/odo/pkg/util"
"github.com/spf13/cobra"
ktemplates "k8s.io/kubectl/pkg/util/templates"
"sigs.k8s.io/yaml"
Expand All @@ -26,10 +23,8 @@ var viewExample = ktemplates.Examples(`# For viewing the current configuration f

// ViewOptions encapsulates the options for the command
type ViewOptions struct {
contextDir string
devfilePath string
devfileObj parser.DevfileObj
IsDevfile bool
contextDir string
*genericclioptions.Context
}

// NewViewOptions creates a new ViewOptions instance
Expand All @@ -39,15 +34,8 @@ func NewViewOptions() *ViewOptions {

// Complete completes ViewOptions after they've been created
func (o *ViewOptions) Complete(name string, cmd *cobra.Command, args []string) (err error) {
devfilePath := location.DevfileLocation(o.contextDir)
if util.CheckPathExists(devfilePath) {
o.devfilePath = devfilePath
o.IsDevfile = true
o.devfileObj, err = parser.Parse(o.devfilePath)
if err != nil {
return err
}
}
params := genericclioptions.NewCreateParameters(cmd).NeedDevfile(o.contextDir)
o.Context, err = genericclioptions.New(params)
return
}

Expand All @@ -59,7 +47,7 @@ func (o *ViewOptions) Validate() (err error) {
// Run contains the logic for the command
func (o *ViewOptions) Run(cmd *cobra.Command) (err error) {
w := tabwriter.NewWriter(os.Stdout, 5, 2, 2, ' ', tabwriter.TabIndent)
repr, err := component.ToDevfileRepresentation(o.devfileObj)
repr, err := component.ToDevfileRepresentation(o.Context.EnvSpecificInfo.GetDevfileObj())
if err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/cmd_pref_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ var _ = Describe("odo preference and config command tests", func() {
})
})

When("running odo config view", func() {
It("should pass if devfile is present in current dir", func() {
helper.Chdir(commonVar.Context)
cmpName := helper.RandString(6)
helper.Cmd("odo", "create", cmpName, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass()
out := helper.Cmd("odo", "config", "view").ShouldPass().Out()
helper.MatchAllInOutput(out, []string{"runtime", "Memory: 1024Mi"})
})

It("should fail if devfile not present in current dir", func() {
err := helper.Cmd("odo", "config", "view").ShouldFail().Err()
Expect(err).To(ContainSubstring("the current directory does not represent an odo component."))
})
})

Context("When viewing global config", func() {
var newContext string
// ConsentTelemetry is set to false in helper.CommonBeforeEach so that it does not prompt to set a value
Expand Down

0 comments on commit 7f8efcc

Please sign in to comment.