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

Rewrite wsk basic tests #3103

Merged
merged 2 commits into from
Jan 24, 2018
Merged

Conversation

houshengbo
Copy link

@houshengbo houshengbo commented Dec 13, 2017

This rewrites the test cases in WskBasicTests by implementing them in REST interface.

@houshengbo houshengbo force-pushed the rewrite-WskBasicTests branch 2 times, most recently from ac1835d to 44808c8 Compare December 13, 2017 20:43
@houshengbo houshengbo added review Review for this PR has been requested and yet needs to be done. cli labels Dec 13, 2017
@houshengbo houshengbo force-pushed the rewrite-WskBasicTests branch from 44808c8 to 06f9236 Compare December 13, 2017 22:41
@markusthoemmes
Copy link
Contributor

Please provide a description about what this PR is supposed to solve and what's the intended change.

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

Please fix mutability aspects and some parsing which could make the tests clearer.

stdout should include regex (""""key":"a"""")
stdout should include regex (""""value":"A"""")
stdout should include regex (""""publish":true""")
stdout should include regex (""""version":"0.0.2"""")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we parse the JSON response of the API and then assert on the parsed values? That would remove those whitespace issues alltogether.

result.getField("version") shouldBe "0.0.1"
result.getFieldJsValue("publish").toString shouldBe "false"
result.getFieldJsValue("binding").toString shouldBe "{}"
result.getField("invalid") shouldBe ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Above tests should work like this!

Copy link
Author

Choose a reason for hiding this comment

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

Done

case (value) =>
val fullName = fullEntityName(value)
paramsList :+= JsString(fullName)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

See #2996 for comments on these parts.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@dubee dubee left a comment

Choose a reason for hiding this comment

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

@houshengbo, what's the status of this PR?

@rabbah rabbah self-requested a review January 11, 2018 02:00
@houshengbo houshengbo force-pushed the rewrite-WskBasicTests branch from 2b7eee0 to 67b2f51 Compare January 11, 2018 16:05
ActivationResult.serdes.read(removeCLIHeader(stderr).parseJson).response.result shouldBe Some {
JsObject("error" -> JsObject("msg" -> "failed activation on purpose".toJson))
}
val result = wsk.action.invoke(name, blocking = true, expectedExitCode = 502)
Copy link
Member

Choose a reason for hiding this comment

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

502? Why not use the akka code?

Copy link
Author

Choose a reason for hiding this comment

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

done.

stdout should include regex (""""version": "0.0.2"""")
wsk.pkg.list().stdout should include(name)
val pack = wsk.pkg.get(name)
pack.getFieldJsValue("publish").toString shouldBe "true"
Copy link
Member

Choose a reason for hiding this comment

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

you can remove toString and use shouldBe JsBoolean(true) also fyi.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

val stderr = wsk.pkg.create(name, expectedExitCode = CONFLICT).stderr
stderr should include regex (s"""Unable to create package '$name': resource already exists \\(code \\d+\\)""")
val stderr = wsk.pkg.create(name, expectedExitCode = Conflict.intValue).stderr
stderr should include regex (s"""resource already exists""")
Copy link
Member

@rabbah rabbah Jan 12, 2018

Choose a reason for hiding this comment

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

many cases of s"""xxx""" dont need string interpolation, and can just be "xxx".

Copy link
Author

Choose a reason for hiding this comment

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

Done.

.stdout should include regex (""""count": 3""")
val result = wsk.action
.invoke(name, Map("payload" -> "one two three".toJson), blocking = true, result = true)
result.stdout should include regex (""""count":3""")
Copy link
Member

@rabbah rabbah Jan 12, 2018

Choose a reason for hiding this comment

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

this check is weaker now - it should be:
result.stdout.parseJson.asJsObject shouldBe JsObject("count" -> JsNumber(3))

Copy link
Author

Choose a reason for hiding this comment

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

Done.

}

it should "list entities in default namespace" in {
// use a fresh wsk props instance that is guaranteed to use
// the default namespace
wsk.namespace.get(expectedExitCode = SUCCESS_EXIT)(WskProps()).stdout should include("default")
val result = wsk.namespace.get()(WskProps()).stdout
result should include("actions")
Copy link
Member

Choose a reason for hiding this comment

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

how about parsing the output and checking that it's a JsObject that includes these four fields, and each value is an JsArray.

Copy link
Author

Choose a reason for hiding this comment

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

I will remove this test case, since get is not supported by REST implementation.


it should "not list entities with an invalid namespace" in {
val namespace = "fakeNamespace"
val stderr = wsk.namespace.get(Some(s"/${namespace}"), expectedExitCode = Forbidden.intValue).stderr
Copy link
Member

Choose a reason for hiding this comment

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

use action list as this will no longer work soon.

Copy link
Author

@houshengbo houshengbo Jan 12, 2018

Choose a reason for hiding this comment

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

I will remove this test case, since get is not supported by REST implementation.

Copy link
Member

@rabbah rabbah left a comment

Choose a reason for hiding this comment

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

See comments.

@rabbah rabbah self-assigned this Jan 12, 2018
@houshengbo houshengbo force-pushed the rewrite-WskBasicTests branch 4 times, most recently from eed4114 to c03dbd3 Compare January 12, 2018 21:56
@rabbah
Copy link
Member

rabbah commented Jan 17, 2018

@markusthoemmes can you update your review?

@houshengbo
Copy link
Author

Relaunched a PG: Playground3 1691.

@houshengbo houshengbo force-pushed the rewrite-WskBasicTests branch 2 times, most recently from 599e390 to 63e9aff Compare January 17, 2018 21:11
result.getField("name") shouldBe name
result.getField("version") shouldBe "0.0.1"
result.getFieldJsValue("publish") shouldBe JsBoolean(false)
result.getFieldJsValue("binding").toString shouldBe "{}"
Copy link
Member

@rabbah rabbah Jan 23, 2018

Choose a reason for hiding this comment

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

result.getFieldJsValue("binding") shouldBe JsObject()?

result.getFieldJsValue("annotations").toString shouldBe "[]"
result.getFieldJsValue("parameters") shouldBe JsArray(
JsObject("key" -> JsString("payload"), "value" -> JsString("test")))
result.getFieldJsValue("limits").toString shouldBe "{}"
Copy link
Member

Choose a reason for hiding this comment

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

i think you can replace all the {} checks with JsObject()

@rabbah rabbah dismissed markusthoemmes’s stale review January 23, 2018 03:29

requested changes already made.

@houshengbo houshengbo force-pushed the rewrite-WskBasicTests branch from 63e9aff to 1e84f61 Compare January 23, 2018 16:20
@rabbah rabbah merged commit 469c5a5 into apache:master Jan 24, 2018
BillZong pushed a commit to BillZong/openwhisk that referenced this pull request Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli review Review for this PR has been requested and yet needs to be done.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants