Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(84)

Unified Diff: charm/config_test.go

Issue 7405049: charm: Add config.Convert() (Closed)
Patch Set: charm: Add config.Convert() Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « charm/config.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: charm/config_test.go
=== modified file 'charm/config_test.go'
--- charm/config_test.go 2013-02-11 05:51:12 +0000
+++ charm/config_test.go 2013-02-27 08:18:52 +0000
@@ -189,3 +189,68 @@
c.Assert(output, IsNil)
c.Assert(err, ErrorMatches, `Unknown configuration option: "bad"`)
}
+
+var convertTests = []struct {
+ summary string
+ input map[string]interface{}
+ expect map[string]interface{}
+ err string
+}{{
+ // Schema defaults are ignored.
+ summary: "valid strings",
+ input: map[string]interface{}{
+ "title": "Helpful Title",
+ "outlook": "Peachy",
+ },
+ expect: map[string]interface{}{
+ "title": "Helpful Title",
+ "outlook": "Peachy",
+ },
+}, {
+ // Integers are always int64 in YAML, where the input is usually coming from.
+ summary: "valid integers and floats",
+ input: map[string]interface{}{
+ "agility-ratio": 0.5,
+ "skill-level": int64(7),
+ },
+ expect: map[string]interface{}{
+ "agility-ratio": 0.5,
+ "skill-level": int64(7),
+ },
+}, {
+ summary: "valid booleans",
+ input: map[string]interface{}{"reticulate-splines": true},
+ expect: map[string]interface{}{"reticulate-splines": true},
+}, {
+ summary: "invalid type error with floats",
+ input: map[string]interface{}{"agility-ratio": "bar"},
+ err: `unexpected type in service configuration "agility-ratio"="bar"; expected float`,
+}, {
+ summary: "invalid type error with integers",
+ input: map[string]interface{}{"skill-level": "foo"},
+ err: `unexpected type in service configuration "skill-level"="foo"; expected int`,
+}, {
+ summary: "invalid type error with booleans",
+ input: map[string]interface{}{"reticulate-splines": "maybe"},
+ err: `unexpected type in service configuration "reticulate-splines"="maybe"; expected boolean`,
+}, {
+ summary: "with value not in the schema (ignored)",
+ input: map[string]interface{}{"bad": "value"},
+ expect: map[string]interface{}{},
+}}
+
+func (s *ConfigSuite) TestConvert(c *C) {
+ config, err := charm.ReadConfig(bytes.NewBuffer([]byte(sampleConfig)))
+ c.Assert(err, IsNil)
+
+ for i, t := range convertTests {
+ c.Logf("test %d: %s", i, t.summary)
+ output, err := config.Convert(t.input)
+ if t.err != "" {
+ c.Assert(err, ErrorMatches, t.err)
+ } else {
+ c.Assert(err, IsNil)
+ c.Assert(output, DeepEquals, t.expect)
+ }
+ }
+}
« no previous file with comments | « charm/config.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b