Skip to content

Commit

Permalink
Merge pull request #54 from yaroslavpopovic/patch-collection
Browse files Browse the repository at this point in the history
  • Loading branch information
hkulekci authored Jun 23, 2024
2 parents 0ba31dc + b4983ca commit 9bae9fe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/Endpoints/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ public function info(): Response
);
}

/**
* # Collection exists
* Checks whether the specified collection exists.
*
* @throws InvalidArgumentException
*/
public function exists(): Response
{
return $this->client->execute(
$this->createRequest('GET', '/collections/' . $this->getCollectionName(). '/exists')
);
}

/**
* # Delete collection
* Drop collection and all associated data
Expand Down Expand Up @@ -121,4 +134,4 @@ public function cluster(): Cluster
{
return (new Cluster($this->client))->setCollectionName($this->collectionName);
}
}
}
20 changes: 19 additions & 1 deletion tests/Integration/Endpoints/CollectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ public function testCollections(): void
$this->assertEquals('ok', $response['status']);
}

/**
* @throws InvalidArgumentException
*/
public function testCollectionExits(): void
{
$collections = new Collections($this->client);
$collections->setCollectionName('sample-collection');

$response = $collections->create(self::sampleCollectionOption());
$this->assertEquals('ok', $response['status']);

$response = $collections->exists();
$this->assertEquals(true, $response['result']['exists']);

$response = $collections->setCollectionName('sample-collection-that-not-exists')->exists();
$this->assertEquals(false, $response['result']['exists']);
}

public function testCollectionsCluster(): void
{
$collections = new Collections($this->client);
Expand Down Expand Up @@ -185,4 +203,4 @@ protected function tearDown(): void
$collections->setCollectionName('sample-collection')->delete();
$collections->setCollectionName('other-collection')->delete();
}
}
}

0 comments on commit 9bae9fe

Please sign in to comment.