github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/uniter/runner/jujuc/application-version-set_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package jujuc_test
     5  
     6  import (
     7  	"github.com/juju/cmd"
     8  	"github.com/juju/cmd/cmdtesting"
     9  	"github.com/juju/errors"
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/worker/uniter/runner/jujuc"
    14  )
    15  
    16  type ApplicationVersionSetSuite struct {
    17  	ContextSuite
    18  }
    19  
    20  var _ = gc.Suite(&ApplicationVersionSetSuite{})
    21  
    22  func (s *ApplicationVersionSetSuite) createCommand(c *gc.C, err error) (*Context, cmd.Command) {
    23  	hctx := s.GetHookContext(c, -1, "")
    24  	s.Stub.SetErrors(err)
    25  
    26  	com, err := jujuc.NewCommand(hctx, cmdString("application-version-set"))
    27  	c.Assert(err, jc.ErrorIsNil)
    28  	return hctx, jujuc.NewJujucCommandWrappedForTest(com)
    29  }
    30  
    31  func (s *ApplicationVersionSetSuite) TestApplicationVersionSetNoArguments(c *gc.C) {
    32  	hctx, com := s.createCommand(c, nil)
    33  	ctx := cmdtesting.Context(c)
    34  	code := cmd.Main(com, ctx, nil)
    35  	c.Check(code, gc.Equals, 2)
    36  	c.Check(bufferString(ctx.Stdout), gc.Equals, "")
    37  	c.Check(bufferString(ctx.Stderr), gc.Equals, "ERROR no version specified\n")
    38  	c.Check(hctx.info.Version.WorkloadVersion, gc.Equals, "")
    39  }
    40  
    41  func (s *ApplicationVersionSetSuite) TestApplicationVersionSetWithArguments(c *gc.C) {
    42  	hctx, com := s.createCommand(c, nil)
    43  	ctx := cmdtesting.Context(c)
    44  	code := cmd.Main(com, ctx, []string{"dia de los muertos"})
    45  	c.Check(code, gc.Equals, 0)
    46  	c.Check(bufferString(ctx.Stdout), gc.Equals, "")
    47  	c.Check(bufferString(ctx.Stderr), gc.Equals, "")
    48  	c.Check(hctx.info.Version.WorkloadVersion, gc.Equals, "dia de los muertos")
    49  }
    50  
    51  func (s *ApplicationVersionSetSuite) TestApplicationVersionSetError(c *gc.C) {
    52  	hctx, com := s.createCommand(c, errors.New("uh oh spaghettio"))
    53  	ctx := cmdtesting.Context(c)
    54  	code := cmd.Main(com, ctx, []string{"cannae"})
    55  	c.Check(code, gc.Equals, 1)
    56  	c.Check(bufferString(ctx.Stdout), gc.Equals, "")
    57  	c.Check(bufferString(ctx.Stderr), gc.Equals, "ERROR uh oh spaghettio\n")
    58  	c.Check(hctx.info.Version.WorkloadVersion, gc.Equals, "")
    59  }
    60  
    61  func (s *ApplicationVersionSetSuite) TestHelp(c *gc.C) {
    62  
    63  	var helpTemplate = `
    64  Usage: application-version-set <new-version>
    65  
    66  Summary:
    67  specify which version of the application is deployed
    68  
    69  Details:
    70  application-version-set tells Juju which version of the application
    71  software is running. This could be a package version number or some
    72  other useful identifier, such as a Git hash, that indicates the
    73  version of the deployed software. (It shouldn't be confused with the
    74  charm revision.) The version set will be displayed in "juju status"
    75  output for the application.
    76  `[1:]
    77  
    78  	_, com := s.createCommand(c, nil)
    79  	ctx := cmdtesting.Context(c)
    80  	code := cmd.Main(com, ctx, []string{"--help"})
    81  	c.Check(code, gc.Equals, 0)
    82  
    83  	c.Check(bufferString(ctx.Stdout), gc.Equals, helpTemplate)
    84  	c.Check(bufferString(ctx.Stderr), gc.Equals, "")
    85  }