~axwalk/juju-core/lp1303195-manual-ubuntuuser-bash

« back to all changes in this revision

Viewing changes to state/conn_test.go

[r=wallyworld] Add constraints validation to providers

Each provider has a constraints validator which
is used when setting constraints on a machine or
service, as well as when constraints are merged.
The validation step allows conflicting constraints
like instance-type and mem to be rejected, and also
unsupported constraints to be logged with a warning.
The merge step allows things like instance-type to
mask other incompatible constraints like mem or arch,
and visa versa.

https://codereview.appspot.com/88780043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
        "labix.org/v2/mgo"
10
10
        gc "launchpad.net/gocheck"
11
11
 
 
12
        "launchpad.net/juju-core/constraints"
12
13
        "launchpad.net/juju-core/environs/config"
13
14
        "launchpad.net/juju-core/errors"
14
15
        "launchpad.net/juju-core/state"
101
102
}
102
103
 
103
104
type mockPolicy struct {
104
 
        getPrechecker        func(*config.Config) (state.Prechecker, error)
105
 
        getConfigValidator   func(string) (state.ConfigValidator, error)
106
 
        getEnvironCapability func(*config.Config) (state.EnvironCapability, error)
 
105
        getPrechecker           func(*config.Config) (state.Prechecker, error)
 
106
        getConfigValidator      func(string) (state.ConfigValidator, error)
 
107
        getEnvironCapability    func(*config.Config) (state.EnvironCapability, error)
 
108
        getConstraintsValidator func(*config.Config) (constraints.Validator, error)
107
109
}
108
110
 
109
111
func (p *mockPolicy) Prechecker(cfg *config.Config) (state.Prechecker, error) {
126
128
        }
127
129
        return nil, errors.NotImplementedf("EnvironCapability")
128
130
}
 
131
 
 
132
func (p *mockPolicy) ConstraintsValidator(cfg *config.Config) (constraints.Validator, error) {
 
133
        if p.getConstraintsValidator != nil {
 
134
                return p.getConstraintsValidator(cfg)
 
135
        }
 
136
        return nil, errors.NewNotImplemented(nil, "ConstraintsValidator")
 
137
}