From 8d36c2da42366f95a7f6f6ab305ee17e662cc308 Mon Sep 17 00:00:00 2001 From: Eric Zimanyi Date: Wed, 20 Feb 2019 19:08:29 -0500 Subject: [PATCH] fix(openstack): Fix openstack unit tests The openstack unit tests fail when run locally using gradle; the root cause is that the tests are not independent, as there is a test that does metaprogramming to change the behavior of a class. --- .../client/OpenstackIdentityV3ProviderSpec.groovy | 1 - .../OpenstackNamedAccountCredentialsSpec.groovy | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/clouddriver-openstack/src/test/groovy/com/netflix/spinnaker/clouddriver/openstack/client/OpenstackIdentityV3ProviderSpec.groovy b/clouddriver-openstack/src/test/groovy/com/netflix/spinnaker/clouddriver/openstack/client/OpenstackIdentityV3ProviderSpec.groovy index db03ac86e1c..0788b840572 100644 --- a/clouddriver-openstack/src/test/groovy/com/netflix/spinnaker/clouddriver/openstack/client/OpenstackIdentityV3ProviderSpec.groovy +++ b/clouddriver-openstack/src/test/groovy/com/netflix/spinnaker/clouddriver/openstack/client/OpenstackIdentityV3ProviderSpec.groovy @@ -55,7 +55,6 @@ class OpenstackIdentityV3ProviderSpec extends Specification { mockClient = Mock(OSClient.OSClientV3) { getToken() >> { Mock(Token) } } - //IOSClientBuilder.V3.metaClass.authenticate = { mockClient } provider = Spy(OpenstackIdentityV3Provider, constructorArgs:[credentials]) { buildClient() >> { mockClient } getClient() >> { mockClient } diff --git a/clouddriver-openstack/src/test/groovy/com/netflix/spinnaker/clouddriver/openstack/security/OpenstackNamedAccountCredentialsSpec.groovy b/clouddriver-openstack/src/test/groovy/com/netflix/spinnaker/clouddriver/openstack/security/OpenstackNamedAccountCredentialsSpec.groovy index fdf1b662772..78954155035 100644 --- a/clouddriver-openstack/src/test/groovy/com/netflix/spinnaker/clouddriver/openstack/security/OpenstackNamedAccountCredentialsSpec.groovy +++ b/clouddriver-openstack/src/test/groovy/com/netflix/spinnaker/clouddriver/openstack/security/OpenstackNamedAccountCredentialsSpec.groovy @@ -19,11 +19,10 @@ package com.netflix.spinnaker.clouddriver.openstack.security import com.netflix.spinnaker.clouddriver.consul.config.ConsulConfig import com.netflix.spinnaker.clouddriver.openstack.client.OpenstackClientProvider import com.netflix.spinnaker.clouddriver.openstack.client.OpenstackIdentityV3Provider -import com.netflix.spinnaker.clouddriver.openstack.config.OpenstackConfigurationProperties +import com.netflix.spinnaker.clouddriver.openstack.client.OpenstackProviderFactory import com.netflix.spinnaker.clouddriver.openstack.config.OpenstackConfigurationProperties.LbaasConfig import com.netflix.spinnaker.clouddriver.openstack.config.OpenstackConfigurationProperties.StackConfig import org.openstack4j.api.OSClient -import org.openstack4j.api.client.IOSClientBuilder import org.openstack4j.model.identity.v3.Token import org.openstack4j.openstack.compute.domain.ext.ExtAvailabilityZone import spock.lang.Specification @@ -41,7 +40,8 @@ class OpenstackNamedAccountCredentialsSpec extends Specification { setup: // Mock out the authenticate call within Openstack4J OSClient.OSClientV3 mockClient = Mock(OSClient.OSClientV3) - IOSClientBuilder.V3.metaClass.authenticate = { mockClient } + def openStackIdentityProvider = GroovySpy(OpenstackIdentityV3Provider, global: true) + openStackIdentityProvider.buildClient() >> mockClient when: def credentials = new OpenstackNamedAccountCredentials("name", "test", "main", "user", "pw", "project", "domain", "endpoint", [], false, "", new LbaasConfig(pollTimeout: 60, pollInterval: 5),new StackConfig(pollTimeout: 60, pollInterval: 5), new ConsulConfig(), null) @@ -62,7 +62,9 @@ class OpenstackNamedAccountCredentialsSpec extends Specification { def "Builder populates region-to-zone map: #description"() { setup: OpenstackClientProvider mockProvider = Mock(OpenstackClientProvider) - OpenstackCredentials.metaClass.getProvider = { mockProvider } + GroovyMock(OpenstackProviderFactory, global: true) { + OpenstackProviderFactory.createProvider(_) >> mockProvider + } when: def builder = new OpenstackNamedAccountCredentials.Builder()