~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/undertaker/validate_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package undertaker_test
 
5
 
 
6
import (
 
7
        "github.com/juju/errors"
 
8
        "github.com/juju/testing"
 
9
        jc "github.com/juju/testing/checkers"
 
10
        gc "gopkg.in/check.v1"
 
11
 
 
12
        "github.com/juju/juju/worker/undertaker"
 
13
)
 
14
 
 
15
type ValidateSuite struct {
 
16
        testing.IsolationSuite
 
17
}
 
18
 
 
19
var _ = gc.Suite(&ValidateSuite{})
 
20
 
 
21
func (*ValidateSuite) TestNilFacade(c *gc.C) {
 
22
        config := validConfig()
 
23
        config.Facade = nil
 
24
        checkInvalid(c, config, "nil Facade not valid")
 
25
}
 
26
 
 
27
func (*ValidateSuite) TestNilEnviron(c *gc.C) {
 
28
        config := validConfig()
 
29
        config.Environ = nil
 
30
        checkInvalid(c, config, "nil Environ not valid")
 
31
}
 
32
 
 
33
func validConfig() undertaker.Config {
 
34
        return undertaker.Config{
 
35
                Facade:  &fakeFacade{},
 
36
                Environ: &fakeEnviron{},
 
37
        }
 
38
}
 
39
 
 
40
func checkInvalid(c *gc.C, config undertaker.Config, message string) {
 
41
        check := func(err error) {
 
42
                c.Check(err, jc.Satisfies, errors.IsNotValid)
 
43
                c.Check(err, gc.ErrorMatches, message)
 
44
        }
 
45
        err := config.Validate()
 
46
        check(err)
 
47
 
 
48
        worker, err := undertaker.NewUndertaker(config)
 
49
        c.Check(worker, gc.IsNil)
 
50
        check(err)
 
51
}