Skip to content

Commit

Permalink
Fix connection builder
Browse files Browse the repository at this point in the history
  • Loading branch information
blackshadev committed Dec 20, 2024
1 parent 1892e14 commit b1819b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/Infrastructure/Elastic/ElasticClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ public static function fromConfig(Repository $config): ClientBuilder
);

if (!empty($hostConnectionProperties)) {
$builder->setHosts([$hostConnectionProperties]);
$builder->setHosts([
sprintf(
"%s://%s:%s",
$hostConnectionProperties['scheme'],
$hostConnectionProperties['host'],
$hostConnectionProperties['port']
),
]);
}

if ($config->has('explorer.additionalConnections')) {
Expand Down
23 changes: 12 additions & 11 deletions tests/Unit/ElasticClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class ElasticClientBuilderTest extends MockeryTestCase
private const CLOUD_ID = 'staging:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw';

private const CONNECTION = [ 'host' => 'example.com', 'port' => '9222', 'scheme' => 'https' ];
private const CONNECTION_STRING = 'https://example.com:9222';

/** @dataProvider provideClientConfigs */
public function test_it_creates_client_with_config(array $config, ClientBuilder $expectedBuilder): void
Expand All @@ -39,7 +40,7 @@ public function provideClientConfigs(): ?\Generator
'connection' => self::CONNECTION
],
ClientBuilder::create()
->setHosts([self::CONNECTION])
->setHosts([self::CONNECTION_STRING])
];

yield 'elastic cloud id' => [
Expand All @@ -62,7 +63,7 @@ public function provideClientConfigs(): ?\Generator
], self::CONNECTION)
],
ClientBuilder::create()
->setHosts([self::CONNECTION])
->setHosts([self::CONNECTION_STRING])
->setBasicAuthentication('myName', 'myPassword'),
];

Expand All @@ -76,7 +77,7 @@ public function provideClientConfigs(): ?\Generator
], self::CONNECTION)
],
ClientBuilder::create()
->setHosts([self::CONNECTION])
->setHosts([self::CONNECTION_STRING])
->setApiKey('myId', 'myKey'),
];

Expand All @@ -87,7 +88,7 @@ public function provideClientConfigs(): ?\Generator
], self::CONNECTION)
],
ClientBuilder::create()
->setHosts([self::CONNECTION])
->setHosts([self::CONNECTION_STRING])
->setNodePool(new SimpleNodePool(new RoundRobin(), new ElasticsearchResurrect())),
];

Expand All @@ -110,7 +111,7 @@ public function provideClientConfigs(): ?\Generator
], self::CONNECTION)
],
ClientBuilder::create()
->setHosts([self::CONNECTION])
->setHosts([self::CONNECTION_STRING])
->setSSLVerification(false),
];

Expand All @@ -121,7 +122,7 @@ public function provideClientConfigs(): ?\Generator
], self::CONNECTION)
],
ClientBuilder::create()
->setHosts([self::CONNECTION])
->setHosts([self::CONNECTION_STRING])
->setSSLVerification(),
];

Expand All @@ -135,7 +136,7 @@ public function provideClientConfigs(): ?\Generator
], self::CONNECTION)
],
ClientBuilder::create()
->setHosts([self::CONNECTION])
->setHosts([self::CONNECTION_STRING])
->setSSLCert('path/to/cert.pem', 'passphrase')
->setSSLKey('path/to/key.pem', 'passphrase'),
];
Expand All @@ -150,7 +151,7 @@ public function provideClientConfigs(): ?\Generator
], self::CONNECTION)
],
ClientBuilder::create()
->setHosts([self::CONNECTION])
->setHosts([self::CONNECTION_STRING])
->setSSLCert('path/to/cert.pem')
->setSSLKey('path/to/key.pem'),
];
Expand All @@ -162,7 +163,7 @@ public function provideClientConfigs(): ?\Generator
'connection' => self::CONNECTION,
],
ClientBuilder::create()
->setHosts([self::CONNECTION])
->setHosts([self::CONNECTION_STRING])
->setLogger(new NullLogger()),
];

Expand All @@ -173,7 +174,7 @@ public function provideClientConfigs(): ?\Generator
'connection' => self::CONNECTION,
],
ClientBuilder::create()
->setHosts([self::CONNECTION]),
->setHosts([self::CONNECTION_STRING]),
];

yield 'without logger' => [
Expand All @@ -182,7 +183,7 @@ public function provideClientConfigs(): ?\Generator
'connection' => self::CONNECTION,
],
ClientBuilder::create()
->setHosts([self::CONNECTION]),
->setHosts([self::CONNECTION_STRING]),
];
}

Expand Down

0 comments on commit b1819b6

Please sign in to comment.