suite: addon vpn
templates:
  - common.yaml
release:
  name: test-release-name
  namespace: test-release-namespace
tests:
  - it: addon vpn gluetun enabled with config and env should pass
    set:
      resources:
        limits:
          nvidia.com/gpu: 1

      addons:
        gluetun:
          enabled: true
          secret:
            my-conf:
              basePath: /gluetun/wireguard
              data:
                wg0.conf: |
                  some vpn config
                  with multiple lines
          container:
            env:
              key: value
              key1: value1
              key2: value2
              key3: value3
              FIREWALL: "on"
              FIREWALL_OUTBOUND_SUBNETS: "10.0.0/8, 192.168.0/16"
              FIREWALL_INPUT_PORTS: "8080 , 8443"
      workload: &workload
        main:
          enabled: true
          primary: true
          type: Deployment
          podSpec:
            containers:
              container-1:
                enabled: true
                primary: true
                probes:
                  liveness:
                    enabled: false
                  readiness:
                    enabled: false
                  startup:
                    enabled: false
      service:
        main:
          enabled: true
          primary: false
          ports:
            main:
              enabled: true
              primary: true
              protocol: http
              port: 8089
        service-name1:
          enabled: true
          primary: true
          ports:
            port-1:
              enabled: true
              primary: true
              port: 8080
    asserts:
      - hasDocuments:
          count: 4
      - documentIndex: &SecretDocument 0
        isKind:
          of: Secret
      - documentIndex: &DeploymentDocument 1
        isKind:
          of: Deployment
      - documentIndex: &ServiceDocument 3
        isKind:
          of: Service
      - documentIndex: *SecretDocument
        equal:
          path: metadata.name
          value: test-release-name-common-test-gluetun-my-conf
      - documentIndex: *SecretDocument
        equal:
          path: stringData
          value:
            wg0.conf: |
              some vpn config
              with multiple lines
      - documentIndex: *DeploymentDocument
        equal:
          path: metadata.name
          value: test-release-name-common-test
      - documentIndex: *DeploymentDocument
        equal:
          path: spec.template.spec.containers[0].name
          value: test-release-name-common-test
      - documentIndex: *DeploymentDocument
        isSubset:
          path: spec.template.spec.containers[0]
          content:
            resources:
              limits:
                cpu: 1500m
                memory: 2400Mi
                nvidia.com/gpu: 1
              requests:
                cpu: 75m
                memory: 200Mi
      - documentIndex: *DeploymentDocument
        equal:
          path: spec.template.spec.containers[1].name
          value: test-release-name-common-test-gluetun
      - documentIndex: *DeploymentDocument
        isSubset:
          path: spec.template.spec.containers[1]
          content:
            resources:
              limits:
                cpu: 1500m
                memory: 2400Mi
              requests:
                cpu: 75m
                memory: 200Mi
      - documentIndex: *ServiceDocument
        equal:
          path: metadata.name
          value: test-release-name-common-test
      - documentIndex: *DeploymentDocument
        notContains:
          path: spec.template.spec.containers[0].volumeMounts
          content: &content
            mountPath: /gluetun/wireguard
            name: gluetun-my-conf
            readOnly: false
      - documentIndex: *DeploymentDocument
        notContains:
          path: spec.template.spec.containers[0].env
          content:
            name: key
            value: value
      - documentIndex: *DeploymentDocument
        notContains:
          path: spec.template.spec.containers[0].env
          content:
            name: key1
            value: value1
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.containers[1].env
          content:
            name: key
            value: value
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.containers[1].env
          content:
            name: key1
            value: value1
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.containers[1].env
          content:
            name: key2
            value: value2
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.containers[1].env
          content:
            name: key3
            value: value3
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.containers[1].env
          content:
            name: FIREWALL_OUTBOUND_SUBNETS
            value: 10.0.0/8,192.168.0/16,172.16.0.0/16,172.17.0.0/16
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.containers[1].env
          content:
            name: FIREWALL_INPUT_PORTS
            value: 8080,8443,8089
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.containers[1].volumeMounts
          content: *content
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.volumes
          content:
            name: gluetun-my-conf
            secret:
              items:
                - key: wg0.conf
                  path: wg0.conf
              optional: false
              secretName: test-release-name-common-test-gluetun-my-conf

  - it: addon vpn gluetun enabled with scripts added
    set:
      addons:
        gluetun:
          enabled: true
          secret:
            my-conf:
              basePath: /gluetun/wireguard
              data:
                wg0.conf: |
                  some vpn config
                  with multiple lines
            scripts:
              basePath: /gluetun/scripts
              defaultMode: "0777"
              data:
                up.sh: |
                  echo "up"
                  echo "done"
                down.sh: |
                  echo "down"
                  echo "done"
      workload: *workload
      service:
        main:
          enabled: true
          primary: true
          ports:
            main:
              enabled: true
              primary: true
              port: 8080
    asserts:
      - hasDocuments:
          count: 4
      - documentIndex: &SecretConfDocument 0
        isKind:
          of: Secret
      - documentIndex: *SecretConfDocument
        equal:
          path: metadata.name
          value: test-release-name-common-test-gluetun-my-conf
      - documentIndex: &SecretScriptsDocument 1
        isKind:
          of: Secret
      - documentIndex: *SecretScriptsDocument
        equal:
          path: metadata.name
          value: test-release-name-common-test-gluetun-scripts
      - documentIndex: &DeploymentDocument 2
        isKind:
          of: Deployment
      - documentIndex: &ServiceDocument 3
        isKind:
          of: Service
      - documentIndex: *SecretScriptsDocument
        equal:
          path: stringData
          value:
            up.sh: |
              echo "up"
              echo "done"
            down.sh: |
              echo "down"
              echo "done"
      - documentIndex: *SecretConfDocument
        equal:
          path: stringData
          value:
            wg0.conf: |
              some vpn config
              with multiple lines
      - documentIndex: *DeploymentDocument
        equal:
          path: spec.template.spec.containers[0].name
          value: test-release-name-common-test
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.containers[1].volumeMounts
          content: &content1
            mountPath: /gluetun/wireguard
            name: gluetun-my-conf
            readOnly: false
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.containers[1].volumeMounts
          content: &content2
            mountPath: /gluetun/scripts
            name: gluetun-scripts
            readOnly: false
      - documentIndex: *DeploymentDocument
        notContains:
          path: spec.template.spec.containers[0].volumeMounts
          content: *content1
      - documentIndex: *DeploymentDocument
        notContains:
          path: spec.template.spec.containers[0].volumeMounts
          content: *content2
      - documentIndex: *DeploymentDocument
        equal:
          path: spec.template.spec.containers[1].name
          value: test-release-name-common-test-gluetun
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.volumes
          content:
            name: gluetun-my-conf
            secret:
              items:
                - key: wg0.conf
                  path: wg0.conf
              optional: false
              secretName: test-release-name-common-test-gluetun-my-conf
      - documentIndex: *DeploymentDocument
        contains:
          path: spec.template.spec.volumes
          content:
            name: gluetun-scripts
            secret:
              defaultMode: 511
              items:
                - key: down.sh
                  path: down.sh
                - key: up.sh
                  path: up.sh
              optional: false
              secretName: test-release-name-common-test-gluetun-scripts
