Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Stehler committed Dec 14, 2022
1 parent 7ebd5ee commit e538be4
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ class TravisBuildMonitorSpec extends Specification {
1 * travisService.getLatestBuilds() >> [ build ]
build.branchedRepoSlug() >> "test-org/test-repo/master"
build.jobs >> []
build.getNumber() >> 4
build.getNumber() >> '4'
build.getState() >> TravisBuildState.passed
build.repository >> repository
repository.slug >> 'test-org/test-repo'

1 * travisService.getGenericBuild(build, true) >> TravisBuildConverter.genericBuild(build, MASTER)
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/master', false) >> 3
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo', false) >> 5
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/master', 4, false, CACHED_JOB_TTL_SECONDS)
0 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', 4, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/master', false) >> '3'
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo', false) >> '5'
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/master', '4', false, CACHED_JOB_TTL_SECONDS)
0 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', '4', false, CACHED_JOB_TTL_SECONDS)

buildPollingDelta.items.size() == 1
buildPollingDelta.items[0].branchedRepoSlug == 'test-org/test-repo/master'
buildPollingDelta.items[0].currentBuildNum == 4
buildPollingDelta.items[0].previousBuildNum == 3
buildPollingDelta.items[0].currentBuildNum == '4'
buildPollingDelta.items[0].previousBuildNum == '3'
}

void 'send events for build both on branch and on repository'() {
Expand All @@ -104,24 +104,25 @@ class TravisBuildMonitorSpec extends Specification {
then:
1 * travisService.getLatestBuilds() >> [ build ]
build.branchedRepoSlug() >> "test-org/test-repo/my_branch"
build.getNumber() >> 4
build.getNumber() >> '4'
build.getState() >> TravisBuildState.passed
build.jobs >> []
build.repository >> repository
repository.slug >> 'test-org/test-repo'

1 * travisService.getGenericBuild(build, true) >> TravisBuildConverter.genericBuild(build, MASTER)
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/my_branch', false) >> 3
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/my_branch', 4, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', 4, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo', false) >> '-1'
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/my_branch', false) >> '3'
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/my_branch', '4', false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', '4', false, CACHED_JOB_TTL_SECONDS)

1 * echoService.postEvent({
it.content.project.name == "test-org/test-repo"
it.content.project.lastBuild.number == 4
it.content.project.lastBuild.number == '4'
})
1 * echoService.postEvent({
it.content.project.name == "test-org/test-repo/my_branch"
it.content.project.lastBuild.number == 4
it.content.project.lastBuild.number == '4'
})
}

Expand All @@ -136,11 +137,12 @@ class TravisBuildMonitorSpec extends Specification {
then:
1 * travisService.getLatestBuilds() >> [ build ]
build.branchedRepoSlug() >> "test-org/test-repo/my_branch"
build.getNumber() >> 4
build.getNumber() >> '4'

1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/my_branch', false) >> 3
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/my_branch', 4, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', 4, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo', false) >> '-1'
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/my_branch', false) >> '3'
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/my_branch', '4', false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', '4', false, CACHED_JOB_TTL_SECONDS)

build.jobs >> []
build.repository >> repository
Expand All @@ -162,42 +164,43 @@ class TravisBuildMonitorSpec extends Specification {
then:
1 * travisService.getLatestBuilds() >> [ build, buildDifferentBranch ]
build.branchedRepoSlug() >> "test-org/test-repo/my_branch"
build.getNumber() >> 4
build.getNumber() >> '4'
build.getState() >> TravisBuildState.passed
build.jobs >> []
build.repository >> repository
buildDifferentBranch.branchedRepoSlug() >> "test-org/test-repo/different_branch"
buildDifferentBranch.getNumber() >> 3
buildDifferentBranch.getNumber() >> '3'
buildDifferentBranch.getState() >> TravisBuildState.passed
buildDifferentBranch.jobs >> []
buildDifferentBranch.repository >> repository
repository.slug >> 'test-org/test-repo'
1 * travisService.getGenericBuild(build, true) >> TravisBuildConverter.genericBuild(build, MASTER)
1 * travisService.getGenericBuild(buildDifferentBranch, true) >> TravisBuildConverter.genericBuild(buildDifferentBranch, MASTER)
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/my_branch', false) >> 2
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/my_branch', 4, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', 4, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', 3, false, CACHED_JOB_TTL_SECONDS)
2 * buildCache.getLastBuild(MASTER, 'test-org/test-repo', false) >> '-1'
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/my_branch', false) >> '2'
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/my_branch', '4', false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', '4', false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', '3', false, CACHED_JOB_TTL_SECONDS)

1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/different_branch', false) >> 1
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/different_branch', 3, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/different_branch', false) >> '1'
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/different_branch', '3', false, CACHED_JOB_TTL_SECONDS)

