# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  creationTimestamp: null
  name: metrics
spec:
  steps:
    - name: step-00
      try:
        - apply:
            file: 00-install.yaml
    - name: step-01
      try:
        - apply:
            file: badmetric1.yaml
            expect:
              - check:
                  ($error != null): true
        - apply:
            file: badmetric2.yaml
            expect:
              - check:
                  ($error != null): true
        - apply:
            file: badmetric3.yaml
            expect:
              - check:
                  ($error != null): true
        - apply:
            file: goodmetric.yaml
    - name: step-02
      try:
        - assert:
            file: goodmetric.yaml
        - error:
            file: badmetric1.yaml
        - error:
            file: badmetric2.yaml
        - error:
            file: badmetric3.yaml
    - name: step-03
      try:
        - script:
            # yamllint disable rule:line-length
            content: |
              METRIC_VALUE=$(kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/${NAMESPACE}/keptnmetrics.metrics.sh/podtato-head/podtato-head")
              echo $METRIC_VALUE | jq '.items | length'
            # yamllint enable rule:line-length
            check:
              (contains($stdout, '1')): true
