# See https://taskfile.dev/usage/
version: "3"
env:
  TEST_TIMEOUT: 1800
  LONG_TEST_TIMEOUT: 3600
dotenv: [".test.env"]
tasks:
  ### Utility tasks. ###
  default:
    deps: [build, check-license, check-fmt, check-modules, lint, test-short]
  add-license: bash etc/check_license.sh -a
  check-license: bash etc/check_license.sh
  init-submodule: git submodule update --init
  build:
    deps: [install-libmongocrypt]
    cmds:
      - go build ./...
      - go build ${BUILD_TAGS} ./...
      - task: build-tests
      - task: compilecheck-119
  build-tests: go test -short ${BUILD_TAGS} -run ^$$ ./...
  compilecheck-119:
    dir: internal/test/compilecheck
    cmds:
      - go mod download
      - GOTOOLCHAIN=auto go test -v -run '^TestCompileCheck/go:1\.19$'
  build-compile-check-all: bash etc/run-compile-check-test.sh
  build-aws-ecs-test: go test -c ./internal/test/aws -o aws.testbin
  check-fmt:
    deps: [install-lll, install-gofumpt]
    cmds:
      - bash etc/check_fmt.sh
  check-modules: bash etc/check_modules.sh
  doc: godoc -http=:6060 -index
  fmt:
    deps: [install-gofumpt]
    cmds:
      - gofumpt -w .
  api-report: bash etc/api_report.sh
  install-libmongocrypt:
    cmds: [bash etc/install-libmongocrypt.sh]
    status:
      - test -d install || test -d /cygdrive/c/libmongocrypt/bin
  run-docker: bash etc/run_docker.sh
  run-fuzz: bash etc/run-fuzz.sh
  cherry-picker: bash etc/cherry-picker.sh
  pr-task: bash etc/pr-task.sh
  perf-pr-comment: bash etc/perf-pr-comment.sh
  # Lint with various GOOS and GOARCH tasks to catch static analysis failures that may only affect
  # specific operating systems or architectures. For example, staticcheck will only check for 64-bit
  # alignment of atomically accessed variables on 32-bit architectures (see
  # https://staticcheck.io/docs/checks#SA1027)
  lint:
    cmds:
      - GOOS=linux GOARCH=386 etc/golangci-lint.sh
      - GOOS=linux GOARCH=arm etc/golangci-lint.sh
      - GOOS=linux GOARCH=arm64 etc/golangci-lint.sh
      - GOOS=linux GOARCH=amd64 etc/golangci-lint.sh
      - GOOS=linux GOARCH=ppc64le etc/golangci-lint.sh
      - GOOS=linux GOARCH=s390x etc/golangci-lint.sh
  govulncheck: bash etc/govulncheck.sh
  update-notices: bash etc/generate_notices.pl > THIRD-PARTY-NOTICES
  ### Local testing tasks. ###
  test: go test ${BUILD_TAGS} -timeout {{.TEST_TIMEOUT}}s -p 1 ./...
  test-cover:
    - go test ${BUILD_TAGS} -timeout {{.TEST_TIMEOUT}}s -cover ${COVER_ARGS} -p 1 ./...
  test-race:
    - go test ${BUILD_TAGS} -timeout {{.TEST_TIMEOUT}}s -race -p 1 ./...
  test-short: go test ${BUILD_TAGS} -timeout 60s -short -race ./...
  test-oidc: bash etc/run-oidc-test.sh
  test-oidc-remote: bash etc/run-oidc-remote-test.sh
  test-atlas-connect:
    - go test -v -run ^TestAtlas$ go.mongodb.org/mongo-driver/v2/internal/cmd/testatlas -tags atlastest >> test.suite
  test-awskms: bash etc/run-awskms-test.sh
  test-azurekms: bash etc/run-azurekms-test.sh
  test-gcpkms: bash etc/run-gcpkms-test.sh
  test-goleak: bash etc/run-goleak-test.sh
  ### Local FaaS tasks. ###
  build-faas-awslambda:
    requires:
      vars: [MONGODB_URI]
    cmds:
      - make -c internal/cmd/faas/awslambda
  ### Evergreen specific tasks. ###
  setup-test: bash etc/setup-test.sh
  setup-encryption: bash etc/setup-encryption.sh
  evg-test:
    - go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} DYLD_LIBRARY_PATH=$MACOS_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s -p 1 ./... >> test.suite
  evg-test-enterprise-auth:
    - go run -tags gssapi ./internal/cmd/testentauth/main.go
  evg-test-oidc-auth:
    - go test -v ./internal/test/oidcauth/... >> test.suite
    - go test -v -race ./internal/test/oidcauth/... >> test.suite
  evg-test-kmip:
    - go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} DYLD_LIBRARY_PATH=${MACOS_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s ./internal/integration -run TestClientSideEncryptionSpec/kmipKMS >> test.suite
  evg-test-client-side-encryption:
    - go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} DYLD_LIBRARY_PATH=${MACOS_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s ./internal/integration -run TestClientSideEncryptionProse >> test.suite
  evg-test-load-balancers:
    # Load balancer should be tested with all unified tests as well as tests in the following
    # components: retryable reads, retryable writes, change streams, initial DNS seedlist discovery.
    - go test ${BUILD_TAGS} ./internal/integration -run TestInitialDNSSeedlistDiscoverySpec/load_balanced -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
    - go test ${BUILD_TAGS} ./internal/integration -run TestLoadBalancerSupport -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
    - go test ${BUILD_TAGS} ./internal/integration -run TestLoadBalancedConnectionHandshake -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
    - go test ${BUILD_TAGS} ./internal/integration/unified -run TestUnifiedSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
  evg-test-search-index:
    # Use the long timeout to wait for the responses from the server.
    - go test ./internal/integration -run TestSearchIndexProse -v -timeout {{.LONG_TEST_TIMEOUT}}s >> test.suite
  evg-test-ocsp:
    - go test -v ./mongo -run TestOCSP ${OCSP_TLS_SHOULD_SUCCEED} >> test.suite
  evg-test-versioned-api:
    # Versioned API related tests are in the mongo, integration and unified packages.
    - go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} DYLD_LIBRARY_PATH=${MACOS_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s ./mongo >> test.suite
    - go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} DYLD_LIBRARY_PATH=${MACOS_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s ./internal/integration >> test.suite
    - go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} DYLD_LIBRARY_PATH=${MACOS_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s ./internal/integration/unified >> test.suite
  evg-test-aws: bash etc/run-mongodb-aws-test.sh
  evg-test-aws-ecs: bash etc/run-mongodb-aws-ecs-test.sh
  evg-test-deployed-lambda-aws: bash ${DRIVERS_TOOLS}/.evergreen/aws_lambda/run-deployed-lambda-aws-tests.sh
  evg-gather-test-suites: find . -name \*.suite | xargs --no-run-if-empty tar czf test_suite.tgz
  build-kms-test: go build ${BUILD_TAGS} ./internal/cmd/testkms
  ### Benchmark specific tasks and support. ###
  benchmark:
    deps: [perf-files]
    cmds:
      - go test ${BUILD_TAGS} -benchmem -bench=. ./benchmark | test benchmark.suite
  driver-benchmark:
    cmds:
      - go test ./internal/cmd/benchmark -v --fullRun | tee perf.suite
  ### Internal tasks. ###
  install-gofumpt:
    internal: true
    cmds:
      - go install mvdan.cc/gofumpt@v0.9.2
    status:
      - command -v gofumpt
  install-lll:
    internal: true
    cmds:
      - go install github.com/walle/lll/...@latest
