Documentation ¶
Overview ¶
Package configtest is used as a helper in tests that need configuration service implementing config.Interface.
Index ¶
- Variables
- func CleanEtcd(t *testing.T, key string)
- func SetupEtcd(t *testing.T, key string)
- func SetupEtcdWrong(t *testing.T, key string)
- func TestSampleConfig(t *testing.T, cfg *config.Config, expectedRawData map[string]interface{})
- type ChildProfile
- type Config
- type SampleConfigType
- type UserProfile
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoData error is returned when predefined configuration data is nil. ErrNoData = errors.New("no data") // ErrNoSuchKey error is returned when requested key is not exists in predefined configuration data. ErrNoSuchKey = errors.New("no such key") // ErrOutputNotPointer error is returned when provided output parameter is not a pointer. ErrOutputNotPointer = errors.New("output must be a pointer") )
var ExpectedSampleConfig = SampleConfigType{ Name: "Peter", Profile: UserProfile{ Sex: "m", Age: 32, Married: true, Children: []ChildProfile{ {Name: "George", Weight: 5.4, Age: 5}, {Name: "Olivia", Weight: 12.2, Age: 12}, }, }, }
ExpectedSampleConfig variable contains expected result of configuration parsing.
var ExpectedSampleRawDataJSON = map[string]interface{}{ "name": "Peter", "profile": map[string]interface{}{ "sex": "m", "age": 32., "married": true, "children": []interface{}{ map[string]interface{}{"name": "George", "weight": 5.4, "age": 5.}, map[string]interface{}{"name": "Olivia", "weight": 12.2, "age": 12.}, }, }, }
ExpectedSampleRawDataJSON variable contains expected raw result of configuration parsing by JSON encoder.
var ExpectedSampleRawDataTOML = map[string]interface{}{ "name": "Peter", "profile": map[string]interface{}{ "sex": "m", "age": int64(32), "married": true, "children": []map[string]interface{}{ {"name": "George", "weight": 5.4, "age": int64(5)}, {"name": "Olivia", "weight": 12.2, "age": int64(12)}, }, }, }
ExpectedSampleRawDataTOML variable contains expected raw result of configuration parsing by TOML encoder.
var ExpectedSampleRawDataYAML = map[string]interface{}{ "name": "Peter", "profile": map[string]interface{}{ "sex": "m", "age": 32, "married": true, "children": []interface{}{ map[string]interface{}{"name": "George", "weight": 5.4, "age": 5}, map[string]interface{}{"name": "Olivia", "weight": 12.2, "age": 12}, }, }, }
ExpectedSampleRawDataYAML variable contains expected raw result of configuration parsing by YAML encoder.
var SampleConfigDataJSON = []byte(`{
"name": "Peter",
"profile": {
"sex": "m",
"age": 32,
"married": true,
"children": [
{ "name": "George", "weight": 5.4, "age": 5},
{ "name": "Olivia", "weight": 12.2, "age": 12}
]
}
}`)
SampleConfigDataJSON variable contains sample configuration as raw JSON data.
var SampleConfigDataTOML = []byte(`
name = "Peter"
[profile]
sex = "m"
age = 32
married = true
[[profile.children]]
name = "George"
weight = 5.4
age = 5
[[profile.children]]
name = "Olivia"
weight = 12.2
age = 12
`)
SampleConfigDataTOML variable contains sample configuration as raw TOML data.
var SampleConfigDataWrongJSON = []byte(`{
"name": "Peter",
`)
SampleConfigDataWrongJSON variable contains sample wrong JSON data.
var SampleConfigDataWrongTOML = []byte(`
name = Peter
`)
SampleConfigDataWrongTOML variable contains sample wrong TOML data.
var SampleConfigDataWrongYAML = []byte(`
name: - Peter
`)
SampleConfigDataWrongYAML variable contains sample wrong YAML data.
var SampleConfigDataYAML = []byte(`
name: Peter
profile:
sex: m
age: 32
married: true
children:
- name: George
weight: 5.4
age: 5
- name: Olivia
weight: 12.2
age: 12
`)
SampleConfigDataYAML variable contains sample configuration as raw YAML data.
Functions ¶
func SetupEtcd ¶
SetupEtcd function prepares etcd for testing by setting provided key to sample config JSON data.
func SetupEtcdWrong ¶
SetupEtcdWrong function prepares etcd for testing by setting provided key to sample wrong config JSON data.
Types ¶
type ChildProfile ¶
ChildProfile structure used as inner aggregate type sample configuration.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config structure implementing config.Interface.
func (*Config) Get ¶
Get method fills structure that 'out' parameter points to with predefined data under empty key. It will return an error if 'out' is not a pointer or predefined data is nil. If empty key contains an error that error will be returned.
func (*Config) GetByKey ¶
GetByKey method fills structure that 'out' parameter points to with predefined data under the provided key. It will return an error if 'out' is not a pointer or predefined data is nil or there is no such key in that data. If corresponding key contains an error that error will be returned.
func (*Config) IsNoSuchKeyError ¶
IsNoSuchKeyError checks if provided error is 'NoSuchKey' one.
type SampleConfigType ¶
type SampleConfigType struct { Name string Profile UserProfile }
SampleConfigType structure used for sample configuration.
type UserProfile ¶
type UserProfile struct { Sex string Age int Married bool Children []ChildProfile }
UserProfile structure used as inner type in sample configuration.