github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/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  	"strings"
     8  
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/testing"
    12  )
    13  
    14  type HelpToolSuite struct {
    15  	testing.FakeJujuXDGDataHomeSuite
    16  }
    17  
    18  var _ = gc.Suite(&HelpToolSuite{})
    19  
    20  func (suite *HelpToolSuite) SetUpTest(c *gc.C) {
    21  	suite.FakeJujuXDGDataHomeSuite.SetUpTest(c)
    22  	setFeatureFlags("")
    23  }
    24  
    25  func (suite *HelpToolSuite) TestHelpToolHelp(c *gc.C) {
    26  	output := badrun(c, 0, "help", "help-tool")
    27  	c.Assert(output, gc.Equals, `Usage: juju help-tool [tool]
    28  
    29  Summary:
    30  Show help on a Juju charm hook tool.
    31  
    32  Global Options:
    33  --debug  (= false)
    34      Equivalent to --show-log --logging-config=<root>=DEBUG
    35  -h, --help  (= false)
    36      Show help on a command or other topic.
    37  --logging-config (= "")
    38      Specify log levels for modules
    39  --quiet  (= false)
    40      Show no informational output
    41  --show-log  (= false)
    42      If set, write the log file to stderr
    43  --verbose  (= false)
    44      Show more verbose output
    45  
    46  Details:
    47  Juju charms can access a series of built-in helpers called 'hook-tools'.
    48  These are useful for the charm to be able to inspect its running environment.
    49  Currently available charm hook tools are:
    50  
    51      action-fail              set action fail status with message
    52      action-get               get action parameters
    53      action-log               record a progress message for the current action
    54      action-set               set action results
    55      add-metric               add metrics
    56      application-version-set  specify which version of the application is deployed
    57      close-port               register a request to close a port or port range
    58      config-get               print application configuration
    59      credential-get           access cloud credentials
    60      goal-state               print the status of the charm's peers and related units
    61      is-leader                print application leadership status
    62      juju-log                 write a message to the juju log
    63      juju-reboot              Reboot the host machine
    64      k8s-raw-get              get k8s raw spec information
    65      k8s-raw-set              set k8s raw spec information
    66      k8s-spec-get             get k8s spec information
    67      k8s-spec-set             set k8s spec information
    68      leader-get               print application leadership settings
    69      leader-set               write application leadership settings
    70      network-get              get network config
    71      open-port                register a request to open a port or port range
    72      opened-ports             list all ports or port ranges opened by the unit
    73      payload-register         register a charm payload with juju
    74      payload-status-set       update the status of a payload
    75      payload-unregister       stop tracking a payload
    76      pod-spec-get             get k8s spec information (deprecated)
    77      pod-spec-set             set k8s spec information (deprecated)
    78      relation-get             get relation settings
    79      relation-ids             list all relation ids with the given relation name
    80      relation-list            list relation units
    81      relation-set             set relation settings
    82      resource-get             get the path to the locally cached resource file
    83      secret-add               add a new secret
    84      secret-get               get the content of a secret
    85      secret-grant             grant access to a secret
    86      secret-ids               print secret ids
    87      secret-info-get          get a secret's metadata info
    88      secret-remove            remove a existing secret
    89      secret-revoke            revoke access to a secret
    90      secret-set               update an existing secret
    91      state-delete             delete server-side-state key value pair
    92      state-get                print server-side-state value
    93      state-set                set server-side-state values
    94      status-get               print status information
    95      status-set               set status information
    96      storage-add              add storage instances
    97      storage-get              print information for storage instance with specified id
    98      storage-list             list storage attached to the unit
    99      unit-get                 print public-address or private-address
   100  
   101  Examples:
   102  
   103  For help on a specific tool, supply the name of that tool, for example:
   104  
   105          juju help-tool unit-get
   106  `)
   107  }
   108  
   109  var expectedCommands = []string{
   110  	"action-fail",
   111  	"action-get",
   112  	"action-log",
   113  	"action-set",
   114  	"add-metric",
   115  	"application-version-set",
   116  	"close-port",
   117  	"config-get",
   118  	"credential-get",
   119  	"goal-state",
   120  	"is-leader",
   121  	"juju-log",
   122  	"juju-reboot",
   123  	"k8s-raw-get",
   124  	"k8s-raw-set",
   125  	"k8s-spec-get",
   126  	"k8s-spec-set",
   127  	"leader-get",
   128  	"leader-set",
   129  	"network-get",
   130  	"open-port",
   131  	"opened-ports",
   132  	"payload-register",
   133  	"payload-status-set",
   134  	"payload-unregister",
   135  	"pod-spec-get",
   136  	"pod-spec-set",
   137  	"relation-get",
   138  	"relation-ids",
   139  	"relation-list",
   140  	"relation-set",
   141  	"resource-get",
   142  	"secret-add",
   143  	"secret-get",
   144  	"secret-grant",
   145  	"secret-ids",
   146  	"secret-info-get",
   147  	"secret-remove",
   148  	"secret-revoke",
   149  	"secret-set",
   150  	"state-delete",
   151  	"state-get",
   152  	"state-set",
   153  	"status-get",
   154  	"status-set",
   155  	"storage-add",
   156  	"storage-get",
   157  	"storage-list",
   158  	"unit-get",
   159  }
   160  
   161  func (suite *HelpToolSuite) TestHelpTool(c *gc.C) {
   162  	output := badrun(c, 0, "help-tool")
   163  	lines := strings.Split(strings.TrimSpace(output), "\n")
   164  	for i, line := range lines {
   165  		command := strings.Fields(line)[0]
   166  		lines[i] = command
   167  	}
   168  	c.Assert(lines, gc.DeepEquals, expectedCommands)
   169  }
   170  
   171  func (suite *HelpToolSuite) TestHelpToolName(c *gc.C) {
   172  	var output string
   173  	output = badrun(c, 0, "help-tool", "relation-get")
   174  	expectedHelp := `Usage: relation-get \[options\] <key> <unit id>
   175  
   176  Summary:
   177  get relation settings
   178  
   179  Options:
   180  (.|\n)*
   181  
   182  Details:
   183  relation-get prints the value(.|\n)*`
   184  	c.Assert(output, gc.Matches, expectedHelp)
   185  }