コード例 #1
0
def test_odd_api_versions():
    """Should serialize and deserialize odd api versions."""
    bundle = kuber.from_file(os.path.join(directory, "odd-resources.yaml"),
                             kubernetes_version="1.18")

    print(bundle.render_yaml_bundle())
    assert len(bundle.resources) == 1
コード例 #2
0
def test_remove():
    """Should return the correct resource type."""
    bundle = kuber.from_file(os.path.join(MY_DIRECTORY, "test-get.yaml"))
    count = len(bundle.resources)
    resource = bundle.resources[1]
    bundle.remove(resource)
    assert len(bundle.resources) == count - 1
    assert resource not in bundle.resources
コード例 #3
0
def test_pop():
    """Should remove the resource from the bundle."""
    bundle = kuber.from_file(os.path.join(MY_DIRECTORY, "test-get.yaml"))
    resource = bundle.resources[1]
    popped_resource = bundle.pop(name=resource.metadata.name,
                                 kind=resource.kind,
                                 **resource.metadata.labels)
    assert resource == popped_resource
コード例 #4
0
def test_array_filtering(scenario: dict):
    """Should filter down to the expected resources."""
    bundle = kuber.from_file(str(RESOURCES_PATH))
    matches = bundle.resources.matching(*scenario["filters"])

    assert scenario["matches"] == {
        f"{m.metadata.namespace}/{m.kind}/{m.metadata.name}"
        for m in matches.to_list()
    }
コード例 #5
0
def test_odd_api_versions():
    """Should serialize and deserialize odd api versions."""
    bundle = kuber.from_file(
        os.path.join(directory, "same-names-different-resources.yaml"),
        kubernetes_version="latest",
    )

    service_account: core_v1.ServiceAccount = bundle.resources.service_account.foo_bar
    assert service_account.kind == "ServiceAccount"
コード例 #6
0
def test_unshift():
    """
    Should place the resource at the beginning fo the resources list.
    """
    bundle = kuber.from_file(os.path.join(MY_DIRECTORY, "test-get.yaml"))
    resource = bundle.resources[1]
    bundle.remove(resource)
    bundle.unshift(resource)
    assert bundle.resources[0] == resource
コード例 #7
0
import kuber

result = kuber.from_yaml_file_multiple("../samples/bundle.yaml")
print(result)

b = kuber.from_file("../samples/bundle.yaml")
print(b.resources)
コード例 #8
0
ファイル: test_get.py プロジェクト: datalayer-externals/kuber
def test_get_deployment():
    """Should return the correct resource type."""
    bundle = kuber.from_file(os.path.join(MY_DIRECTORY, "test-get.yaml"))
    resource = bundle.get(name="foo", kind="Deployment")
    assert resource.kind == "Deployment"
コード例 #9
0
ファイル: test_get.py プロジェクト: datalayer-externals/kuber
def test_get_many():
    """Should return all matching resources"""
    bundle = kuber.from_file(os.path.join(MY_DIRECTORY, "test-get.yaml"))
    resources = bundle.get_many(kind="Job")
    assert len(resources) == 2
    assert set([r.kind for r in resources]) == {"Job"}
コード例 #10
0
ファイル: test_get.py プロジェクト: datalayer-externals/kuber
def test_get_none():
    """Should not find a match that doesn't exist."""
    bundle = kuber.from_file(os.path.join(MY_DIRECTORY, "test-get.yaml"))
    resource = bundle.get(app="baz")
    assert resource is None
コード例 #11
0
ファイル: test_get.py プロジェクト: datalayer-externals/kuber
def test_get_job_label():
    """Should return the correct resource type."""
    bundle = kuber.from_file(os.path.join(MY_DIRECTORY, "test-get.yaml"))
    resource = bundle.get(kind="Job", app="bar")
    assert resource.kind == "Job"
    assert resource.metadata.labels["app"] == "bar"
コード例 #12
0
def test_delete(delete_resource: MagicMock):
    """Should execute delete on bundle resources."""
    bundle = kuber.from_file(os.path.join(MY_DIRECTORY, "test-get.yaml"))
    bundle.delete()
    assert delete_resource.call_count == len(bundle.resources)
コード例 #13
0
def test_statuses(get_resource_status: MagicMock):
    """Should execute statuses on bundle resources."""
    bundle = kuber.from_file(os.path.join(MY_DIRECTORY, "test-get.yaml"))
    bundle.statuses()
    assert get_resource_status.call_count == len(bundle.resources)
コード例 #14
0
def test_zero_replicas_from_file():
    """Should preserve a 0 replicas on a deployment loaded from yaml."""
    path = os.path.realpath(
        os.path.join(os.path.dirname(__file__), "deployment.yaml"))
    bundle = kuber.from_file(path)
    assert "replicas: 0" in bundle.render_yaml_bundle()