1 * echoService.postEvent({
it.content.project.name == "test-org/test-repo/my_branch" &&
it.content.project.lastBuild.number == 4
it.content.project.lastBuild.number == '4'
})
1 * echoService.postEvent({
it.content.project.name == "test-org/test-repo" &&
it.content.project.lastBuild.number == 4
it.content.project.lastBuild.number == '4'
})

1 * echoService.postEvent({
it.content.project.name == "test-org/test-repo" &&
it.content.project.lastBuild.number == 3
it.content.project.lastBuild.number == '3'
})
1 * echoService.postEvent({
it.content.project.name == "test-org/test-repo/different_branch" &&
it.content.project.lastBuild.number == 3
it.content.project.lastBuild.number == '3'
})
}

Expand All @@ -211,7 +214,7 @@ class TravisBuildMonitorSpec extends Specification {
build.branch = new V3Branch()
build.branch.name = "my_branch"
build.id = 1337
build.number = 4
build.number = '4'
build.state = TravisBuildState.started
build.jobs = []
build.repository = repository
Expand All @@ -233,18 +236,19 @@ class TravisBuildMonitorSpec extends Specification {
2 * travisService.getGenericBuild(_, _) >> { V3Build b, boolean fetchLogs ->
TravisBuildConverter.genericBuild(b, MASTER)
}
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/my_branch', true) >> 3
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/my_branch', false) >> 3
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/my_branch', 4, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', 4, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo', false) >> '-1'
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/my_branch', true) >> '3'
1 * buildCache.getLastBuild(MASTER, 'test-org/test-repo/my_branch', false) >> '3'
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo/my_branch', '4', false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, 'test-org/test-repo', '4', false, CACHED_JOB_TTL_SECONDS)

1 * echoService.postEvent({
it.content.project.name == "test-org/test-repo"
it.content.project.lastBuild.number == 4
it.content.project.lastBuild.number == '4'
})
1 * echoService.postEvent({
it.content.project.name == "test-org/test-repo/my_branch"
it.content.project.lastBuild.number == 4
it.content.project.lastBuild.number == '4'
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ class TravisClientSpec extends Specification {
}'''

when:
Builds builds = client.builds("someToken", "some/build", 31)
Builds builds = client.builds("someToken", "some/build", '31')

then:
Build build = builds.builds.first()
build.number == 31
build.number == '31'
build.duration == 8
build.finishedAt.toEpochMilli() == 1458051084000
}
Expand Down Expand Up @@ -320,11 +320,11 @@ class TravisClientSpec extends Specification {
}'''
when:
Builds builds = client.builds("someToken", "some/build", 31)
Builds builds = client.builds("someToken", "some/build", '31')
then:
Build build = builds.builds.first()
build.number == 3
build.number == '3'
build.config.globalEnv.size() == 1
build.config.globalEnv.first() == "TARGET_ENV=test.environment"
}
Expand All @@ -334,7 +334,7 @@ class TravisClientSpec extends Specification {
setResponse '''{"builds":[],"commits":[]}'''
when:
Builds builds = client.builds("someToken", "some/build", 31)
Builds builds = client.builds("someToken", "some/build", '31')
then:
builds.builds.size() == 0
Expand Down Expand Up @@ -373,7 +373,7 @@ class TravisClientSpec extends Specification {
}'''
when:
Builds builds = client.builds("someToken", "org/repo", 39)
Builds builds = client.builds("someToken", "org/repo", '39')
then:
builds.commits.first().isTag()
Expand Down Expand Up @@ -412,7 +412,7 @@ class TravisClientSpec extends Specification {
}'''
when:
Builds builds = client.builds("someToken", "org/repo", 31)
Builds builds = client.builds("someToken", "org/repo", '31')
then:
builds.commits.first().timestamp == LocalDateTime.of(2016, Month.JUNE, 1, 18, 57, 48).toInstant(ZoneOffset.UTC)
Expand Down Expand Up @@ -645,7 +645,7 @@ class TravisClientSpec extends Specification {
V3Build build = client.v3build("someToken", 7128433, "build.log_complete")
then:
build.number == 265
build.number == '265'
build.commit.committer.name == "Alice"
build.commit.author.name == "Bob"
build.jobs*.id == [7128434]
Expand Down Expand Up @@ -687,7 +687,7 @@ class TravisClientSpec extends Specification {
'''
when:
Builds builds = client.builds("someToken", "org/repo", 38)
Builds builds = client.builds("someToken", "org/repo", '38')
then:
!builds.commits.first().isTag()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class TravisServiceSpec extends Specification {
GenericBuild genericBuild = service.getGenericBuild(build, "some/repo-slug")

then:
genericBuild.number == 1337
genericBuild.number == '1337'
genericBuild.result == Result.SUCCESS
genericBuild.duration == 32
genericBuild.timestamp == "1458051084000"
Expand All @@ -95,7 +95,7 @@ class TravisServiceSpec extends Specification {
1 * travisCache.setJobLog('travis-ci', 42, "") >>> [null, ""]
1 * client.jobLog(_, 42) >> v3log
2 * build.job_ids >> [42]
2 * build.number >> 1337
2 * build.number >> '1337'
2 * build.state >> 'passed'
1 * build.duration >> 32
1 * build.finishedAt >> Instant.now()
Expand Down Expand Up @@ -311,7 +311,7 @@ class TravisServiceSpec extends Specification {
}) >> response
1 * travisCache.setQueuedJob("travis-ci", 42, 1337) >> 1

buildNumber == 1
buildNumber == '1'
}

@Unroll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class BuildController {
}


void stopJob(String master, int buildNumber, String jobName, String queuedBuild) {
void stopJob(String master, String buildNumber, String jobName, String queuedBuild) {
def buildService = getBuildService(master)
if (buildService instanceof JenkinsService) {
// Jobs that haven't been started yet won't have a buildNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ class GitlabCiBuildMonitorSpec extends Specification {
service.getProjects() >> [project]
service.getPipelines(project, 5) >> [pipeline]
buildCache.getJobNames(MASTER) >> jobsInCache
buildCache.getLastBuild(MASTER, "999", true) >> lastBuildNr
buildCache.getLastBuild(MASTER, "999", false) >> lastBuildNr

when:
buildMonitor.pollSingle(new PollContext(MASTER).fastForward())

then:
1 * buildCache.setLastBuild(MASTER, "999", 101, false, CACHED_JOB_TTL_SECONDS)
1 * buildCache.setLastBuild(MASTER, "999", '101', false, CACHED_JOB_TTL_SECONDS)

and:
0 * echoService.postEvent(_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class WerckerServiceSpec extends Specification {
def (org, app, pipe) = names
def job = names.join('/')
def runId = "testGenericBuild_werckerRunId"
int buildNumber = '6'
String buildNumber = '6'
setup:
cache.getRunID(master, job, buildNumber) >> runId
client.getRunById(_, runId) >> new Run(id: runId)
Expand All @@ -147,7 +147,7 @@ class WerckerServiceSpec extends Specification {
def (org, app, pipe) = names
def (pipeline, pipelineId) = [names.join('/'), pipe + "ID"]
def runId = 'test_triggerBuild_runId'
int buildNumber = '8'
String buildNumber = '8'

setup:
client.getPipelinesForApplication(_, org, app) >> [
Expand Down

0 comments on commit e538be4

Please sign in to comment.