Skip to content

Commit

Permalink
Added failure test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jpommerening committed Nov 29, 2013
1 parent bdc11a6 commit 17655c2
Showing 1 changed file with 53 additions and 4 deletions.
57 changes: 53 additions & 4 deletions master/buildbot/test/unit/test_steps_transfer.py
Expand Up @@ -29,7 +29,7 @@
from buildbot import interfaces
from buildbot.process import buildstep
from buildbot.process.properties import Properties
from buildbot.status.results import SUCCESS, SKIPPED
from buildbot.status.results import SUCCESS, SKIPPED, FAILURE
from buildbot.steps import transfer
from buildbot.test.fake.remotecommand import Expect
from buildbot.test.fake.remotecommand import ExpectRemoteRef
Expand All @@ -50,15 +50,15 @@ def behavior(command):


def uploadTarFile(filename, **members):
def behaviour(command):
def behavior(command):
f = StringIO()
archive = tarfile.TarFile(fileobj=f, name=filename, mode='w')
for name, content in members.iteritems():
archive.addfile(tarfile.TarInfo(name), StringIO(content))
writer = command.args['writer']
writer.remote_write(f.getvalue())
writer.remote_unpack()
return behaviour
return behavior


# Test buildbot.steps.transfer._FileWriter class.
Expand Down Expand Up @@ -147,7 +147,7 @@ def tearDown(self):
os.unlink(self.destfile)
return self.tearDownBuildStep()

def test_constructor_mode_type(self):
def testConstructorModeType(self):
self.assertRaises(config.ConfigErrors, lambda:
transfer.FileUpload(slavesrc=__file__, masterdest='xyz', mode='g+rwx'))

Expand Down Expand Up @@ -222,6 +222,21 @@ def checkURL(_):
os.path.basename(self.destfile), "http://server/file")
return d

def testFailure(self):
self.setupStep(
transfer.FileUpload(slavesrc='srcfile', masterdest=self.destfile))

self.expectCommands(
Expect('uploadFile', dict(
slavesrc="srcfile", workdir='wkdir',
blocksize=16384, maxsize=None, keepstamp=False,
writer=ExpectRemoteRef(transfer._FileWriter)))
+ 1)

self.expectOutcome(result=FAILURE, status_text=["uploading", "srcfile"])
d = self.runStep()
return d


class TestDirectoryUpload(steps.BuildStepMixin, unittest.TestCase):

Expand Down Expand Up @@ -254,6 +269,21 @@ def testBasic(self):
d = self.runStep()
return d

def testFailure(self):
self.setupStep(
transfer.DirectoryUpload(slavesrc="srcdir", masterdest=self.destdir))

self.expectCommands(
Expect('uploadDirectory', dict(
slavesrc="srcdir", workdir='wkdir',
blocksize=16384, compress=None, maxsize=None,
writer=ExpectRemoteRef(transfer._DirectoryWriter)))
+ 1)

self.expectOutcome(result=FAILURE, status_text=["uploading", "srcdir"])
d = self.runStep()
return d


class TestMultipleFileUpload(steps.BuildStepMixin, unittest.TestCase):

Expand Down Expand Up @@ -350,6 +380,25 @@ def testMultiple(self):
d = self.runStep()
return d

def testFailure(self):
self.setupStep(
transfer.MultipleFileUpload(slavesrcs=["srcfile", "srcdir"], masterdest=self.destdir))

self.expectCommands(
Expect('stat', dict(file="srcfile",
workdir='wkdir'))
+ Expect.update('stat', [stat.S_IFREG, 99, 99])
+ 0,
Expect('uploadFile', dict(
slavesrc="srcfile", workdir='wkdir',
blocksize=16384, maxsize=None, keepstamp=False,
writer=ExpectRemoteRef(transfer._FileWriter)))
+ 1)

self.expectOutcome(result=FAILURE, status_text=["uploading", "2 files"])
d = self.runStep()
return d


class TestStringDownload(unittest.TestCase):

Expand Down

0 comments on commit 17655c2

Please sign in to comment.