|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +package org.elasticsearch.xpack.inference.services.elastic; |
| 9 | + |
| 10 | +import org.elasticsearch.common.settings.Settings; |
| 11 | +import org.elasticsearch.test.ESTestCase; |
| 12 | + |
| 13 | +import static org.hamcrest.Matchers.equalTo; |
| 14 | + |
| 15 | +public class ElasticInferenceServiceSettingsTests extends ESTestCase { |
| 16 | + |
| 17 | + private static final String ELASTIC_INFERENCE_SERVICE_URL = "http://elastic-inference-service"; |
| 18 | + private static final String ELASTIC_INFERENCE_SERVICE_LEGACY_URL = "http://elastic-inference-service-legacy"; |
| 19 | + |
| 20 | + public void testGetElasticInferenceServiceUrl_WithUrlSetting() { |
| 21 | + var settings = Settings.builder() |
| 22 | + .put(ElasticInferenceServiceSettings.ELASTIC_INFERENCE_SERVICE_URL.getKey(), ELASTIC_INFERENCE_SERVICE_URL) |
| 23 | + .build(); |
| 24 | + |
| 25 | + var eisSettings = new ElasticInferenceServiceSettings(settings); |
| 26 | + |
| 27 | + assertThat(eisSettings.getElasticInferenceServiceUrl(), equalTo(ELASTIC_INFERENCE_SERVICE_URL)); |
| 28 | + } |
| 29 | + |
| 30 | + public void testGetElasticInferenceServiceUrl_WithLegacyUrlSetting() { |
| 31 | + var settings = Settings.builder() |
| 32 | + .put(ElasticInferenceServiceSettings.EIS_GATEWAY_URL.getKey(), ELASTIC_INFERENCE_SERVICE_LEGACY_URL) |
| 33 | + .build(); |
| 34 | + |
| 35 | + var eisSettings = new ElasticInferenceServiceSettings(settings); |
| 36 | + |
| 37 | + assertThat(eisSettings.getElasticInferenceServiceUrl(), equalTo(ELASTIC_INFERENCE_SERVICE_LEGACY_URL)); |
| 38 | + } |
| 39 | + |
| 40 | + public void testGetElasticInferenceServiceUrl_WithUrlSetting_TakesPrecedenceOverLegacyUrlSetting() { |
| 41 | + var settings = Settings.builder() |
| 42 | + .put(ElasticInferenceServiceSettings.EIS_GATEWAY_URL.getKey(), ELASTIC_INFERENCE_SERVICE_LEGACY_URL) |
| 43 | + .put(ElasticInferenceServiceSettings.ELASTIC_INFERENCE_SERVICE_URL.getKey(), ELASTIC_INFERENCE_SERVICE_URL) |
| 44 | + .build(); |
| 45 | + |
| 46 | + var eisSettings = new ElasticInferenceServiceSettings(settings); |
| 47 | + |
| 48 | + assertThat(eisSettings.getElasticInferenceServiceUrl(), equalTo(ELASTIC_INFERENCE_SERVICE_URL)); |
| 49 | + } |
| 50 | + |
| 51 | + public void testGetElasticInferenceServiceUrl_WithoutUrlSetting() { |
| 52 | + var eisSettings = new ElasticInferenceServiceSettings(Settings.EMPTY); |
| 53 | + |
| 54 | + assertThat(eisSettings.getElasticInferenceServiceUrl(), equalTo("")); |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments