~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/bundlechanges/changes_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import (
7
7
        "encoding/json"
 
8
        "fmt"
8
9
        "reflect"
9
10
        "strings"
10
11
        "testing"
84
85
                annotations:
85
86
                    gui-x: "609"
86
87
                    gui-y: "-15"
 
88
                resources:
 
89
                    data: 3
87
90
            mysql:
88
91
                charm: cs:precise/mysql-28
89
92
                num_units: 1
103
106
                Id:     "deploy-1",
104
107
                Method: "deploy",
105
108
                Params: bundlechanges.AddServiceParams{
106
 
                        Charm:   "$addCharm-0",
107
 
                        Service: "mediawiki",
108
 
                        Options: map[string]interface{}{"debug": false},
 
109
                        Charm:     "$addCharm-0",
 
110
                        Service:   "mediawiki",
 
111
                        Options:   map[string]interface{}{"debug": false},
 
112
                        Resources: map[string]int{"data": 3},
109
113
                },
110
114
                GUIArgs: []interface{}{
111
115
                        "$addCharm-0",
1195
1199
        }},
1196
1200
}}
1197
1201
 
 
1202
func (s *changesSuite) assertParseData(c *gc.C, content string, expected []record) {
 
1203
        // Retrieve and validate the bundle data.
 
1204
        data, err := charm.ReadBundleData(strings.NewReader(content))
 
1205
        c.Assert(err, jc.ErrorIsNil)
 
1206
        err = data.Verify(nil, nil)
 
1207
        c.Assert(err, jc.ErrorIsNil)
 
1208
 
 
1209
        // Retrieve the changes, and convert them to a sequence of records.
 
1210
        changes := bundlechanges.FromData(data)
 
1211
        records := make([]record, len(changes))
 
1212
        for i, change := range changes {
 
1213
                r := record{
 
1214
                        Id:       change.Id(),
 
1215
                        Requires: change.Requires(),
 
1216
                        Method:   change.Method(),
 
1217
                        GUIArgs:  change.GUIArgs(),
 
1218
                }
 
1219
                r.Params = reflect.ValueOf(change).Elem().FieldByName("Params").Interface()
 
1220
                records[i] = r
 
1221
        }
 
1222
 
 
1223
        // Output the records for debugging.
 
1224
        b, err := json.MarshalIndent(records, "", "  ")
 
1225
        c.Assert(err, jc.ErrorIsNil)
 
1226
        c.Logf("obtained records: %s", b)
 
1227
 
 
1228
        // Check that the obtained records are what we expect.
 
1229
        c.Assert(records, jc.DeepEquals, expected)
 
1230
}
 
1231
 
1198
1232
func (s *changesSuite) TestFromData(c *gc.C) {
1199
1233
        for i, test := range fromDataTests {
1200
1234
                c.Logf("test %d: %s", i, test.about)
1201
 
 
1202
 
                // Retrieve and validate the bundle data.
1203
 
                data, err := charm.ReadBundleData(strings.NewReader(test.content))
1204
 
                c.Assert(err, jc.ErrorIsNil)
1205
 
                err = data.Verify(nil, nil)
1206
 
                c.Assert(err, jc.ErrorIsNil)
1207
 
 
1208
 
                // Retrieve the changes, and convert them to a sequence of records.
1209
 
                changes := bundlechanges.FromData(data)
1210
 
                records := make([]record, len(changes))
1211
 
                for i, change := range changes {
1212
 
                        r := record{
1213
 
                                Id:       change.Id(),
1214
 
                                Requires: change.Requires(),
1215
 
                                Method:   change.Method(),
1216
 
                                GUIArgs:  change.GUIArgs(),
1217
 
                        }
1218
 
                        r.Params = reflect.ValueOf(change).Elem().FieldByName("Params").Interface()
1219
 
                        records[i] = r
1220
 
                }
1221
 
 
1222
 
                // Output the records for debugging.
1223
 
                b, err := json.MarshalIndent(records, "", "  ")
1224
 
                c.Assert(err, jc.ErrorIsNil)
1225
 
                c.Logf("obtained records: %s", b)
1226
 
 
1227
 
                // Check that the obtained records are what we expect.
1228
 
                c.Assert(records, jc.DeepEquals, test.expected)
 
1235
                s.assertParseData(c, test.content, test.expected)
1229
1236
        }
1230
1237
}
 
1238
 
 
1239
func (s *changesSuite) TestLocalCharmWithSeries(c *gc.C) {
 
1240
        charmDir := c.MkDir()
 
1241
        content := fmt.Sprintf(`
 
1242
        services:
 
1243
            django:
 
1244
                charm: %s
 
1245
                series: xenial
 
1246
    `, charmDir)
 
1247
        expected := []record{{
 
1248
                Id:     "addCharm-0",
 
1249
                Method: "addCharm",
 
1250
                Params: bundlechanges.AddCharmParams{
 
1251
                        Charm:  charmDir,
 
1252
                        Series: "xenial",
 
1253
                },
 
1254
                GUIArgs: []interface{}{charmDir},
 
1255
        }, {
 
1256
                Id:     "deploy-1",
 
1257
                Method: "deploy",
 
1258
                Params: bundlechanges.AddServiceParams{
 
1259
                        Charm:   "$addCharm-0",
 
1260
                        Service: "django",
 
1261
                },
 
1262
                GUIArgs: []interface{}{
 
1263
                        "$addCharm-0",
 
1264
                        "django",
 
1265
                        map[string]interface{}{},
 
1266
                        "",
 
1267
                        map[string]string{},
 
1268
                        map[string]string{},
 
1269
                },
 
1270
                Requires: []string{"addCharm-0"},
 
1271
        }}
 
1272
        s.assertParseData(c, content, expected)
 
1273
}