You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2017/08/10 12:08:34 UTC
[incubator-openwhisk-cli] 09/11: Remove "experimental" gateway api
(#2547)
This is an automated email from the ASF dual-hosted git repository.
csantanapr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-cli.git
commit 34c5fc1ac4987987720a03be7d6d079446240630
Author: David Cariello <dr...@us.ibm.com>
AuthorDate: Tue Aug 8 12:14:35 2017 -0500
Remove "experimental" gateway api (#2547)
---
.../apigw/healthtests/ApiGwEndToEndTests.scala | 73 +---
.../actions/test/ApiGwRoutemgmtActionTests.scala | 283 +-----------
.../scala/whisk/core/cli/test/ApiGwTests.scala | 479 +++------------------
.../whisk/core/cli/test/WskBasicUsageTests.scala | 95 +---
4 files changed, 77 insertions(+), 853 deletions(-)
diff --git a/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala b/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
index 9e8ecd0..dd70b6d 100644
--- a/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
+++ b/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
@@ -36,7 +36,6 @@ import common.TestCLIUtils
import common.TestUtils._
import common.Wsk
import common.WskProps
-import common.WskPropsV2
import common.WskTestHelpers
import spray.json._
import spray.json.DefaultJsonProtocol._
@@ -66,81 +65,11 @@ class ApiGwEndToEndTests
*/
override def beforeAll() = {
cliWskPropsFile.deleteOnExit()
- val wskprops = WskPropsV2(token = "SOME TOKEN")
+ val wskprops = WskProps(token = "SOME TOKEN")
wskprops.writeFile(cliWskPropsFile)
println(s"wsk temporary props file created here: ${cliWskPropsFile.getCanonicalPath()}")
}
- behavior of "Wsk api-experimental"
-
- it should s"create an API and successfully invoke that API" in {
- val testName = "APIGWe_HEALTHTEST1"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_echo"
- val urlqueryparam = "name"
- val urlqueryvalue = "test"
-
- try {
- println("cli namespace: " + clinamespace)
-
- // Create the action for the API
- val file = TestCLIUtils.getTestActionFilename(s"echo.js")
- wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = SUCCESS_EXIT)
-
- // Create the API
- var rr = wsk.apiexperimental.create(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- val apiurl = rr.stdout.split("\n")(1)
- println(s"apiurl: '${apiurl}'")
-
- // Validate the API was successfully created
- // List result will look like:
- // ok: APIs
- // Action Verb API Name URL
- // /_//whisk.system/utils/echo get APIGW_HEALTHTEST1 API Name http://172.17.0.1:9001/api/ab9082cd-ea8e-465a-8a65-b491725cc4ef/APIGW_HEALTHTEST1_bp/path
- rr = wsk.apiexperimental.list(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
-
- // Recreate the API using a JSON swagger file
- rr = wsk.apiexperimental.get(basepathOrApiName = Some(testbasepath))
- val swaggerfile = File.createTempFile("api", ".json")
- swaggerfile.deleteOnExit()
- val bw = new BufferedWriter(new FileWriter(swaggerfile))
- bw.write(rr.stdout)
- bw.close()
-
- // Delete API to that it can be recreated again using the generated swagger file
- val deleteApiResult = wsk.apiexperimental.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
-
- // Create the API again, but use the swagger file this time
- rr = wsk.apiexperimental.create(swagger = Some(swaggerfile.getAbsolutePath()))
- rr.stdout should include("ok: created API")
- val swaggerapiurl = rr.stdout.split("\n")(1)
- println(s"apiurl: '${swaggerapiurl}'")
-
- // Call the API URL and validate the results
- val response = whisk.utils.retry({
- val response = RestAssured.given().config(sslconfig).get(s"$swaggerapiurl?$urlqueryparam=$urlqueryvalue")
- response.statusCode should be(200)
- response
- }, 5, Some(1.second))
- val responseString = response.body.asString
- println("URL invocation response: " + responseString)
- responseString.parseJson.asJsObject.fields(urlqueryparam).convertTo[String] should be(urlqueryvalue)
-
- } finally {
- println("Deleting action: " + actionName)
- val finallydeleteActionResult = wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
- println("Deleting API: " + testbasepath)
- val finallydeleteApiResult = wsk.apiexperimental.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
behavior of "Wsk api"
it should s"create an API and successfully invoke that API" in {
diff --git a/tests/src/test/scala/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala b/tests/src/test/scala/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala
index 5a0f97c..28f9b0f 100644
--- a/tests/src/test/scala/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala
+++ b/tests/src/test/scala/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala
@@ -72,136 +72,6 @@ class ApiGwRoutemgmtActionTests
bpOrName: Option[String],
relpath: Option[String] = None,
operation: Option[String] = None,
- docid: Option[String] = None): Vector[JsValue] = {
- val parms = Map[String, JsValue]() ++
- Map("__ow_user" -> wskprops.namespace.toJson) ++
- { bpOrName map { b => Map("basepath" -> b.toJson) } getOrElse Map[String, JsValue]() } ++
- { relpath map { r => Map("relpath" -> r.toJson) } getOrElse Map[String, JsValue]() } ++
- { operation map { o => Map("operation" -> o.toJson) } getOrElse Map[String, JsValue]() } ++
- { docid map { d => Map("docid" -> d.toJson) } getOrElse Map[String, JsValue]() }
-
- val rr = wsk.action.invoke(
- name = "routemgmt/getApi",
- parameters = parms,
- blocking = true,
- result = true,
- expectedExitCode = SUCCESS_EXIT)(wskprops)
- var apiJsArray: JsArray =
- try {
- var apisobj = rr.stdout.parseJson.asJsObject.fields("apis")
- apisobj.convertTo[JsArray]
- } catch {
- case e: Exception =>
- JsArray.empty
- }
- return apiJsArray.elements
- }
-
- def createApi(
- namespace: Option[String] = Some("_"),
- basepath: Option[String] = Some("/"),
- relpath: Option[String],
- operation: Option[String],
- apiname: Option[String],
- action: Option[ApiAction],
- swagger: Option[String] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
- val parms = Map[String, JsValue]() ++
- { namespace map { n => Map("namespace" -> n.toJson) } getOrElse Map[String, JsValue]() } ++
- { basepath map { b => Map("gatewayBasePath" -> b.toJson) } getOrElse Map[String, JsValue]() } ++
- { relpath map { r => Map("gatewayPath" -> r.toJson) } getOrElse Map[String, JsValue]() } ++
- { operation map { o => Map("gatewayMethod" -> o.toJson) } getOrElse Map[String, JsValue]() } ++
- { apiname map { an => Map("apiName" -> an.toJson) } getOrElse Map[String, JsValue]() } ++
- { action map { a => Map("action" -> a.toJson) } getOrElse Map[String, JsValue]() } ++
- { swagger map { s => Map("swagger" -> s.toJson) } getOrElse Map[String, JsValue]() }
- val parm = Map[String, JsValue]("apidoc" -> JsObject(parms)) ++
- { namespace map { n => Map("__ow_user" -> n.toJson) } getOrElse Map[String, JsValue]() }
-
- val rr = wsk.action.invoke(
- name = "routemgmt/createApi",
- parameters = parm,
- blocking = true,
- result = true,
- expectedExitCode = expectedExitCode)(wskprops)
- return rr
- }
-
- def deleteApi(
- namespace: Option[String] = Some("_"),
- basepath: Option[String] = Some("/"),
- relpath: Option[String] = None,
- operation: Option[String] = None,
- apiname: Option[String] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
- val parms = Map[String, JsValue]() ++
- { namespace map { n => Map("__ow_user" -> n.toJson) } getOrElse Map[String, JsValue]() } ++
- { basepath map { b => Map("basepath" -> b.toJson) } getOrElse Map[String, JsValue]() } ++
- { relpath map { r => Map("relpath" -> r.toJson) } getOrElse Map[String, JsValue]() } ++
- { operation map { o => Map("operation" -> o.toJson) } getOrElse Map[String, JsValue]() } ++
- { apiname map { an => Map("apiname" -> an.toJson) } getOrElse Map[String, JsValue]() }
-
- val rr = wsk.action.invoke(
- name = "routemgmt/deleteApi",
- parameters = parms,
- blocking = true,
- result = true,
- expectedExitCode = expectedExitCode)(wskprops)
- return rr
- }
-
- def apiMatchExperimental(
- apiarr: Vector[JsValue],
- basepath: String = "/",
- relpath: String = "",
- operation: String = "",
- apiname: String = "",
- action: ApiAction = null): Boolean = {
- var matches: Boolean = false
- for (api <- apiarr) {
- val basepathExists = JsObjectHelper(api.asJsObject).fieldPathExists("value", "apidoc", "basePath")
- if (basepathExists) {
- System.out.println("basePath exists")
- val basepathMatches = (JsObjectHelper(api.asJsObject).getFieldPath("value", "apidoc", "basePath").get.convertTo[String] == basepath)
- if (basepathMatches) {
- System.out.println("basePath matches: " + basepath)
- val apinameExists = JsObjectHelper(api.asJsObject).fieldPathExists("value", "apidoc", "info", "title")
- if (apinameExists) {
- System.out.println("api name exists")
- val apinameMatches = (JsObjectHelper(api.asJsObject).getFieldPath("value", "apidoc", "info", "title").get.convertTo[String] == apiname)
- if (apinameMatches) {
- System.out.println("api name matches: " + apiname)
- val endpointMatches = JsObjectHelper(api.asJsObject).fieldPathExists("value", "apidoc", "paths", relpath, operation)
- if (endpointMatches) {
- System.out.println("endpoint exists/matches : " + relpath + " " + operation)
- val actionConfig = JsObjectHelper(api.asJsObject).getFieldPath("value", "apidoc", "paths", relpath, operation, "x-ibm-op-ext").get.asJsObject
- val actionMatches = actionMatchExperimental(actionConfig, action)
- if (actionMatches) {
- System.out.println("endpoint action matches")
- matches = true;
- }
- }
- }
- }
- }
- }
- }
- return matches
- }
-
- def actionMatchExperimental(
- jsAction: JsObject,
- action: ApiAction): Boolean = {
- val matches = jsAction.fields("backendMethod").convertTo[String] == action.backendMethod &&
- jsAction.fields("backendUrl").convertTo[String] == action.backendUrl &&
- jsAction.fields("actionNamespace").convertTo[String] == action.namespace &&
- jsAction.fields("actionName").convertTo[String] == action.name
- return matches
- }
-
- def getApisV2(
- bpOrName: Option[String],
- relpath: Option[String] = None,
- operation: Option[String] = None,
docid: Option[String] = None,
accesstoken: Option[String] = Some("AnAccessToken"),
spaceguid: Option[String] = Some("ASpaceGuid") ): Vector[JsValue] = {
@@ -231,7 +101,7 @@ class ApiGwRoutemgmtActionTests
return apiJsArray.elements
}
- def createApiV2(
+ def createApi(
namespace: Option[String] = Some("_"),
basepath: Option[String] = Some("/"),
relpath: Option[String],
@@ -264,7 +134,7 @@ class ApiGwRoutemgmtActionTests
return rr
}
- def deleteApiV2(
+ def deleteApi(
namespace: Option[String] = Some("_"),
basepath: Option[String] = Some("/"),
relpath: Option[String] = None,
@@ -342,7 +212,7 @@ class ApiGwRoutemgmtActionTests
return matches
}
- behavior of "API Gateway routemgmt action parameter validation"
+ behavior of "API Gateway apimgmt action parameter validation"
it should "verify successful creation of a new API" in {
val testName = "APIGWTEST1"
@@ -352,7 +222,7 @@ class ApiGwRoutemgmtActionTests
val testapiname = testName + " API Name"
val actionName = testName + "_action"
val actionNamespace = wskprops.namespace
- val actionUrl = "http://some.whisk.host/api/v1/namespaces/" + actionNamespace + "/actions/" + actionName
+ val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
val actionAuthKey = testName + "_authkey"
val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
@@ -362,7 +232,7 @@ class ApiGwRoutemgmtActionTests
JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
val apiVector = getApis(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
apiVector.size should be > 0
- apiMatchExperimental(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
+ apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
} finally {
val deleteResult = deleteApi(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
}
@@ -376,7 +246,7 @@ class ApiGwRoutemgmtActionTests
val testapiname = testName + " API Name"
val actionName = testName + "_action"
val actionNamespace = wskprops.namespace
- val actionUrl = "http://some.whisk.host/api/v1/namespaces/" + actionNamespace + "/actions/" + actionName
+ val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
val actionAuthKey = testName + "_authkey"
val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
@@ -386,10 +256,10 @@ class ApiGwRoutemgmtActionTests
JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
var apiVector = getApis(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
apiVector.size should be > 0
- apiMatchExperimental(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
+ apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
val deleteResult = deleteApi(namespace = Some(wskprops.namespace), basepath = Some(testbasepath))
apiVector = getApis(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- apiMatchExperimental(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(false)
+ apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(false)
} finally {
val deleteResult = deleteApi(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
}
@@ -405,7 +275,7 @@ class ApiGwRoutemgmtActionTests
val testapiname = testName + " API Name"
val actionName = testName + "_action"
val actionNamespace = wskprops.namespace
- val actionUrl = "http://some.whisk.host/api/v1/namespaces/" + actionNamespace + "/actions/" + actionName
+ val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
val actionAuthKey = testName + "_authkey"
val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
@@ -417,143 +287,10 @@ class ApiGwRoutemgmtActionTests
JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
var apiVector = getApis(bpOrName = Some(testbasepath))
apiVector.size should be > 0
- apiMatchExperimental(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
- apiMatchExperimental(apiVector, testbasepath, testnewrelpath, testnewurlop, testapiname, testaction) should be(true)
- } finally {
- val deleteResult = deleteApi(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "reject routemgmt actions that are invoked with not enough parameters" in {
- val invalidArgs = Seq(
- //getApi
- ("/whisk.system/routemgmt/getApi", ANY_ERROR_EXIT, "Invalid authentication.", Seq()),
-
- //deleteApi
- ("/whisk.system/routemgmt/deleteApi", ANY_ERROR_EXIT, "Invalid authentication.", Seq("-p", "basepath", "/ApiGwRoutemgmtActionTests_bp")),
- ("/whisk.system/routemgmt/deleteApi", ANY_ERROR_EXIT, "basepath is required", Seq("-p", "__ow_user", "_")),
- ("/whisk.system/routemgmt/deleteApi", ANY_ERROR_EXIT, "When specifying an operation, the path is required",
- Seq("-p", "__ow_user", "_", "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp", "-p", "operation", "get")),
-
- //createApi
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is required", Seq("-p", "__ow_user", "_")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is missing the namespace field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", "{}")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is missing the gatewayBasePath field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_"}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is missing the gatewayPath field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp"}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is missing the gatewayMethod field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp"}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is missing the action field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get"}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the backendMethod field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the backendUrl field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post"}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the namespace field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL"}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the name field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_"}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the authkey field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_","name":"N"}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "swagger and gatewayBasePath are mutually exclusive and cannot be specified together",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_","name":"N","authkey":"XXXX"},"swagger":{}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc field cannot be parsed. Ensure it is valid JSON",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", "{1:[}}}")))
-
- invalidArgs foreach {
- case (action: String, exitcode: Int, errmsg: String, params: Seq[String]) =>
- val cmd: Seq[String] = Seq("action",
- "invoke",
- action,
- "-i", "-b", "-r",
- "--apihost", wskprops.apihost,
- "--auth", wskprops.authKey) ++ params
- val rr = wsk.cli(cmd, expectedExitCode = exitcode)
- rr.stderr should include regex (errmsg)
- }
- }
-
- behavior of "API Gateway apimgmt action parameter validation"
-
- it should "verify successful creation of a new V2 API" in {
- val testName = "APIGWTEST1"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- val actionNamespace = wskprops.namespace
- val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
- val actionAuthKey = testName + "_authkey"
- val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
-
- try {
- val createResult = createApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), relpath = Some(testrelpath),
- operation = Some(testurlop), apiname = Some(testapiname), action = Some(testaction))
- JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
- val apiVector = getApisV2(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- apiVector.size should be > 0
- apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
- } finally {
- val deleteResult = deleteApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify successful V2 API deletion using basepath" in {
- val testName = "APIGWTEST2"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- val actionNamespace = wskprops.namespace
- val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
- val actionAuthKey = testName + "_authkey"
- val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
-
- try {
- val createResult = createApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), relpath = Some(testrelpath),
- operation = Some(testurlop), apiname = Some(testapiname), action = Some(testaction))
- JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
- var apiVector = getApisV2(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- apiVector.size should be > 0
- apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
- val deleteResult = deleteApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath))
- apiVector = getApisV2(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(false)
- } finally {
- val deleteResult = deleteApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify successful addition of new relative path to existing V2 API" in {
- val testName = "APIGWTEST3"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testnewurlop = "delete"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- val actionNamespace = wskprops.namespace
- val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
- val actionAuthKey = testName + "_authkey"
- val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
-
- try {
- var createResult = createApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), relpath = Some(testrelpath),
- operation = Some(testurlop), apiname = Some(testapiname), action = Some(testaction))
- createResult = createApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), relpath = Some(testnewrelpath),
- operation = Some(testnewurlop), apiname = Some(testapiname), action = Some(testaction))
- JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
- var apiVector = getApisV2(bpOrName = Some(testbasepath))
- apiVector.size should be > 0
apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
apiMatch(apiVector, testbasepath, testnewrelpath, testnewurlop, testapiname, testaction) should be(true)
} finally {
- val deleteResult = deleteApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
+ val deleteResult = deleteApi(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
}
}
diff --git a/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala b/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
index aa3fd84..0944044 100644
--- a/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
@@ -18,6 +18,8 @@
package whisk.core.cli.test
import java.io.File
+import java.io.BufferedWriter
+import java.io.FileWriter
import java.time.Instant
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.duration._
@@ -30,7 +32,6 @@ import common.TestCLIUtils
import common.WhiskProperties
import common.Wsk
import common.WskProps
-import common.WskPropsV2
import common.WskTestHelpers
/**
@@ -94,7 +95,7 @@ class ApiGwTests
override def beforeAll() = {
//cliWskPropsFile = File.createTempFile("wskprops", ".tmp")
cliWskPropsFile.deleteOnExit()
- val wskprops = WskPropsV2(token = "SOME TOKEN")
+ val wskprops = WskProps(token = "SOME TOKEN")
wskprops.writeFile(cliWskPropsFile)
println(s"wsk temporary props file created here: ${cliWskPropsFile.getCanonicalPath()}")
}
@@ -108,51 +109,6 @@ class ApiGwTests
checkThrottle(30)
}
- def apiCreateExperimental(
- basepath: Option[String] = None,
- relpath: Option[String] = None,
- operation: Option[String] = None,
- action: Option[String] = None,
- apiname: Option[String] = None,
- swagger: Option[String] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
-
- checkThrottle()
- wsk.apiexperimental.create(basepath, relpath, operation, action, apiname, swagger, expectedExitCode)
- }
-
- def apiListExperimental(
- basepathOrApiName: Option[String] = None,
- relpath: Option[String] = None,
- operation: Option[String] = None,
- limit: Option[Int] = None,
- since: Option[Instant] = None,
- full: Option[Boolean] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
-
- checkThrottle()
- wsk.apiexperimental.list(basepathOrApiName, relpath, operation, limit, since, full, expectedExitCode)
- }
-
- def apiGetExperimental(
- basepathOrApiName: Option[String] = None,
- full: Option[Boolean] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
-
- checkThrottle()
- wsk.apiexperimental.get(basepathOrApiName, full, expectedExitCode)
- }
-
- def apiDeleteExperimental(
- basepathOrApiName: String,
- relpath: Option[String] = None,
- operation: Option[String] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
-
- checkThrottle()
- wsk.apiexperimental.delete(basepathOrApiName, relpath, operation, expectedExitCode)
- }
-
def apiCreate(
basepath: Option[String] = None,
relpath: Option[String] = None,
@@ -204,402 +160,77 @@ class ApiGwTests
wsk.api.delete(basepathOrApiName, relpath, operation, expectedExitCode, cliCfgFile)
}
- behavior of "Wsk api-experimental"
+ behavior of "Wsk api"
- it should "reject api commands having an invalid path parameter" in {
+ it should "reject an api commands with an invalid path parameter" in {
val badpath = "badpath"
- var rr = apiCreateExperimental(basepath = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), action = Some("action"), expectedExitCode = ANY_ERROR_EXIT)
+ var rr = apiCreate(basepath = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), action = Some("action"), expectedExitCode = ANY_ERROR_EXIT)
rr.stderr should include (s"'${badpath}' must begin with '/'")
- rr = apiDeleteExperimental(basepathOrApiName = "/basepath", relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
+ rr = apiDelete(basepathOrApiName = "/basepath", relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
rr.stderr should include (s"'${badpath}' must begin with '/'")
- rr = apiListExperimental(basepathOrApiName = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
+ rr = apiList(basepathOrApiName = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
rr.stderr should include (s"'${badpath}' must begin with '/'")
}
- it should "verify full list output" 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 {
- println("cli namespace: " + clinamespace)
-
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- println("api create: " + rr.stdout)
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), full = Some(true))
- println("api list: " + rr.stdout)
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"Action:\\s+/${clinamespace}/${actionName}\n")
- rr.stdout should include regex (s"Verb:\\s+${testurlop}\n")
- rr.stdout should include regex (s"Base path:\\s+${testbasepath}\n")
- rr.stdout should include regex (s"Path:\\s+${testrelpath}\n")
- rr.stdout should include regex (s"API Name:\\s+${testapiname}\n")
- rr.stdout should include regex (s"URL:\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath)
- }
- }
-
- it should "verify successful creation and deletion of a new API" in {
- val testName = "CLI_APIGWTEST1"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- try {
- println("cli namespace: "+clinamespace)
-
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath)
- deleteresult.stdout should include("ok: deleted API")
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify get API name " in {
- val testName = "CLI_APIGWTEST3"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiGetExperimental(basepathOrApiName = Some(testapiname))
- rr.stdout should include(testbasepath)
- rr.stdout should include(s"${actionName}")
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify delete API name " in {
- val testName = "CLI_APIGWTEST4"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiDeleteExperimental(basepathOrApiName = testapiname)
- rr.stdout should include("ok: deleted API")
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify delete API basepath " in {
- val testName = "CLI_APIGWTEST5"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiDeleteExperimental(basepathOrApiName = testbasepath)
- rr.stdout should include("ok: deleted API")
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify adding endpoints to existing api" in {
- val testName = "CLI_APIGWTEST6"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path2"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- val newEndpoint = "/newEndpoint"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(newEndpoint), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr.stdout should include(testbasepath + newEndpoint)
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify successful creation with swagger doc as input" in {
- // NOTE: These values must match the swagger file contents
- val testName = "CLI_APIGWTEST7"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- val swaggerPath = TestCLIUtils.getTestApiGwFilename("testswaggerdoc1")
- try {
- var rr = apiCreateExperimental(swagger = Some(swaggerPath))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- println("list stdout: "+rr.stdout)
- println("list stderr: "+rr.stderr)
- rr.stdout should include("ok: APIs")
- // Actual CLI namespace will vary from local dev to automated test environments, so don't check
- rr.stdout should include regex (s"/[@\\w._\\-]+/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify adding endpoints to two existing apis" in {
- val testName = "CLI_APIGWTEST8"
- val testbasepath = "/"+testName+"_bp"
- val testbasepath2 = "/"+testName+"_bp2"
- val testrelpath = "/path2"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- val newEndpoint = "/newEndpoint"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiCreateExperimental(basepath = Some(testbasepath2), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
+ it should "reject an api commands with an invalid verb parameter" in {
+ val badverb = "badverb"
- // Update both APIs - each with a new endpoint
- rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(newEndpoint), operation = Some(testurlop), action = Some(actionName))
- rr.stdout should include("ok: created API")
- rr = apiCreateExperimental(basepath = Some(testbasepath2), relpath = Some(newEndpoint), operation = Some(testurlop), action = Some(actionName))
- rr.stdout should include("ok: created API")
+ var rr = apiCreate(basepath = Some("/basepath"), relpath = Some("/path"), operation = Some(badverb), action = Some("action"), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr.stdout should include(testbasepath + newEndpoint)
+ rr = apiDelete(basepathOrApiName = "/basepath", relpath = Some("/path"), operation = Some(badverb), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath2))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath2 + testrelpath)
- rr.stdout should include(testbasepath2 + newEndpoint)
- }
- finally {
- var deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath2, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify successful creation of a new API using an action name using all allowed characters" in {
- // Be aware: full action name is close to being truncated by the 'list' command
- // e.g. /lime@us.ibm.com/CLI_APIGWTEST9a-c@t ion is currently at the 40 char 'list' display max
- val testName = "CLI_APIGWTEST9"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"a-c@t ion"
- try {
- println("cli namespace: "+clinamespace)
-
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath)
- deleteresult.stdout should include("ok: deleted API")
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify failed creation with invalid swagger doc as input" in {
- val testName = "CLI_APIGWTEST10"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- val swaggerPath = TestCLIUtils.getTestApiGwFilename(s"testswaggerdocinvalid")
- try {
- var rr = apiCreateExperimental(swagger = Some(swaggerPath), expectedExitCode = ANY_ERROR_EXIT)
- println("api create stdout: " + rr.stdout)
- println("api create stderr: " + rr.stderr)
- rr.stderr should include(s"Swagger file is invalid")
- } finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify delete basepath/path " in {
- val testName = "CLI_APIGWTEST11"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- var rr2 = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testnewrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr2.stdout should include("ok: created API")
- rr = apiDeleteExperimental(basepathOrApiName = testbasepath, relpath = Some(testrelpath))
- rr.stdout should include("ok: deleted " + testrelpath +" from "+ testbasepath)
- rr2 = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testnewrelpath))
- rr2.stdout should include("ok: APIs")
- rr2.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr2.stdout should include(testbasepath + testnewrelpath)
- } finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
+ rr = apiList(basepathOrApiName = Some("/basepath"), relpath = Some("/path"), operation = Some(badverb), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
}
- it should "verify delete single operation from existing API basepath/path/operation(s) " in {
- val testName = "CLI_APIGWTEST12"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path2"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testurlop2 = "post"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop2), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr = apiDeleteExperimental(basepathOrApiName = testbasepath,relpath = Some(testrelpath), operation = Some(testurlop2))
- rr.stdout should include("ok: deleted " + testrelpath + " " + "POST" +" from "+ testbasepath)
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath))
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- } finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
+ it should "reject an api create command that specifies a nonexistent configuration file" in {
+ val configfile = "/nonexistent/file"
- it should "verify successful creation with complex swagger doc as input" in {
- val testName = "CLI_APIGWTEST13"
- val testbasepath = "/test1/v1"
- val testrelpath = "/whisk.system/utils/echo"
- val testrelpath2 = "/whisk.system/utils/split"
- val testurlop = "get"
- val testapiname = "/test1/v1"
- val actionName = "test1a"
- val swaggerPath = TestCLIUtils.getTestApiGwFilename(s"testswaggerdoc2")
- try {
- var rr = apiCreateExperimental(swagger = Some(swaggerPath))
- println("api create stdout: " + rr.stdout)
- println("api create stderror: " + rr.stderr)
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath))
- rr.stdout should include("ok: APIs")
- // Actual CLI namespace will vary from local dev to automated test environments, so don't check
- rr.stdout should include regex (s"/[@\\w._\\-]+/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr.stdout should include(testbasepath + testrelpath2)
- } finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
+ var rr = apiCreate(swagger = Some(configfile), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"Error reading swagger file '${configfile}':")
}
- it should "verify successful creation and deletion with multiple base paths" in {
- val testName = "CLI_APIGWTEST14"
- val testbasepath = "/" + testName + "_bp"
- val testbasepath2 = "/" + testName + "_bp2"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr = apiCreateExperimental(basepath = Some(testbasepath2), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath2), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath2 + testrelpath)
- rr = apiDeleteExperimental(basepathOrApiName = testbasepath2)
- rr.stdout should include("ok: deleted API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr = apiDeleteExperimental(basepathOrApiName = testbasepath)
- rr.stdout should include("ok: deleted API")
- } finally {
- var deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath2, expectedExitCode = DONTCARE_EXIT)
- }
- }
+ it should "reject an api create command specifying a non-JSON configuration file" in {
+ val file = File.createTempFile("api.json", ".txt")
+ file.deleteOnExit()
+ val filename = file.getAbsolutePath()
- it should "reject deletion of a non-existent api" in {
- val nonexistentApi = "/not-there"
+ val bw = new BufferedWriter(new FileWriter(file))
+ bw.write("a=A")
+ bw.close()
- var rr = apiDeleteExperimental(basepathOrApiName = nonexistentApi, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include (s"API '${nonexistentApi}' does not exist")
+ var rr = apiCreate(swagger = Some(filename), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"Error parsing swagger file '${filename}':")
}
- behavior of "Wsk api"
+ it should "reject an api create command specifying a non-swagger JSON configuration file" in {
+ val file = File.createTempFile("api.json", ".txt")
+ file.deleteOnExit()
+ val filename = file.getAbsolutePath()
- it should "reject an api commands with an invalid path parameter" in {
- val badpath = "badpath"
-
- var rr = apiCreate(basepath = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), action = Some("action"), expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include (s"'${badpath}' must begin with '/'")
-
- rr = apiDelete(basepathOrApiName = "/basepath", relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include (s"'${badpath}' must begin with '/'")
+ val bw = new BufferedWriter(new FileWriter(file))
+ bw.write("""|{
+ | "swagger": "2.0",
+ | "info": {
+ | "title": "My API",
+ | "version": "1.0.0"
+ | },
+ | "BADbasePath": "/bp",
+ | "paths": {
+ | "/rp": {
+ | "get":{}
+ | }
+ | }
+ |}""".stripMargin)
+ bw.close()
- rr = apiList(basepathOrApiName = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include (s"'${badpath}' must begin with '/'")
+ var rr = apiCreate(swagger = Some(filename), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"Swagger file is invalid (missing basePath, info, paths, or swagger fields")
}
it should "verify full list output" in {
@@ -781,7 +412,11 @@ class ApiGwTests
val testurlop = "get"
val testapiname = testName+" API Name"
val actionName = testName+"_action"
+<<<<<<< HEAD
val swaggerPath = TestCLIUtils.getTestApiGwFilename("testswaggerdoc1V2")
+=======
+ val swaggerPath = TestUtils.getTestApiGwFilename("testswaggerdoc1")
+>>>>>>> a509e00... Remove "experimental" gateway api (#2547)
try {
var rr = apiCreate(swagger = Some(swaggerPath))
rr.stdout should include("ok: created API")
@@ -963,7 +598,11 @@ class ApiGwTests
val testurlop = "get"
val testapiname = testName + " API Name"
val actionName = "test1a"
+<<<<<<< HEAD
val swaggerPath = TestCLIUtils.getTestApiGwFilename(s"testswaggerdoc2V2")
+=======
+ val swaggerPath = TestUtils.getTestApiGwFilename(s"testswaggerdoc2")
+>>>>>>> a509e00... Remove "experimental" gateway api (#2547)
try {
var rr = apiCreate(swagger = Some(swaggerPath))
println("api create stdout: " + rr.stdout)
@@ -1035,7 +674,7 @@ class ApiGwTests
rr.stderr should include("does not exist")
}
finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
+ val deleteresult = apiDelete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
}
}
diff --git a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
index e0234f8..a9dd84b 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
@@ -17,9 +17,6 @@
package whisk.core.cli.test
-import java.io.File
-import java.io.BufferedWriter
-import java.io.FileWriter
import java.time.Instant
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
@@ -845,84 +842,6 @@ class WskBasicUsageTests
}
}
- behavior of "Wsk api"
-
- it should "reject an api commands with an invalid path parameter" in {
- val badpath = "badpath"
-
- var rr = wsk.cli(Seq("api-experimental", "create", "/basepath", badpath, "GET", "action", "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badpath}' must begin with '/'")
-
- rr = wsk.cli(Seq("api-experimental", "delete", "/basepath", badpath, "GET", "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badpath}' must begin with '/'")
-
- rr = wsk.cli(Seq("api-experimental", "list", "/basepath", badpath, "GET", "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badpath}' must begin with '/'")
- }
-
- it should "reject an api commands with an invalid verb parameter" in {
- val badverb = "badverb"
-
- var rr = wsk.cli(Seq("api-experimental", "create", "/basepath", "/path", badverb, "action", "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
-
- rr = wsk.cli(Seq("api-experimental", "delete", "/basepath", "/path", badverb, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
-
- rr = wsk.cli(Seq("api-experimental", "list", "/basepath", "/path", badverb, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
- }
-
- it should "reject an api create command with an API name argument and an API name option" in {
- val apiName = "An API Name"
- val rr = wsk.cli(Seq("api-experimental", "create", apiName, "/path", "GET", "action", "-n", apiName, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"An API name can only be specified once.")
- }
-
- it should "reject an api create command that specifies a nonexistent configuration file" in {
- val configfile = "/nonexistent/file"
- val rr = wsk.cli(Seq("api-experimental", "create", "-c", configfile, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"Error reading swagger file '${configfile}':")
- }
-
- it should "reject an api create command specifying a non-JSON configuration file" in {
- val file = File.createTempFile("api.json", ".txt")
- file.deleteOnExit()
- val filename = file.getAbsolutePath()
-
- val bw = new BufferedWriter(new FileWriter(file))
- bw.write("a=A")
- bw.close()
-
- val rr = wsk.cli(Seq("api-experimental", "create", "-c", filename, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"Error parsing swagger file '${filename}':")
- }
-
- it should "reject an api create command specifying a non-swagger JSON configuration file" in {
- val file = File.createTempFile("api.json", ".txt")
- file.deleteOnExit()
- val filename = file.getAbsolutePath()
-
- val bw = new BufferedWriter(new FileWriter(file))
- bw.write("""|{
- | "swagger": "2.0",
- | "info": {
- | "title": "My API",
- | "version": "1.0.0"
- | },
- | "BADbasePath": "/bp",
- | "paths": {
- | "/rp": {
- | "get":{}
- | }
- | }
- |}""".stripMargin)
- bw.close()
-
- val rr = wsk.cli(Seq("api-experimental", "create", "-c", filename, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"Swagger file is invalid (missing basePath, info, paths, or swagger fields")
- }
-
behavior of "Wsk entity list formatting"
it should "create, and list a package with a long name" in withAssetCleaner(wskprops) {
@@ -1187,13 +1106,13 @@ class WskBasicUsageTests
val invalidShared = s"Cannot use value '$invalidArg' for shared"
val entityNameMsg = s"An entity name, '$invalidArg', was provided instead of a namespace. Valid namespaces are of the following format: /NAMESPACE."
val invalidArgs = Seq(
- (Seq("api-experimental", "create"), s"${tooFewArgsMsg} ${apiCreateReqMsg}"),
- (Seq("api-experimental", "create", "/basepath", "/path", "GET", "action", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiCreateReqMsg}"),
- (Seq("api-experimental", "get"), s"${tooFewArgsMsg} ${apiGetReqMsg}"),
- (Seq("api-experimental", "get", "/basepath", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiGetReqMsg}"),
- (Seq("api-experimental", "delete"), s"${tooFewArgsMsg} ${apiDeleteReqMsg}"),
- (Seq("api-experimental", "delete", "/basepath", "/path", "GET", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiDeleteReqMsg}"),
- (Seq("api-experimental", "list", "/basepath", "/path", "GET", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiListReqMsg}"),
+ (Seq("api", "create"), s"${tooFewArgsMsg} ${apiCreateReqMsg}"),
+ (Seq("api", "create", "/basepath", "/path", "GET", "action", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiCreateReqMsg}"),
+ (Seq("api", "get"), s"${tooFewArgsMsg} ${apiGetReqMsg}"),
+ (Seq("api", "get", "/basepath", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiGetReqMsg}"),
+ (Seq("api", "delete"), s"${tooFewArgsMsg} ${apiDeleteReqMsg}"),
+ (Seq("api", "delete", "/basepath", "/path", "GET", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiDeleteReqMsg}"),
+ (Seq("api", "list", "/basepath", "/path", "GET", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiListReqMsg}"),
(Seq("action", "create"), s"${tooFewArgsMsg} ${actionNameActionReqMsg}"),
(Seq("action", "create", "someAction"), s"${tooFewArgsMsg} ${actionNameActionReqMsg}"),
(Seq("action", "create", "actionName", "artifactName", invalidArg), s"${tooManyArgsMsg}${invalidArg}."),
--
To stop receiving notification emails like this one, please contact
"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>.