# SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA
# SPDX-License-Identifier: BSD 3-Clause License
import pytest

import kr8s
from kr8s.objects import Pod


async def test_version():
    kubernetes = kr8s.Kr8sApi()
    version = await kubernetes.version()
    assert "major" in version


@pytest.mark.parametrize("namespace", [kr8s.ALL, "kube-system"])
async def test_get_pods(namespace):
    kubernetes = kr8s.Kr8sApi()
    pods = await kubernetes.get("pods", namespace=namespace)
    assert isinstance(pods, list)
    assert len(pods) > 0
    assert isinstance(pods[0], Pod)


async def test_get_deployments():
    kubernetes = kr8s.Kr8sApi()
    deployments = await kubernetes.get("deployments")
    assert isinstance(deployments, list)


async def test_api_resources():
    kubernetes = kr8s.Kr8sApi()
    resources = await kubernetes.api_resources()

    names = [r["name"] for r in resources]
    assert "nodes" in names
    assert "pods" in names
    assert "services" in names
    assert "namespaces" in names

    [pods] = [r for r in resources if r["name"] == "pods"]
    assert pods["namespaced"]
    assert pods["kind"] == "Pod"
    assert pods["version"] == "v1"
    assert "get" in pods["verbs"]

    [deployment] = [d for d in resources if d["name"] == "deployments"]
    assert deployment["namespaced"]
    assert deployment["kind"] == "Deployment"
    assert deployment["version"] == "apps/v1"
    assert "get" in deployment["verbs"]
    assert "deploy" in deployment["shortNames"]
