~ubuntu-branches/ubuntu/saucy/juju-core/saucy-updates

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/cmd/juju/synctools_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-09-03 14:22:22 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20130903142222-9mes2r8wqr0bs7lp
Tags: 1.13.3-0ubuntu1
New upstream point release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
        "launchpad.net/juju-core/cmd"
13
13
        "launchpad.net/juju-core/environs"
14
14
        "launchpad.net/juju-core/environs/sync"
15
 
        envtesting "launchpad.net/juju-core/environs/testing"
16
15
        "launchpad.net/juju-core/provider/dummy"
17
16
        coretesting "launchpad.net/juju-core/testing"
 
17
        jc "launchpad.net/juju-core/testing/checkers"
18
18
)
19
19
 
20
20
type syncToolsSuite struct {
42
42
        var err error
43
43
        s.targetEnv, err = environs.NewFromName("test-target")
44
44
        c.Assert(err, gc.IsNil)
45
 
        envtesting.RemoveAllTools(c, s.targetEnv)
46
45
        s.origSyncTools = syncTools
47
46
}
48
47
 
74
73
        {
75
74
                description: "environment as only argument",
76
75
                args:        []string{"-e", "test-target"},
77
 
                sctx: &sync.SyncContext{
78
 
                        EnvName: "test-target",
79
 
                },
 
76
                sctx:        &sync.SyncContext{},
80
77
        },
81
78
        {
82
79
                description: "specifying also the synchronization source",
83
80
                args:        []string{"-e", "test-target", "--source", "/foo/bar"},
84
81
                sctx: &sync.SyncContext{
85
 
                        EnvName: "test-target",
86
 
                        Source:  "/foo/bar",
 
82
                        Source: "/foo/bar",
87
83
                },
88
84
        },
89
85
        {
90
86
                description: "synchronize all version including development",
91
87
                args:        []string{"-e", "test-target", "--all", "--dev"},
92
88
                sctx: &sync.SyncContext{
93
 
                        EnvName:     "test-target",
94
89
                        AllVersions: true,
95
90
                        Dev:         true,
96
91
                },
99
94
                description: "synchronize to public bucket",
100
95
                args:        []string{"-e", "test-target", "--public"},
101
96
                sctx: &sync.SyncContext{
102
 
                        EnvName:      "test-target",
103
97
                        PublicBucket: true,
104
98
                },
105
99
        },
107
101
                description: "just make a dry run",
108
102
                args:        []string{"-e", "test-target", "--dry-run"},
109
103
                sctx: &sync.SyncContext{
110
 
                        EnvName: "test-target",
111
 
                        DryRun:  true,
 
104
                        DryRun: true,
112
105
                },
113
106
        },
114
107
}
115
108
 
 
109
func (s *syncToolsSuite) Reset(c *gc.C) {
 
110
        s.TearDownTest(c)
 
111
        s.SetUpTest(c)
 
112
}
 
113
 
116
114
func (s *syncToolsSuite) TestSyncToolsCommand(c *gc.C) {
117
 
        for _, test := range tests {
118
 
                c.Log(test.description)
119
 
                called := make(chan struct{}, 1)
 
115
        for i, test := range tests {
 
116
                c.Logf("test %d: %s", i, test.description)
 
117
                called := false
120
118
                syncTools = func(sctx *sync.SyncContext) error {
121
 
                        c.Assert(sctx.EnvName, gc.Equals, test.sctx.EnvName)
 
119
                        env := sctx.Target.(environs.Environ)
 
120
                        c.Assert(env.Name(), gc.Equals, s.targetEnv.Name())
122
121
                        c.Assert(sctx.AllVersions, gc.Equals, test.sctx.AllVersions)
123
122
                        c.Assert(sctx.DryRun, gc.Equals, test.sctx.DryRun)
124
123
                        c.Assert(sctx.PublicBucket, gc.Equals, test.sctx.PublicBucket)
125
124
                        c.Assert(sctx.Dev, gc.Equals, test.sctx.Dev)
126
125
                        c.Assert(sctx.Source, gc.Equals, test.sctx.Source)
127
 
                        called <- struct{}{}
 
126
                        s.targetEnv.Storage() // This will panic if the environment is not prepared.
 
127
                        called = true
128
128
                        return nil
129
129
                }
130
130
                ctx, err := runSyncToolsCommand(c, test.args...)
131
131
                c.Assert(err, gc.IsNil)
132
132
                c.Assert(ctx, gc.NotNil)
133
 
                c.Assert(wait(called), gc.IsNil)
 
133
                c.Assert(called, jc.IsTrue)
 
134
                s.Reset(c)
134
135
        }
135
136
}