github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/featuretests/package_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package featuretests
     5  
     6  import (
     7  	"flag"
     8  	"runtime"
     9  	"testing"
    10  
    11  	"github.com/juju/cmd"
    12  	"github.com/juju/loggo"
    13  	jc "github.com/juju/testing/checkers"
    14  	gc "gopkg.in/check.v1"
    15  
    16  	jujucmd "github.com/juju/juju/cmd/juju/commands"
    17  	coretesting "github.com/juju/juju/testing"
    18  )
    19  
    20  var runFeatureTests = flag.Bool("featuretests", true, "Run long-running feature tests.")
    21  
    22  func init() {
    23  	flag.Parse()
    24  
    25  	if *runFeatureTests == false {
    26  		return
    27  	}
    28  	// Initialize all suites here.
    29  	gc.Suite(&annotationsSuite{})
    30  	gc.Suite(&CloudAPISuite{})
    31  	gc.Suite(&apiEnvironmentSuite{})
    32  	gc.Suite(&BakeryStorageSuite{})
    33  	gc.Suite(&blockSuite{})
    34  	gc.Suite(&cmdControllerSuite{})
    35  	gc.Suite(&cmdCredentialSuite{})
    36  	gc.Suite(&cmdJujuSuite{})
    37  	gc.Suite(&cmdLoginSuite{})
    38  	gc.Suite(&cmdModelSuite{})
    39  	gc.Suite(&cmdRegistrationSuite{})
    40  	gc.Suite(&cmdStorageSuite{})
    41  	gc.Suite(&cmdSubnetSuite{})
    42  	gc.Suite(&dblogSuite{})
    43  	gc.Suite(&dumpLogsCommandSuite{})
    44  	gc.Suite(&undertakerSuite{})
    45  	gc.Suite(&upgradeSuite{})
    46  	gc.Suite(&CmdRelationSuite{})
    47  
    48  	// TODO (anastasiamac 2016-07-19) Bug#1603585
    49  	// These tests cannot run on windows - they require a bootstrapped controller.
    50  	if runtime.GOOS == "linux" {
    51  		gc.Suite(&cloudImageMetadataSuite{})
    52  		gc.Suite(&cmdSpaceSuite{})
    53  	}
    54  }
    55  
    56  func TestPackage(t *testing.T) {
    57  	coretesting.MgoTestPackage(t)
    58  }
    59  
    60  func runCommand(c *gc.C, args ...string) (*cmd.Context, error) {
    61  	// Writers need to be reset, because
    62  	// they are set globally in the juju/cmd package and will
    63  	// return an error if we attempt to run two commands in the
    64  	// same test.
    65  	loggo.ResetWriters()
    66  	ctx := coretesting.Context(c)
    67  	command := jujucmd.NewJujuCommand(ctx)
    68  	return coretesting.RunCommand(c, command, args...)
    69  }
    70  
    71  func runCommandExpectSuccess(c *gc.C, command string, args ...string) {
    72  	_, err := runCommand(c, append([]string{command}, args...)...)
    73  	c.Assert(err, jc.ErrorIsNil)
    74  }
    75  
    76  func runCommandExpectFailure(c *gc.C, command, expectedError string, args ...string) {
    77  	context, err := runCommand(c, append([]string{command}, args...)...)
    78  	c.Assert(err, gc.ErrorMatches, "cmd: error out silently")
    79  	c.Assert(coretesting.Stderr(context), jc.Contains, expectedError)
    80  }