~rogpeppe/juju-core/438-local-instance-Addresses

« back to all changes in this revision

Viewing changes to environs/sshstorage/storage_test.go

[r=axwalk],[bug=1234125] provider/null: fix intermittent test failure

Also, in environs/sshstorage (related to test failure):
capture command output in case of outer ssh/bash command
failure.

Fixes #1234125

https://codereview.appspot.com/14315044/

Show diffs side-by-side

added added

removed removed

Lines of Context:
151
151
        c.Assert(err, jc.Satisfies, coreerrors.IsNotFoundError)
152
152
}
153
153
 
 
154
func (s *storageSuite) TestWriteFailure(c *gc.C) {
 
155
        // Invocations:
 
156
        //  1: first "install"
 
157
        //  2: touch, Put
 
158
        //  3: second "install"
 
159
        //  4: touch
 
160
        var invocations int
 
161
        badSshCommand := func(host string, tty bool, command string) *exec.Cmd {
 
162
                invocations++
 
163
                switch invocations {
 
164
                case 1, 3:
 
165
                        return exec.Command("bash", "-c", "echo alles gut")
 
166
                case 2:
 
167
                        // Note: must close stdin before responding the first time, or
 
168
                        // the second command will race with closing stdin, and may
 
169
                        // flush first.
 
170
                        return exec.Command("bash", "-c", "head -n 1 > /dev/null; exec 0<&-; echo JUJU-RC: 0; echo blah blah")
 
171
                case 4:
 
172
                        return exec.Command("bash", "-c", `head -n 1 > /dev/null; echo "Hey it's JUJU-RC: , but not at the beginning of the line"`)
 
173
                default:
 
174
                        c.Errorf("unexpected invocation: #%d, %s", invocations, command)
 
175
                        return nil
 
176
                }
 
177
        }
 
178
        s.PatchValue(&sshCommand, badSshCommand)
 
179
 
 
180
        stor, err := NewSSHStorage("example.com", c.MkDir(), c.MkDir())
 
181
        c.Assert(err, gc.IsNil)
 
182
        defer stor.Close()
 
183
        err = stor.Put("whatever", bytes.NewBuffer(nil), 0)
 
184
        c.Assert(err, gc.ErrorMatches, regexp.QuoteMeta(`failed to flush input: write |1: broken pipe (output: "blah blah")`))
 
185
 
 
186
        _, err = NewSSHStorage("example.com", c.MkDir(), c.MkDir())
 
187
        c.Assert(err, gc.ErrorMatches, regexp.QuoteMeta(`failed to locate "JUJU-RC: " (output: "Hey it's JUJU-RC: , but not at the beginning of the line")`))
 
188
}
 
189
 
154
190
func (s *storageSuite) TestPut(c *gc.C) {
155
191
        stor, storageDir := s.makeStorage(c)
156
192
        data := []byte("abc\000def")