Search in sources :

Example 16 with StackGresClusterInstalledExtension

use of io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension in project stackgres by ongres.

the class ExtensionsMutatorTest method clusterWithExtensionInstalledAddExtensionWithExtraMounts_shouldReplaceToInstallExtensions.

@Test
void clusterWithExtensionInstalledAddExtensionWithExtraMounts_shouldReplaceToInstallExtensions() throws Exception {
    final StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
    final StackGresClusterExtension extension = getExtension();
    extension.setVersion(installedExtension.getVersion());
    review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(extension));
    review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
    final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
    installedTestExtension.setName("test");
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedTestExtension);
    final StackGresExtensionMetadata extensionMetadata = getExtensionMetadata();
    extensionMetadata.getVersion().setExtraMounts(ImmutableList.of("test"));
    when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(extension))).thenReturn(extensionMetadata);
    final List<JsonPatchOperation> operations = mutator.mutate(review);
    assertEquals(1, operations.size());
    assertEquals(1, operations.stream().filter(o -> o instanceof ReplaceOperation).count());
}
Also used : ReplaceOperation(com.github.fge.jsonpatch.ReplaceOperation) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) StackGresExtensionMetadata(io.stackgres.common.extension.StackGresExtensionMetadata) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) Test(org.junit.jupiter.api.Test)

Example 17 with StackGresClusterInstalledExtension

use of io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension in project stackgres by ongres.

the class ExtensionsMutatorTest method clusterWithMissingExtension_shouldNotDoAnything.

@Test
void clusterWithMissingExtension_shouldNotDoAnything() throws Exception {
    final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
    installedTestExtension.setName("test");
    final StackGresClusterExtension testExtension = getExtension();
    testExtension.setName("test");
    testExtension.setVersion(installedTestExtension.getVersion());
    review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(testExtension));
    review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
    final StackGresExtensionMetadata extensionTestMetadata = getExtensionMetadata();
    extensionTestMetadata.getExtension().setName("test");
    when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(testExtension))).thenThrow(IllegalArgumentException.class);
    final List<JsonPatchOperation> operations = mutator.mutate(review);
    assertEquals(0, operations.size());
}
Also used : StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) StackGresExtensionMetadata(io.stackgres.common.extension.StackGresExtensionMetadata) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) Test(org.junit.jupiter.api.Test)

Example 18 with StackGresClusterInstalledExtension

use of io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension in project stackgres by ongres.

the class ExtensionsMutatorTest method clusterWithExtensionInstalledAddDifferntExtension_shouldReplaceToInstallPostgresExtensions.

@Test
void clusterWithExtensionInstalledAddDifferntExtension_shouldReplaceToInstallPostgresExtensions() throws Exception {
    final StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
    final StackGresClusterExtension extension = getExtension();
    extension.setVersion(installedExtension.getVersion());
    review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(extension));
    review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
    final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
    installedTestExtension.setName("test");
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedTestExtension);
    when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(extension))).thenReturn(getExtensionMetadata());
    final List<JsonPatchOperation> operations = mutator.mutate(review);
    assertEquals(1, operations.size());
    assertEquals(1, operations.stream().filter(o -> o instanceof ReplaceOperation).count());
}
Also used : ReplaceOperation(com.github.fge.jsonpatch.ReplaceOperation) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) Test(org.junit.jupiter.api.Test)

Example 19 with StackGresClusterInstalledExtension

use of io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension in project stackgres by ongres.

the class ExtensionsMutatorTest method clusterWithTwoExtensionInstalledAddDifferntExtension_shouldReplaceToInstallExtensions.

@Test
void clusterWithTwoExtensionInstalledAddDifferntExtension_shouldReplaceToInstallExtensions() throws Exception {
    final StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
    final StackGresClusterExtension extension = getExtension();
    extension.setVersion(installedExtension.getVersion());
    review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(extension));
    review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
    final StackGresClusterInstalledExtension installedTestExtension = getInstalledExtension();
    installedTestExtension.setName("test");
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedTestExtension);
    final StackGresClusterInstalledExtension installedTestExtension2 = getInstalledExtension();
    installedTestExtension2.setName("test2");
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedTestExtension2);
    when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(extension))).thenReturn(getExtensionMetadata());
    final List<JsonPatchOperation> operations = mutator.mutate(review);
    assertEquals(1, operations.size());
    assertEquals(1, operations.stream().filter(o -> o instanceof ReplaceOperation).count());
}
Also used : ReplaceOperation(com.github.fge.jsonpatch.ReplaceOperation) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) Test(org.junit.jupiter.api.Test)

Example 20 with StackGresClusterInstalledExtension

use of io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension in project stackgres by ongres.

the class ExtensionsMutatorTest method clusterWithAnExtensionAlreadyInstalled_shouldNotDoAnything.

@Test
void clusterWithAnExtensionAlreadyInstalled_shouldNotDoAnything() throws Exception {
    final StackGresClusterInstalledExtension installedExtension = getInstalledExtension();
    final StackGresClusterExtension extension = getExtension();
    extension.setVersion(installedExtension.getVersion());
    review.getRequest().getObject().getSpec().getPostgres().setExtensions(ImmutableList.of(extension));
    review.getRequest().getObject().getSpec().setToInstallPostgresExtensions(new ArrayList<>());
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().addAll(defaultExtensions);
    review.getRequest().getObject().getSpec().getToInstallPostgresExtensions().add(installedExtension);
    when(extensionMetadataManager.getExtensionCandidateSameMajorBuild(same(review.getRequest().getObject()), same(extension))).thenReturn(getExtensionMetadata());
    final List<JsonPatchOperation> operations = mutator.mutate(review);
    assertTrue(operations.isEmpty());
}
Also used : StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) StackGresClusterExtension(io.stackgres.common.crd.sgcluster.StackGresClusterExtension) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)52 Test (org.junit.jupiter.api.Test)35 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)24 List (java.util.List)15 Optional (java.util.Optional)15 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)14 ImmutableList (com.google.common.collect.ImmutableList)14 StackGresClusterExtension (io.stackgres.common.crd.sgcluster.StackGresClusterExtension)14 ExtensionInstaller (io.stackgres.common.extension.ExtensionManager.ExtensionInstaller)14 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)13 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)12 StackGresComponent (io.stackgres.common.StackGresComponent)12 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)12 ExtensionUninstaller (io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller)12 ArrayList (java.util.ArrayList)12 ReplaceOperation (com.github.fge.jsonpatch.ReplaceOperation)11 StackGresClusterList (io.stackgres.common.crd.sgcluster.StackGresClusterList)11 JsonUtil (io.stackgres.testutil.JsonUtil)11