Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test cases for quoted strings. #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ javascript/
wsk
scripts
Godeps/_workspace
.gradle/
.idea/
bin/
tests/build/
*.iml
10 changes: 10 additions & 0 deletions tests/src/test/scala/system/basic/WskConsoleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,14 @@ abstract class WskConsoleTests extends TestHelpers with WskTestHelpers {
}
}

it should "invoke an action and poll activations and verify that action names are quoted." in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val name = "helloRunActivationPoll"
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
action.create(name, Some(TestCLIUtils.getTestActionFilename("hello.js")))
}
val activationId = wsk.action.invoke(name)
val pollResults = wsk.activation.console(duration = 5.second, actionName = Some(name))
pollResults.stdout should include (s"""Activation: '${name}'""")
}
}
72 changes: 72 additions & 0 deletions tests/src/test/scala/system/basic/WskSdkTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import common.Wsk
import common.WskProps
import common.WskTestHelpers

import scala.sys.process._

@RunWith(classOf[JUnitRunner])
class WskSdkTests extends TestHelpers with WskTestHelpers {

Expand Down Expand Up @@ -82,6 +84,76 @@ class WskSdkTests extends TestHelpers with WskTestHelpers {
}
}

it should "download docker sdk when blackbox.tar.gz exists, and docker name should be quoted in error." in {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use Seq to squash this test and "download ios sdk when OpenWhiskIOSStarterApp.zip exists, and ios name should be quoted in error. into one test.

val fileName = "blackbox.tar.gz"
val dir = File.createTempFile("wskinstall", ".tmp")
dir.delete()
dir.mkdir() should be(true)
val file = new File(dir, fileName)
file.createNewFile should be (true)
try {
wsk.cli(wskprops.overrides ++ Seq("sdk", "install", "docker"),
workingDir = dir,
expectedExitCode = 1).stderr should include(
s"""The file '${fileName}' already exists. Delete it and retry.""")
} finally {
file.delete()
FileUtils.deleteDirectory(dir)
}
}

it should "download ios sdk when OpenWhiskIOSStarterApp.zip exists, and ios name should be quoted in error." in {
val fileName = "OpenWhiskIOSStarterApp.zip"
val dir = File.createTempFile("wskinstall", ".tmp")
dir.delete()
dir.mkdir() should be(true)
val file = new File(dir, fileName)
file.createNewFile should be (true)
try {
wsk.cli(wskprops.overrides ++ Seq("sdk", "install", "ios"),
workingDir = dir,
expectedExitCode = 1).stderr should include(
s"""The file '${fileName}' already exists. Delete it and retry.""")
} finally {
file.delete()
FileUtils.deleteDirectory(dir)
}
}

it should "download ios sdk, check filename is quoted in error when create fails." in {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expect the same directory permission issue with the Docker SDK?

$ mkdir wskinstall
$ chmod 555 wskinstall
$ cd wskinstall
$ wsk sdk install docker
error: The docker SDK installation failed: Error creating SDK file 'blackbox.tar.gz': open blackbox.tar.gz: permission denied

Could test both with Seq.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to double check this one but last i checked i think there was no way to inject the bad permissions between the download and extraction.

val fileName = "OpenWhiskIOSStarterApp.zip"
val dir = File.createTempFile("wskinstall", ".tmp")
dir.delete()
dir.mkdir() should be(true)
Seq("chmod", "555", dir.getAbsolutePath).!!
try {
wsk.cli(wskprops.overrides ++ Seq("sdk", "install", "ios"),
workingDir = dir,
expectedExitCode = 1).stderr should include(
s"""Error creating SDK file '${fileName}':""")
} finally {
FileUtils.deleteDirectory(dir)
}
}

it should "download docker sdk twice, check directory is quoted in error when create fails." in {
val dir = File.createTempFile("wskinstall", ".tmp")
dir.delete()
dir.mkdir() should be(true)
try {
wsk.cli(wskprops.overrides ++ Seq("sdk", "install", "docker"),
workingDir = dir).stdout should include(
s"""The docker skeleton is now installed at the current directory.""")

wsk.cli(wskprops.overrides ++ Seq("sdk", "install", "docker"),
workingDir = dir,
expectedExitCode = 1).stderr should include(
s"""The directory 'dockerSkeleton' already exists. Delete it and retry.""")
} finally {
FileUtils.deleteDirectory(dir)
}
}

it should "download iOS sdk" in {
val dir = File.createTempFile("wskinstall", ".tmp")
dir.delete()
Expand Down
26 changes: 26 additions & 0 deletions tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,32 @@ abstract class ApiGwTests extends BaseApiGwTests {
verifyMissingField(rr)
}

it should "api create should fail if action is not a web action" in {
val testName = "CLI_APIGWTEST_RO1"
val testbasepath = "/" + testName + "_bp"
val testrelpath = "/path"
val testnewrelpath = "/path_new"
val testurlop = "get"
val testapiname = testName + " API Name"
val actionName = testName + "_action"
try {
// Create the action for the API. It must be a "web-action" action.
val file = TestCLIUtils.getTestActionFilename(s"echo.js")
wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = createCode)

var rr = apiCreate(
basepath = Some(testbasepath),
relpath = Some(testrelpath),
operation = Some(testurlop),
action = Some(actionName),
apiname = Some(testapiname),
expectedExitCode = ERROR_EXIT)
rr.stderr should include(s"""Action '/_/${actionName}' is not a web action. Issue 'wsk action update "/_/${actionName}" --web true' to convert the action to a web action.""")
} finally {
wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
}
}

it should "verify full list output" in {
val testName = "CLI_APIGWTEST_RO1"
val testbasepath = "/" + testName + "_bp"
Expand Down
13 changes: 13 additions & 0 deletions tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ class WskBasicUsageTests extends TestHelpers with WskTestHelpers {
}
}

it should "invoke an action that exits during run and check that the activation summary has the name in quoted" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val name = "helloRunSummary"
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
action.create(name, Some(TestCLIUtils.getTestActionFilename("hello.js")))
}
val activationId = wsk.action.invoke(name).stdout.split("with id ")(1).trim
wsk.activation.waitForActivation(activationId)
val activationResponse = wsk.activation.get(Some(activationId), summary = Some(true))
activationResponse.stdout should include(s"""activation result for '/guest/${name}'""")
}


it should "retrieve the last activation using --last flag" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
val auth: Seq[String] = Seq("--auth", wskprops.authKey)
val includeStr = "hello, undefined!"
Expand Down