Skip to content

Commit

Permalink
add tests for failOnExist
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoli Kalbasin <qwnize@outlook.com>
  • Loading branch information
callbacksin committed Sep 5, 2024
1 parent 7e4e122 commit 6febb36
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,74 @@ class AllocateDatasetStepSpec : ShouldSpec({
assertSoftly { isDatasetAllocating shouldBe true }
assertSoftly { isDatasetAllocated shouldBe true }
}

should("fail as such dataset already exists and failOnExist is set to true") {
var isDatasetAllocating = false
var isFailedToAllocate = false
val taskListener = object : TestBuildListener() {
override fun getLogger(): PrintStream {
val logger = mockk<PrintStream>()
every {
logger.println(any<String>())
} answers {
if (firstArg<String>().contains("Allocating dataset")) {
isDatasetAllocating = true
} else if (firstArg<String>().contains("Dataset allocation failed.")) {
isFailedToAllocate = true
} else {
fail("Unexpected logger message: ${firstArg<String>()}")
}
}
return logger
}
}
val launcher = TestLauncher(taskListener, virtualChannel)

responseDispatcher.injectEndpoint(
this.testCase.name.testName,
{ it?.requestLine?.contains("/zosmf/restfiles/ds/") ?: false },
{ MockResponse().setResponseCode(409) }
)

val allocateDatasetStepInst = spyk(
AllocateDatasetStep(
"test",
"TEST.IJMP.DATASET1",
DatasetOrganization.PS,
1,
0,
RecordFormat.F,
failOnExist = true
)
)
allocateDatasetStepInst.setAlcUnit(AllocationUnit.CYL)
allocateDatasetStepInst.setStorClass("")
allocateDatasetStepInst.setStorClass("TEST")
allocateDatasetStepInst.setMgntClass("")
allocateDatasetStepInst.setMgntClass("TEST")
allocateDatasetStepInst.setDataClass("")
allocateDatasetStepInst.setDataClass("TEST")
allocateDatasetStepInst.setVolser("")
allocateDatasetStepInst.setVolser("TEST")
allocateDatasetStepInst.setUnit("")
allocateDatasetStepInst.setUnit("TEST")
allocateDatasetStepInst.setLrecl(3120)
allocateDatasetStepInst.setBlkSize(3120)
allocateDatasetStepInst.setDsnType(DsnameType.BASIC)
try {
allocateDatasetStepInst.perform(
build,
launcher,
taskListener,
zosConnection
)
} catch (ex: Exception) {
isFailedToAllocate = true
}
assertSoftly { isDatasetAllocating shouldBe true }
assertSoftly { isFailedToAllocate shouldBe true }
}

}

val descriptor = AllocateDatasetStep.DescriptorImpl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,52 @@ class DeleteDatasetStepSpec : ShouldSpec({
assertSoftly { isDeletingDataset shouldBe true }
assertSoftly { isSuccessfullyDeleted shouldBe true }
}

should("succeed as there is no such dataset, but failOnNotExist is set to false") {
var isDeletingDataset = false
var isContinuingExecution = false
val taskListener = object : TestBuildListener() {
override fun getLogger(): PrintStream {
val logger = mockk<PrintStream>()
every {
logger.println(any<String>())
} answers {
if (firstArg<String>().contains("Deleting dataset")) {
isDeletingDataset = true
} else if (firstArg<String>().contains("Dataset deletion failed, but the `failOnNotExist` option is set to false.")
|| firstArg<String>().contains("Reason")) {
isContinuingExecution = true
} else {
fail("Unexpected logger message: ${firstArg<String>()}")
}
}
return logger
}
}
val launcher = TestLauncher(taskListener, virtualChannel)

responseDispatcher.injectEndpoint(
this.testCase.name.testName,
{ it?.requestLine?.contains(Regex("DELETE /zosmf/restfiles/ds/.* HTTP/.*")) ?: false },
{ MockResponse().setBody("{}").setResponseCode(404) }
)

val deleteDatasetStep = spyk(
DeleteDatasetStep("test", "TEST.IJMP.DATASET1", member = null, failOnNotExist = false)
)
deleteDatasetStep.perform(
build,
launcher,
taskListener,
zosConnection
)

assertSoftly { isDeletingDataset shouldBe true }
assertSoftly { isContinuingExecution shouldBe true }
}
}


val descriptor = DeleteDatasetStep.DescriptorImpl()
context("classic/steps module: DeleteDatasetStep.DescriptorImpl") {

Expand Down

0 comments on commit 6febb36

Please sign in to comment.