"""Tests for file type detection."""

from yaml_doctor.analyzers import detect_file_type
from yaml_doctor.models import FileType


class TestDetectFileType:
    def test_github_actions_by_path(self):
        assert detect_file_type("on:\njobs:", ".github/workflows/ci.yml") == FileType.GITHUB_ACTIONS

    def test_github_actions_by_content(self):
        content = "on:\n  push:\njobs:\n  build:\n    runs-on: ubuntu-latest"
        assert detect_file_type(content, "ci.yml") == FileType.GITHUB_ACTIONS

    def test_gitlab_ci_by_path(self):
        assert detect_file_type("stages:\n  - test\ntest:\n  stage: test\n  script:\n    - echo hi", ".gitlab-ci.yml") == FileType.GITLAB_CI

    def test_gitlab_ci_by_content(self):
        content = "stages:\n  - build\nbuild:\n  stage: build\n  script:\n    - make\n  image: python:3.11"
        assert detect_file_type(content, "pipeline.yaml") == FileType.GITLAB_CI

    def test_docker_compose_by_path(self):
        assert detect_file_type("services:\n  web:\n    image: nginx", "docker-compose.yml") == FileType.DOCKER_COMPOSE

    def test_docker_compose_by_content(self):
        content = "version: '3'\nservices:\n  web:\n    image: nginx\nnetworks:\n  default:"
        assert detect_file_type(content, "stack.yaml") == FileType.DOCKER_COMPOSE

    def test_kubernetes_manifest(self):
        content = "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: web"
        assert detect_file_type(content, "deploy.yaml") == FileType.KUBERNETES

    def test_helm_chart(self):
        content = "apiVersion: v2\nname: myapp\nversion: 1.0.0\nappVersion: '1.0'"
        assert detect_file_type(content, "Chart.yaml") == FileType.HELM

    def test_helm_values(self):
        assert detect_file_type("replicaCount: 1", "values.yaml") == FileType.HELM

    def test_generic_yaml(self):
        assert detect_file_type("key: value", "config.yaml") == FileType.GENERIC_YAML

    def test_unknown(self):
        assert detect_file_type("key: value", "config.txt") == FileType.UNKNOWN

    def test_compose_yaml_filename(self):
        assert detect_file_type("services:\n  web:\n    build: .", "compose.yml") == FileType.DOCKER_COMPOSE
