suite: plugin-geoblock middleware test
templates:
  - common.yaml
release:
  name: test-release-name
  namespace: test-release-namespace
tests:
  - it: should pass with all set
    set:
      ingressMiddlewares:
        traefik:
          my-middleware1:
            enabled: true
            type: plugin-geoblock
            data:
              api: https://api.geoblock.org/v2/geoblock
              allowLocalRequests: true
              logLocalRequests: true
              logAllowedRequests: true
              logApiRequests: true
              apiTimeoutMs: 1000
              cacheSize: 1000
              forceMonthlyUpdate: true
              allowUnknownCountries: true
              unknownCountryApiResponse: some-value
              blackListMode: true
              silentStartUp: true
              addCountryHeader: true
              countries:
                - some-country
                - some-other-country
    asserts:
      - documentIndex: &middlewareDoc 0
        equal:
          path: spec
          value:
            plugin:
              GeoBlock:
                allowLocalRequests: true
                logLocalRequests: true
                logAllowedRequests: true
                logApiRequests: true
                api: https://api.geoblock.org/v2/geoblock
                apiTimeoutMs: 1000
                cacheSize: 1000
                forceMonthlyUpdate: true
                allowUnknownCountries: true
                unknownCountryApiResponse: some-value
                blackListMode: true
                silentStartUp: true
                addCountryHeader: true
                countries:
                  - some-country
                  - some-other-country

  - it: should pass with pluginName set
    set:
      ingressMiddlewares:
        traefik:
          my-middleware1:
            enabled: true
            type: plugin-geoblock
            data:
              pluginName: traefik-geoblock-test
              api: https://api.geoblock.org/v2/geoblock
              countries:
                - some-country
                - some-other-country
    asserts:
      - documentIndex: *middlewareDoc
        equal:
          path: spec
          value:
            plugin:
              traefik-geoblock-test:
                api: https://api.geoblock.org/v2/geoblock
                countries:
                  - some-country
                  - some-other-country

  - it: should fail with missing api
    set:
      ingressMiddlewares:
        traefik:
          my-middleware1:
            enabled: true
            type: plugin-geoblock
            data:
              foo: bar
    asserts:
      - failedTemplate:
          errorMessage: Middleware (plugin-geoblock) - Expected [api] to be set

  - it: should fail with missing countries
    set:
      ingressMiddlewares:
        traefik:
          my-middleware1:
            enabled: true
            type: plugin-geoblock
            data:
              api: https://api.geoblock.org/v2/geoblock
    asserts:
      - failedTemplate:
          errorMessage: Middleware (plugin-geoblock) - Expected [countries] to be set
