github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/commands/helptool_test.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package commands
     5  
     6  import (
     7  	"fmt"
     8  	"runtime"
     9  	"strings"
    10  
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/testing"
    14  )
    15  
    16  type HelpToolSuite struct {
    17  	testing.FakeJujuXDGDataHomeSuite
    18  }
    19  
    20  var _ = gc.Suite(&HelpToolSuite{})
    21  
    22  func (suite *HelpToolSuite) TestHelpToolHelp(c *gc.C) {
    23  	output := badrun(c, 0, "help", "help-tool")
    24  	c.Assert(output, gc.Equals, `Usage: juju hook-tool [tool]
    25  
    26  Summary:
    27  Show help on a Juju charm hook tool.
    28  
    29  Global Options:
    30  --debug  (= false)
    31      equivalent to --show-log --logging-config=<root>=DEBUG
    32  -h, --help  (= false)
    33      Show help on a command or other topic.
    34  --logging-config (= "")
    35      specify log levels for modules
    36  --quiet  (= false)
    37      show no informational output
    38  --show-log  (= false)
    39      if set, write the log file to stderr
    40  --verbose  (= false)
    41      show more verbose output
    42  
    43  Details:
    44  Juju charms can access a series of built-in helpers called 'hook-tools'.
    45  These are useful for the charm to be able to inspect its running environment.
    46  Currently available charm hook tools are:
    47  
    48      action-fail              set action fail status with message
    49      action-get               get action parameters
    50      action-set               set action results
    51      add-metric               add metrics
    52      application-version-set  specify which version of the application is deployed
    53      close-port               ensure a port or range is always closed
    54      config-get               print application configuration
    55      credential-get           access cloud credentials
    56      goal-state               print the status of the charm's peers and related units
    57      is-leader                print application leadership status
    58      juju-log                 write a message to the juju log
    59      juju-reboot              Reboot the host machine
    60      leader-get               print application leadership settings
    61      leader-set               write application leadership settings
    62      network-get              get network config
    63      open-port                register a port or range to open
    64      opened-ports             lists all ports or ranges opened by the unit
    65      pod-spec-set             set pod spec information
    66      relation-get             get relation settings
    67      relation-ids             list all relation ids with the given relation name
    68      relation-list            list relation units
    69      relation-set             set relation settings
    70      status-get               print status information
    71      status-set               set status information
    72      storage-add              add storage instances
    73      storage-get              print information for storage instance with specified id
    74      storage-list             list storage attached to the unit
    75      unit-get                 print public-address or private-address
    76  
    77  Examples:
    78  
    79      For help on a specific tool, supply the name of that tool, for example:
    80  
    81          juju hook-tool unit-get
    82  
    83  Aliases: help-tool, hook-tools
    84  `)
    85  }
    86  
    87  var expectedCommands = []string{
    88  	"action-fail",
    89  	"action-get",
    90  	"action-set",
    91  	"add-metric",
    92  	"application-version-set",
    93  	"close-port",
    94  	"config-get",
    95  	"credential-get",
    96  	"goal-state",
    97  	"is-leader",
    98  	"juju-log",
    99  	"juju-reboot",
   100  	"leader-get",
   101  	"leader-set",
   102  	"network-get",
   103  	"open-port",
   104  	"opened-ports",
   105  	"payload-register",
   106  	"payload-status-set",
   107  	"payload-unregister",
   108  	"pod-spec-set",
   109  	"relation-get",
   110  	"relation-ids",
   111  	"relation-list",
   112  	"relation-set",
   113  	"resource-get",
   114  	"status-get",
   115  	"status-set",
   116  	"storage-add",
   117  	"storage-get",
   118  	"storage-list",
   119  	"unit-get",
   120  }
   121  
   122  func (suite *HelpToolSuite) TestHelpTool(c *gc.C) {
   123  	output := badrun(c, 0, "help-tool")
   124  	lines := strings.Split(strings.TrimSpace(output), "\n")
   125  	template := "%v"
   126  	if runtime.GOOS == "windows" {
   127  		template = "%v.exe"
   128  		for i, aCmd := range expectedCommands {
   129  			expectedCommands[i] = fmt.Sprintf(template, aCmd)
   130  		}
   131  	}
   132  	for i, line := range lines {
   133  		command := strings.Fields(line)[0]
   134  		lines[i] = fmt.Sprintf(template, command)
   135  	}
   136  	c.Assert(lines, gc.DeepEquals, expectedCommands)
   137  }
   138  
   139  func (suite *HelpToolSuite) TestHelpToolName(c *gc.C) {
   140  	var output string
   141  	if runtime.GOOS == "windows" {
   142  		output = badrun(c, 0, "help-tool", "relation-get.exe")
   143  	} else {
   144  		output = badrun(c, 0, "help-tool", "relation-get")
   145  	}
   146  	expectedHelp := `Usage: relation-get \[options\] <key> <unit id>
   147  
   148  Summary:
   149  get relation settings
   150  
   151  Options:
   152  (.|\n)*
   153  
   154  Details:
   155  relation-get prints the value(.|\n)*`
   156  	c.Assert(output, gc.Matches, expectedHelp)
   157  }