Skip to content

Commit

Permalink
Allow to replace specify version
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Oct 29, 2020
1 parent 4bb0e0e commit 49396bf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
case Success(_) =>
onComplete(WhiskActionVersionList.get(entityName, entityStore)) {
case Success(result) =>
val id = result.matchedDocId(None).getOrElse(entityName.toDocId)
val id = result.matchedDocId(content.version).getOrElse(entityName.toDocId)
putEntity(
WhiskAction,
entityStore,
Expand Down Expand Up @@ -685,6 +685,9 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
.map(_ ++ content.annotations)
.getOrElse(action.annotations ++ content.annotations)

// if content provided a `version`, then new action should overwrite old entity in database
val newRev = content.version.map(_ => action.rev).getOrElse(DocRevision.empty)

WhiskAction(
action.namespace,
action.name,
Expand All @@ -693,7 +696,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
limits,
content.version getOrElse action.version.upPatch,
content.publish getOrElse action.publish,
WhiskActionsApi.amendAnnotations(newAnnotations, exec, create = false))
WhiskActionsApi.amendAnnotations(newAnnotations, exec, create = false)).revision[WhiskAction](newRev)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,48 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
}
}

it should "replace old action if version is provided" in {
implicit val tid = transid()
val action = WhiskAction(namespace, aname(), jsDefault("??"), Parameters("x", "b"))
val content = WhiskActionPut(parameters = Some(Parameters("x", "X")))
put(entityStore, action)
val action2 = action.copy(
parameters = content.parameters.get,
version = action.version.upPatch,
annotations = action.annotations ++ systemAnnotations(NODEJS10, false))
Put(s"$collectionPath/${action.name}", content) ~> Route.seal(routes(creds)) ~> check {
status should be(OK)
val response = responseAs[WhiskAction]
checkWhiskEntityResponse(response, action2)
}

// the first version should not be replaced
Get(s"$collectionPath/${action.name}?version=0.0.1") ~> Route.seal(routes(creds)) ~> check {
status should be(OK)
val response = responseAs[WhiskAction]
response should be(action)
}

// it should update based on the given version, action1 here, and replace it in database
val content2 = WhiskActionPut(version = Some(action.version), annotations = Some(Parameters("x", "X")))
val action3 =
action.copy(annotations = action.annotations ++ content2.annotations ++ systemAnnotations(NODEJS10, false))
Put(s"$collectionPath/${action.name}", content2) ~> Route.seal(routes(creds)) ~> check {
status should be(OK)
val response = responseAs[WhiskAction]
checkWhiskEntityResponse(response, action3)
}

// the first version should be replaced with action3
Get(s"$collectionPath/${action.name}?version=0.0.1") ~> Route.seal(routes(creds)) ~> check {
deleteAction(action.docid)
deleteAction(action2.docid)
status should be(OK)
val response = responseAs[WhiskAction]
checkWhiskEntityResponse(response, action3)
}
}

it should "delete old action if its versions exceed the limit" in {
implicit val tid = transid()
val action = WhiskAction(namespace, aname(), jsDefault("??"))
Expand Down

0 comments on commit 49396bf

Please sign in to comment.