dubeejw commented on a change in pull request #2544: Allow CLI to Save Code from Action URL: https://github.com/apache/incubator-openwhisk/pull/2544#discussion_r144978426
########## File path: tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala ########## @@ -811,6 +813,81 @@ class WskBasicUsageTests extends TestHelpers with WskTestHelpers { stdoutNoDescOrParams should include regex (s"(?i)action /${namespace}/${actNameNoDescOrParams}\\s*\\(parameters: none defined\\)") } + it should "save action code to file" in withAssetCleaner(wskprops) { (wp, assetHelper) => + val name = "saveAction" + val seqName = "seqName" + val dockerName = "dockerName" + val containerName = s"bogus${Random.alphanumeric.take(16).mkString.toLowerCase}" + val saveName = s"save-as-$name.js" + val badSaveName = s"bad-directory${File.separator}$saveName" + + // Test for successful --save + assetHelper.withCleaner(wsk.action, name) { (action, _) => + action.create(name, defaultAction) + } + + val saveMsg = wsk.action.get(name, save = Some(true)).stdout + + saveMsg should include(s"saved action code to ") + + val savePath = saveMsg.split("ok: saved action code to ")(1).trim() + val saveFile = new File(savePath); + + try { + saveFile.exists shouldBe true + + // Test for failure saving file when it already exist + wsk.action.get(name, save = Some(true), expectedExitCode = MISUSE_EXIT).stderr should include( + s"The file '$name.js' already exists") + } finally { + saveFile.delete() + } + + // Test for successful --save-as + val saveAsMsg = wsk.action.get(name, saveAs = Some(saveName)).stdout + + saveAsMsg should include(s"saved action code to ") + + val saveAsPath = saveAsMsg.split("ok: saved action code to ")(1).trim() + val saveAsFile = new File(saveAsPath); + + try { + saveAsFile.exists shouldBe true + + // Test for failure saving file when it already exist + wsk.action.get(name, saveAs = Some(saveName), expectedExitCode = MISUSE_EXIT).stderr should include( + s"The file '$saveName' already exists") + } finally { + saveAsFile.delete() + } + + // Test for failure when using an invalid filename + wsk.action.get(name, saveAs = Some(badSaveName), expectedExitCode = MISUSE_EXIT).stderr should include( + s"Cannot create file '$badSaveName'") + + // Test for failure saving Docker images + assetHelper.withCleaner(wsk.action, dockerName) { (action, _) => + action.create(dockerName, None, docker = Some(containerName)) + } + + wsk.action.get(dockerName, save = Some(true), expectedExitCode = MISUSE_EXIT).stderr should include( + "Cannot save Docker images") + + wsk.action.get(dockerName, saveAs = Some(dockerName), expectedExitCode = MISUSE_EXIT).stderr should include( + "Cannot save Docker images") + + // Tes for failure saving sequences + assetHelper.withCleaner(wsk.action, seqName) { (action, _) => + action.create(seqName, Some(name), kind = Some("sequence")) + } + + wsk.action.get(seqName, save = Some(true), expectedExitCode = MISUSE_EXIT).stderr should include( + "Cannot save action sequence") Review comment: Yes. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services