cloudformation-cli icon indicating copy to clipboard operation
cloudformation-cli copied to clipboard

Contract test compare_model assertion error when integer property is defined as integer literal in input file

Open AgustinBettati opened this issue 5 months ago • 0 comments

Command being run

cfn test --function-name TestEntrypoint --verbose

Version

cfn 0.2.35

Resource type schema

{
  ...
  "definitions": {
    "ApiSearchDeploymentSpec": {
      "type": "object",
      "properties": {
        "InstanceSize": {
          "type": "string"
        },
        "NodeCount": {
          "type": "integer"
        }
      },
      "required": [
        "InstanceSize",
        "NodeCount"
      ],
      "additionalProperties": false
    }
  },
  "properties": { 
    "Specs": {
      "insertionOrder": false,
      "type": "array",
      "items": {
        "$ref": "#/definitions/ApiSearchDeploymentSpec",
        "type": "object"
      },
    }
  },
  ...
}

Contract test input file

{
  ...
  "Specs": [
    {
      "InstanceSize": "S30_HIGHCPU_NVME",
      "NodeCount": 3
    }
  ]
}

Unexpected error output

/opt/homebrew/Cellar/cloudformation-cli/0.2.35_1/libexec/lib/python3.12/site-packages/rpdk/core/contract/resource_client.py:498: in compare_model
raise AssertionError(assertion_error_message) from exception
E   AssertionError: All properties specified in the request MUST be present in the model returned, and they MUST match exactly, with the exception of properties defined as writeOnlyProperties in the resource schema
E    Request Model : {'Profile': 'default', 'ProjectId': '65251446ae5f3f6ec7968b13', 'ClusterName': 'Cluster0', 'Specs': [{'InstanceSize': 'S30_HIGHCPU_NVME', 'NodeCount': 3}]}
E    Returned Model : {'Profile': 'default', 'ClusterName': 'Cluster0', 'ProjectId': '65251446ae5f3f6ec7968b13', 'Specs': [{'InstanceSize': 'S30_HIGHCPU_NVME', 'NodeCount': '3'}]}
E   , inputs: {"Profile": "default", "ProjectId": "65251446ae5f3f6ec7968b13", "ClusterName": "Cluster0", "Specs": [{"InstanceSize": "S30_HIGHCPU_NVME", "NodeCount": 3}]}, outputs: {"Profile": "default", "ClusterName": "Cluster0", "ProjectId": "65251446ae5f3f6ec7968b13", "Specs": [{"InstanceSize": "S30_HIGHCPU_NVME", "NodeCount": "3"}]}

As a workaround, if the input file defines the integer property as a string the compare logic does not fail and contract tests are successful:

{
  ...
  "Specs": [
    {
      "InstanceSize": "S30_HIGHCPU_NVME",
      "NodeCount": "3"
    }
  ]
}

AgustinBettati avatar Mar 11 '24 17:03 AgustinBettati