Skip to content

Commit

Permalink
Add tests for tag workflow scripts.
Browse files Browse the repository at this point in the history
Change-Id: I5567a2ab348909aa59f998610bf4fb442c8d2ea4
Closes-Bug: #1772594
  • Loading branch information
danieljasinski authored and IridiumOxide committed Jun 27, 2018
1 parent ee55942 commit a019489
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 2 deletions.
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
*/

package net.juniper.contrail.vro.tests.workflows

import net.juniper.contrail.api.Status
import net.juniper.contrail.api.types.Tag

class CreateGlobalTagSpec extends WorkflowSpec {

def createGlobalTag = workflowFromScript("Create global tag")
def tagValue = "my-global-value"
def tagType = "my-global-tag"

def "Creating global tag"() {
given:
def connection = dependencies.connection

connectorMock.read(_) >> Status.success()

when: "Script is executed"
invokeFunction(
createGlobalTag,
connection,
tagType,
tagValue
)

then: "Tag with given type and value is created"
1 * connectorMock.create({
def _it = it as Tag
_it.value == tagValue && _it.typeName == tagType
}) >> Status.success()
}
}
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
*/

package net.juniper.contrail.vro.tests.workflows

import net.juniper.contrail.api.Status
import net.juniper.contrail.api.types.Tag

class CreateTagInProjectSpec extends WorkflowSpec {

def createTagInProject = workflowFromScript("Create tag in project")
def tagValue = "my-project-scoped-value"
def tagType = "my-project-scoped-tag"

def "Creating tag in project"() {
given:
def project = dependencies.someProject()

connectorMock.read(_) >> Status.success()

when: "Script is executed"
invokeFunction(
createTagInProject,
project,
tagType,
tagValue
)

then: "Tag with given type and value is created"
1 * connectorMock.create({
def _it = it as Tag
_it.value == tagValue && _it.typeName == tagType &&
_it.parentUuid == project.uuid
}) >> Status.success()
}
}
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
*/

package net.juniper.contrail.vro.tests.workflows

import net.juniper.contrail.api.Status

class CreateTagTypeSpec extends WorkflowSpec {

def createTagType = workflowFromScript("Create tag type")
def tagName = "my-custom-tag"

def "Creating tag type"() {
given:
def connection = dependencies.connection

connectorMock.read(_) >> Status.success()

when: "Script is executed"
invokeFunction(
createTagType,
tagName,
connection
)

then: "Tag type with given name is created"
1 * connectorMock.create({it.name == tagName}) >> Status.success()
}
}
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
*/

package net.juniper.contrail.vro.tests.workflows

import net.juniper.contrail.api.Status
import net.juniper.contrail.api.types.TagType

class DeleteTagTypeSpec extends WorkflowSpec {

def deleteTagType = workflowFromScript("Delete tag type")

def "Deleting tag type"() {
given:
def tagType = dependencies.someTagType()

when: "Script is executed"
invokeFunction(
deleteTagType,
tagType
)

then: "Tag type with given name is deleted"
1 * connectorMock.delete({
def _it = it as TagType
_it.uuid == tagType.uuid && _it.name == tagType.name
}) >> Status.success()
}
}
Expand Up @@ -98,6 +98,7 @@ abstract class WorkflowSpec extends ScriptSpec {
}

private final static String setupScript = buildWrapperDefinition(
"ConfigRoot",
"ActionListType",
"AllocationPoolType",
"FloatingIp",
Expand All @@ -121,7 +122,9 @@ abstract class WorkflowSpec extends ScriptSpec {
"VnSubnetsType",
"SubnetListType",
"FirewallServiceGroupType",
"FirewallServiceType"
"FirewallServiceType",
"Tag",
"TagType"
)

private static String buildWrapperDefinition(String... types) {
Expand Down
Expand Up @@ -22,6 +22,7 @@ import net.juniper.contrail.vro.gen.ServiceHealthCheck_Wrapper
import net.juniper.contrail.vro.gen.ServiceInstance_Wrapper
import net.juniper.contrail.vro.gen.ServiceTemplate_Wrapper
import net.juniper.contrail.vro.gen.SubnetType_Wrapper
import net.juniper.contrail.vro.gen.TagType_Wrapper
import net.juniper.contrail.vro.gen.Tag_Wrapper
import net.juniper.contrail.vro.gen.Utils_Wrapper
import net.juniper.contrail.vro.gen.VirtualMachineInterfacePropertiesType_Wrapper
Expand Down Expand Up @@ -173,6 +174,13 @@ class Dependencies(private val connection: Connection_Wrapper, private val utils
setParentConnection(this@Dependencies.connection)
}

@JvmOverloads
fun someTagType() = TagType_Wrapper().apply {
uuid = randomStringUuid()
name = "someTag$uuid"
setParentConnection(this@Dependencies.connection)
}

fun someIpamSubnetType() = IpamSubnetType_Wrapper()

fun someSubnetType(ipPrefix: String = "1.2.3.4", ipPrefixLen: Int = 16) = SubnetType_Wrapper(ipPrefix, ipPrefixLen)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -14,7 +14,7 @@
<repo.url>http://${repo.host}:8280/vco-repo</repo.url>
<spring.version>4.3.7.RELEASE</spring.version>
<installation.mode>version</installation.mode>
<kotlin.version>1.2.41</kotlin.version>
<kotlin.version>1.2.50</kotlin.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<workflow.package>net.juniper.contrail</workflow.package>
<!-- Sandbox root is defined relative to submodules -->
Expand Down

0 comments on commit a019489

Please sign in to comment.