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

Defaults returned by resource fails response_contains_resource_model_equal_current_model

Open tayloryork opened this issue 4 years ago • 1 comments

Summary: Sub-properties of properties are not always required. When you use one of the sub-properties the contract tests fails because it expects ALL of the sub-properties to be there.

The short version is that this should pass an "equals" assert

expected = { "top": { "inner1": "1" } }
actual = { "top": { "inner1": "1", "inner2": "2" } }

Details: My Resource has a property NetworkInterfaces which is an array of objects with definition:

    "NetworkInterface": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Description": {
          "type": "string"
        },
        "PrivateIpAddress": {
          "type": "string"
        },
        "PrivateIpAddresses": {
          "type": "array",
          "uniqueItems": false,
          "items": {
            "$ref": "#/definitions/PrivateIpAddressSpecification"
          }
        },
        "SecondaryPrivateIpAddressCount": {
          "type": "integer"
        },
        "DeviceIndex": {
          "type": "string"
        },
        "GroupSet": {
          "type": "array",
          "uniqueItems": false,
          "items": {
            "type": "string"
          }
        },
        "Ipv6Addresses": {
          "type": "array",
          "uniqueItems": false,
          "items": {
            "$ref": "#/definitions/InstanceIpv6Address"
          }
        },
        "SubnetId": {
          "type": "string"
        },
        "AssociatePublicIpAddress": {
          "type": "boolean"
        },
        "NetworkInterfaceId": {
          "type": "string"
        },
        "Ipv6AddressCount": {
          "type": "integer"
        },
        "DeleteOnTermination": {
          "type": "boolean"
        }
      },
      "required": [
        "DeviceIndex"
      ]
    }

Note that only DeviceIndex is required. The ReadHandler will construct this object and fill in the fields. I use the ReadHandler at the end of my CreateHandler.

When I have an input that only specifies some of these fields, such as

{ ...
   "NetworkInteraces" :[
      {
        "DeviceIndex": 0,
        "DeleteOnTermination": false
      } 
   ]
  ...
}

Then the test fails, saying that my input does not match the output. Although it is true that the desiredResource and does not match the output from the Handle, SubnetID is not a required property. It should not matter that SubnetId is not in the desiredResource.

tayloryork avatar Nov 23 '20 19:11 tayloryork

I believe they addressed this issue in: https://github.com/aws-cloudformation/cloudformation-cli/pull/679 and it was released in version 0.2.3.

I had the same issue when running contract tests with 0.2.1, but don't see this issue with 0.2.3.

I believe this issue was originally being tracked in: https://github.com/aws-cloudformation/cloudformation-cli/issues/580

ChoiByungWook avatar Feb 11 '21 19:02 ChoiByungWook