Skip to content

Commit

Permalink
Test case for unshare and show minimum coverage
Browse files Browse the repository at this point in the history
Signed-off-by: nitin sanghi <er.nitin.sanghi@gmail.com>
  • Loading branch information
sanghinitin committed Mar 22, 2022
1 parent 81937f7 commit 125e16f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/supermarketUnshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var supermarketUnShareCmd = &cobra.Command{
os.Exit(1)
}
var c core.Config
if !ui.ConfirmWithoutExit(config, "Do you really want to unshare all versions of the cookbook starter? (Y/N): ", false, 2) {
ui.Msg("You said no, so I'm done here.")
os.Exit(1)
}
data, path := c.LoadConfig(configPath)
var cc chef.ConfigRb
cc, err := chef.NewClientRb(data, path)
Expand Down
2 changes: 1 addition & 1 deletion core/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (u *UI) ConfirmWithoutExit(config Config, question string, appendInstructio
if config.DefaultValue {
return true
}
u.Msg(question)
fmt.Print(question)
if appendInstructions {
u.Msg(u.ConfirmationInstructions(defaultChoice))
}
Expand Down
35 changes: 35 additions & 0 deletions supermarket/cookbookShow_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package supermarket

import (
"io/ioutil"
"os"
"strings"
"testing"

"github.com/chef/go-chef-cli/core"
)

func TestCookbookShow(t *testing.T) {

var config core.Config
var ui core.UI

rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
ShowCookBook("mysql", "https://supermarket.chef.io", ui, config, "8.5.1")
w.Close()
out, _ := ioutil.ReadAll(r)
os.Stdout = rescueStdout
data := string(out)
if !strings.Contains(data, "https://supermarket.chef.io/api/v1/cookbooks/mysql") {
t.Error("not valid output for mysql")
}
if !strings.Contains(data, "https://supermarket.chef.io/api/v1/cookbooks/mysql") {
t.Error("not valid output for mysql")
}
if !strings.Contains(data, "2017-08-23T19:01:28Z") {
t.Error("not valid output for mysql")
}

}
29 changes: 29 additions & 0 deletions supermarket/unshare_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package supermarket

import (
"os"
"testing"

"github.com/chef/go-chef-cli/core"
"github.com/go-chef/chef"
)

func TestCookbookUnshare(t *testing.T) {

var config core.Config
var ui core.UI

homeDir, _ := os.UserHomeDir()
data, path := config.LoadConfig(homeDir + "/.chef/")
var cc chef.ConfigRb
cc, err := chef.NewClientRb(data, path)
if err != nil {
ui.Fatal("No knife configuration file found. See https://docs.chef.io/config_rb/ for details.")
}
err = UnShareCookbook("mysql", "https://supermarket.chef.io", cc.NodeName, cc.ClientKey)

if err == nil {
t.Error("not valid output for mysql")
}

}

0 comments on commit 125e16f

Please sign in to comment.