Skip to content

Commit

Permalink
fix(openstack): Fix openstack unit tests (#3402)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ezimanyi authored Feb 21, 2019
1 parent bf50df8 commit 8924760
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit 8924760

Please sign in to comment.