Skip to content

Commit

Permalink
feat(provider/google): added first test
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandrov authored and maggieneterval committed Oct 15, 2019
1 parent d5a5be2 commit 8f958a5
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,76 @@ class UpsertGoogleLoadBalancerAtomicOperationUnitSpec extends Specification {
1 * regionForwardingRuleOperationGet.execute() >> forwardingRuleInsertOp
}

void "should create a network load balancer with the specified session affinity if it is provided"() {
setup:
def computeMock = Mock(Compute)
def regionOperations = Mock(Compute.RegionOperations)
def regionTargetPoolOperationGet = Mock(Compute.RegionOperations.Get)
def targetPools = Mock(Compute.TargetPools)
def targetPoolsInsert = Mock(Compute.TargetPools.Insert)
def targetPoolsInsertOp = new Operation(
targetLink: "target-pool",
name: TARGET_POOL_OP_NAME,
status: DONE)
def regions = Mock(Compute.Regions)
def regionsList = Mock(Compute.Regions.List)
def regionsListReal = new RegionList(
items: [new Region(name: REGION_US), new Region(name: REGION_ASIA), new Region(name: REGION_EUROPE)])
def forwardingRules = Mock(Compute.ForwardingRules)
def forwardingRulesInsert = Mock(Compute.ForwardingRules.Insert)
def regionForwardingRuleOperationGet = Mock(Compute.RegionOperations.Get)
def forwardingRuleInsertOp = new Operation(
targetLink: "forwarding-rule",
name: LOAD_BALANCER_NAME,
status: DONE)
def credentials = new GoogleNamedAccountCredentials.Builder().project(PROJECT_NAME).compute(computeMock).build()
def description = new UpsertGoogleLoadBalancerDescription(
loadBalancerName: LOAD_BALANCER_NAME,
region: REGION_US,
accountName: ACCOUNT_NAME,
credentials: credentials,
sessionAffinity: GoogleSessionAffinity.CLIENT_IP
)
@Subject def operation = new UpsertGoogleLoadBalancerAtomicOperation(description)
operation.registry = registry
operation.safeRetry = safeRetry
operation.googleOperationPoller =
new GoogleOperationPoller(
googleConfigurationProperties: new GoogleConfigurationProperties(),
threadSleeper: threadSleeperMock,
registry: registry,
safeRetry: safeRetry
)

when:
operation.operate([])

then:
1 * computeMock.regions() >> regions
1 * regions.list(PROJECT_NAME) >> regionsList
1 * regionsList.execute() >> regionsListReal
3 * computeMock.forwardingRules() >> forwardingRules
1 * forwardingRules.get(PROJECT_NAME, REGION_US, LOAD_BALANCER_NAME) >>
{ throw GoogleJsonResponseExceptionFactoryTesting.newMock(new MockJsonFactory(), 404, "not found") }
1 * forwardingRules.get(PROJECT_NAME, REGION_ASIA, LOAD_BALANCER_NAME) >>
{ throw GoogleJsonResponseExceptionFactoryTesting.newMock(new MockJsonFactory(), 404, "not found") }
1 * forwardingRules.get(PROJECT_NAME, REGION_EUROPE, LOAD_BALANCER_NAME) >>
{ throw GoogleJsonResponseExceptionFactoryTesting.newMock(new MockJsonFactory(), 404, "not found") }
0 * computeMock.httpHealthChecks()
1 * computeMock.targetPools() >> targetPools
1 * targetPools.insert(PROJECT_NAME, REGION_US, { it.getSessionAffinity() == GoogleSessionAffinity.CLIENT_IP.toString() }) >> targetPoolsInsert
1 * targetPoolsInsert.execute() >> targetPoolsInsertOp
1 * computeMock.forwardingRules() >> forwardingRules
1 * forwardingRules.insert(PROJECT_NAME, REGION_US, {it.IPAddress == null && it.portRange == Constants.DEFAULT_PORT_RANGE}) >> forwardingRulesInsert
1 * forwardingRulesInsert.execute() >> forwardingRuleInsertOp

2 * computeMock.regionOperations() >> regionOperations
1 * regionOperations.get(PROJECT_NAME, REGION_US, TARGET_POOL_OP_NAME) >> regionTargetPoolOperationGet
1 * regionTargetPoolOperationGet.execute() >> targetPoolsInsertOp
1 * regionOperations.get(PROJECT_NAME, REGION_US, LOAD_BALANCER_NAME) >> regionForwardingRuleOperationGet
1 * regionForwardingRuleOperationGet.execute() >> forwardingRuleInsertOp
}

void "should neither create anything new, nor edit anything existing, if a forwarding rule with the same name already exists in the same region"() {
setup:
def computeMock = Mock(Compute)
Expand Down

0 comments on commit 8f958a5

Please sign in to comment.