Terraform tests: Can aws_caller_identity.current.arn be mocked?

I am writing unit tests for a module which is expecting data.aws_caller_identity.current.arn in a specific format (for example: arn:aws:iam::000000000000:root/assumed-role/some-role).

Is it possible to mock it?

Currently it returns some random string.

I have tried using override_data or mock_data (see below), but with no luck.

mock_data "aws_caller_identity" {
    defaults = {
      data = {
        current = {
          arn = "arn:aws:iam::123456789012:assume-role/test-user"
        }
      }
    }
  }
override_data {
    target = data.aws_caller_identity.current
    values = {
      arn = "arn:aws:iam::123456789012:assume-role/test-user"
    }
  }

I think you need to adjust the data structure to not include data and `current:

in test.tf:

data "aws_caller_identity" "current" {}

output "account_id" {
  value = data.aws_caller_identity.current.arn
}

in test.tftest.hcl:

mock_provider "aws" {
  mock_data "aws_caller_identity" {
    defaults = {
      arn = "arn:aws:iam::123456789012:assume-role/test-user"
    }
  }
}

run "test" {
  assert {
    condition     = data.aws_caller_identity.current.arn == "arn:aws:iam::123456789012:assume-role/test-user"
    error_message = "Expected ARN not found."
  }
}
% terraform test     
test.tftest.hcl... in progress
  run "test"... pass
test.tftest.hcl... tearing down
test.tftest.hcl... pass

Success! 1 passed, 0 failed.

edit: I also tried this, and it also passed for me (everything else same as above):

mock_provider "aws" {}

override_data {
  target = data.aws_caller_identity.current
  values = {
    arn = "arn:aws:iam::123456789012:assume-role/test-user"
  }
}

Also verified that the test fails if I set the mock value to something else.