Skip to content

Commit

Permalink
PR Feedback Test
Browse files Browse the repository at this point in the history
  • Loading branch information
tedteng committed Nov 9, 2022
1 parent 4e736e2 commit 825da9f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/target/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ package target
var (
ValidTargetArgsFunction = validTargetArgsFunction
ToHistoryOutput = toHistoryOutput
ToHistoryParse = toHistoryParse
ToCommand = toCommand
HistoryWrite = historyWrite
)
13 changes: 6 additions & 7 deletions pkg/cmd/target/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ func toHistoryOutput(path string, o base.Options) error {
return err
}

// toHistoryParse executes target history parse from current target
func toHistoryParse(currentTarget target.Target) (string, error) {
// toCommand executes target history parse from current target
func toCommand(currentTarget target.Target) (string, error) {
var (
flags []string
targetString = "target"
flags []string
)

if currentTarget.GardenName() != "" {
Expand All @@ -128,7 +127,7 @@ func toHistoryParse(currentTarget target.Target) (string, error) {
flags = append(flags, "--control-plane")
}

return fmt.Sprintln(os.Args[0], targetString, strings.Join(flags, " ")), nil
return fmt.Sprintln(os.Args[0], "target", strings.Join(flags, " ")), nil
}

// Run does the actual work of the command.
Expand All @@ -148,12 +147,12 @@ func (o *HistoryWriteOptions) Run(f util.Factory) error {
return fmt.Errorf("failed to get current target: %w", err)
}

toHistoryParse, err := toHistoryParse(currentTarget)
toCommand, err := toCommand(currentTarget)
if err != nil {
return err
}

return historyWrite(o.path, toHistoryParse)
return historyWrite(o.path, toCommand)
}

// Complete adapts from the command line args to the data required.
Expand Down
18 changes: 7 additions & 11 deletions pkg/cmd/target/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,30 @@ var _ = Describe("history Command", func() {
})
})

Describe("#HistoryWrite", func() {
Describe("#HistoryWrite and ToHistoryOutput ", func() {
It("should write history file", func() {
err := cmdtarget.HistoryWrite(historyPath, "hello")
Expect(err).NotTo(HaveOccurred())
})
})

Describe("#ToHistoryOutput", func() {
It("should print history output", func() {
err := cmdtarget.ToHistoryOutput(historyPath, *options)
Expect(err).NotTo(HaveOccurred())
Expect(out.String()).Should(ContainSubstring("hello"))
})
})

Describe("#ToHistoryOutput", func() {
It("should print history output from command level", func() {
o := cmdtarget.NewHistoryOptions(streams)
cmd := cmdtarget.NewCmdTarget(factory, streams)
err := o.Complete(factory, cmd, os.Args)
Expect(err).NotTo(HaveOccurred())
err = o.Run(factory)
Expect(err).NotTo(HaveOccurred())
cmd := cmdtarget.NewCmdHistory(factory, o)
Expect(cmd.RunE(cmd, nil)).To(Succeed())
Expect(out.String()).Should(ContainSubstring("target --garden mygarden --project myproject --shoot myshoot"))
})
})

Describe("#ToHistoryParse", func() {
Describe("#toCommand", func() {
It("should succeed execute history parse", func() {
string, err := cmdtarget.ToHistoryParse(currentTarget)
string, err := cmdtarget.ToCommand(currentTarget)
Expect(err).NotTo(HaveOccurred())
Expect(string).Should((ContainSubstring("target --garden mygarden --project myproject --shoot myshoot")))
})
Expand Down

0 comments on commit 825da9f

Please sign in to comment.