suite: ConfigMap
templates:
  - config.yaml
tests:
  - it: default config
    asserts:
      - isKind:
          of: ConfigMap
      - hasDocuments:
         count: 1
      - equal:
          path: metadata.labels
          value:
            app.kubernetes.io/component: jenkins-controller
            app.kubernetes.io/instance: RELEASE-NAME
            app.kubernetes.io/managed-by: Helm
            app.kubernetes.io/name: jenkins
      - equal:
          path: data.apply_config\.sh
          value: |-
            set -e
            echo "disable Setup Wizard"
            # Prevent Setup Wizard when JCasC is enabled
            echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.UpgradeWizard.state
            echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.InstallUtil.lastExecVersion
            echo "download plugins"
            # Install missing plugins
            cp /var/jenkins_config/plugins.txt /var/jenkins_home;
            rm -rf /usr/share/jenkins/ref/plugins/*.lock
            version () { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
            if [ -f "/usr/share/jenkins/jenkins.war" ] && [ -n "$(command -v jenkins-plugin-cli)" 2>/dev/null ] && [ $(version $(jenkins-plugin-cli --version)) -ge $(version "2.1.1") ]; then
              jenkins-plugin-cli --verbose --war "/usr/share/jenkins/jenkins.war" --plugin-file "/var/jenkins_home/plugins.txt" --latest true;
            else
              /usr/local/bin/install-plugins.sh `echo $(cat /var/jenkins_home/plugins.txt)`;
            fi
            echo "copy plugins to shared volume"
            # Copy plugins to shared volume
            yes n | cp -i /usr/share/jenkins/ref/plugins/* /var/jenkins_plugins/;
            echo "finished initialization"
      - equal:
          path: data.plugins\.txt
          value: |-
            kubernetes:3734.v562b_b_a_627ea_c
            workflow-aggregator:590.v6a_d052e5a_a_b_5
            git:4.13.0
            configuration-as-code:1569.vb_72405b_80249
  - it: no plugins
    set:
      controller.installPlugins: []
    asserts:
      - equal:
          path: data.apply_config\.sh
          value: |-
            set -e
            echo "disable Setup Wizard"
            # Prevent Setup Wizard when JCasC is enabled
            echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.UpgradeWizard.state
            echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.InstallUtil.lastExecVersion
            echo "finished initialization"
      - equal:
          path: data.plugins\.txt
          value: ""
  - it: additional plugins config
    set:
      controller:
        additionalPlugins:
              - kubernetes-credentials-provider
    asserts:
      - equal:
          path: data.plugins\.txt
          value: |-
            kubernetes:3734.v562b_b_a_627ea_c
            workflow-aggregator:590.v6a_d052e5a_a_b_5
            git:4.13.0
            configuration-as-code:1569.vb_72405b_80249
            kubernetes-credentials-provider
  - it: install latest plugins
    set:
      controller.installLatestPlugins: false
    asserts:
      - equal:
          path: data.apply_config\.sh
          value: |-
            set -e
            echo "disable Setup Wizard"
            # Prevent Setup Wizard when JCasC is enabled
            echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.UpgradeWizard.state
            echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.InstallUtil.lastExecVersion
            echo "download plugins"
            # Install missing plugins
            cp /var/jenkins_config/plugins.txt /var/jenkins_home;
            rm -rf /usr/share/jenkins/ref/plugins/*.lock
            version () { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
            if [ -f "/usr/share/jenkins/jenkins.war" ] && [ -n "$(command -v jenkins-plugin-cli)" 2>/dev/null ] && [ $(version $(jenkins-plugin-cli --version)) -ge $(version "2.1.1") ]; then
              jenkins-plugin-cli --verbose --war "/usr/share/jenkins/jenkins.war" --plugin-file "/var/jenkins_home/plugins.txt" --latest false;
            else
              /usr/local/bin/install-plugins.sh `echo $(cat /var/jenkins_home/plugins.txt)`;
            fi
            echo "copy plugins to shared volume"
            # Copy plugins to shared volume
            yes n | cp -i /usr/share/jenkins/ref/plugins/* /var/jenkins_plugins/;
            echo "finished initialization"
  - it: install latest specified plugins
    set:
      controller.installLatestSpecifiedPlugins: true
    asserts:
      - equal:
          path: data.apply_config\.sh
          value: |-
            set -e
            echo "disable Setup Wizard"
            # Prevent Setup Wizard when JCasC is enabled
            echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.UpgradeWizard.state
            echo $JENKINS_VERSION > /var/jenkins_home/jenkins.install.InstallUtil.lastExecVersion
            echo "download plugins"
            # Install missing plugins
            cp /var/jenkins_config/plugins.txt /var/jenkins_home;
            rm -rf /usr/share/jenkins/ref/plugins/*.lock
            version () { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
            if [ -f "/usr/share/jenkins/jenkins.war" ] && [ -n "$(command -v jenkins-plugin-cli)" 2>/dev/null ] && [ $(version $(jenkins-plugin-cli --version)) -ge $(version "2.1.1") ]; then
              jenkins-plugin-cli --verbose --war "/usr/share/jenkins/jenkins.war" --plugin-file "/var/jenkins_home/plugins.txt" --latest true --latest-specified;
            else
              /usr/local/bin/install-plugins.sh `echo $(cat /var/jenkins_home/plugins.txt)`;
            fi
            echo "copy plugins to shared volume"
            # Copy plugins to shared volume
            yes n | cp -i /usr/share/jenkins/ref/plugins/* /var/jenkins_plugins/;
            echo "finished initialization"
