Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testing] Add support for mocks #82

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

[testing] Add support for mocks #82

wants to merge 1 commit into from

Conversation

pgavlin
Copy link
Member

@pgavlin pgavlin commented Feb 23, 2022

These changes add simple support for defining mocks alongside a
template.

These changes add simple support for defining mocks alongside a
template.
@pgavlin
Copy link
Member Author

pgavlin commented Feb 23, 2022

@AaronFriel @iwahbe @lukehoban

I wrote this up to do some local testing. I don't think that we want to take it as-is, but I wanted to capture the idea in a PR.

@pgavlin
Copy link
Member Author

pgavlin commented Feb 23, 2022

here's an example of what this looks like in a template:

resources:
  securityGroup:
    type: aws:ec2:SecurityGroup
    properties:
      ingress:
        - protocol: tcp
          fromPort: 0
          toPort: 0
          cidrBlocks:
          - 0.0.0.0/0
  server:
    type: aws:ec2:Instance
    properties:
      tags:
        Name: web-server-www
      instanceType: t2.micro
      securityGroups:
        - ${securityGroup.name}
      ami: ${ami}
      userData: |
        #!/bin/bash
        echo "Hello, World!" > index.html
        nohup python -m SimpleHTTPServer 80 &
variables:
  ami:
    Fn::Invoke:
      Function: aws::getAmi
      Arguments:
        filters:
          - name: name
            values:
            - amzn-ami-hvm-*-x86_64-ebs
        owners:
          - 137112412989
        mostRecent: true
      Return: id
outputs:
  publicIp: ${server.publicIp}
  publicHostName: ${server.publicDns}

mocks:
  resources:
    securityGroup:
      id: securityGroup
      state:
        name: securityGroup
    server:
      id: my-server
      state:
        publicIp: 1.2.3.4
        publicDns: my-server.com
  calls:
    "aws::getAmi":
      return:
        id: some-ami-id

@AaronFriel
Copy link
Member

This would be very useful to put behind an env var and also as a helper method for tests. Very clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants