-1

I have a very simple Spring application with cloud config client and oauth resources. It's turning out to be quite a challenge to run the unit tests without requiring the config server to be up.

None of the solutions out there for disabling cloud config client work for the latest version of spring. I have even tried to use empty or bogus config.import urls, but neither disable it. I really dont want to spin up the config server just for running unit tests and it doesnt feel like the correct way either.

What is the recommended way to setup tests for a config client application?

Looking for pointers, ideas.

Thankyou!

Battlefury
  • 247
  • 1
  • 4
  • 20

1 Answers1

0

Making the configuration optional in test seems to do the job, though you still see an attempt being made to download the config.

spring.config.import: "optional:configserver:http://localhost:8888"

OR you can use

spring.cloud.config.enabled: false

However, client will always attempt to download the configuration, even though it appears to treat it as optional and moves on. I think this is really confusing for new users - one thinks the client is still enabled. What happens when the configserver is up and you expect the client to not download the config, but it still does. I guess the only way to find out is to test.

The weird part is that the following combination fails to load the context.

spring.config.import: "optional:configserver:http://localhost:8888"
spring.cloud.config.enabled: false

Either the import is set to optional or the config is disabled, but not both at the same time.

And, this is only for the tests. Creating another profile application-standalone.yml with same settings as test, fails.

Battlefury
  • 247
  • 1
  • 4
  • 20
  • Have you tried solutions described in this thread? The answer from Doug looks promising ;) : https://stackoverflow.com/questions/41985262/spring-boot-test-overriding-bootstrap-properties – Mark Bramnik May 23 '21 at 08:19
  • @MarkBramnik The latest version of cloud-config-client does not use bootstap.properties (https://stackoverflow.com/a/65009480/1257434), and im already supplying a different property file for tests. I would really like to provide configuration externally from properties files. – Battlefury May 23 '21 at 12:14
  • Maybe a stupid question, but did you put `spring.cloud.config.enabled: false` in `application.yaml` or `bootstrap.yaml`? – crizzis May 23 '21 at 13:00
  • application.yaml. As can be seen here (https://stackoverflow.com/questions/64994034/bootstrap-yml-configuration-not-processed-anymore-with-spring-cloud-2020-0/65009480#65009480) , bootstrap.yml is deprecated and not used by default. A setting must be set to enable legacy mode. – Battlefury May 23 '21 at 21:03