sparse-intern-71089
06/24/2020, 11:27 PMlittle-cartoon-10569
06/24/2020, 11:27 PMapply on those properties, then I can see the resources in my test context (variables that I populate inside the newResource callback in setMocks). But I can't reliably see those resources in the context if I apply on other things (e.g. RouteTables or NACLs). If there's a way to avoid creating properties just for testing, I'd be interested.white-balloon-205
little-cartoon-10569
06/25/2020, 9:34 PMthis.isolatedNacl = new aws.ec2.NetworkAcl(name, {
      vpcId: this.vpc.id,
      subnetIds: this.vpc.isolatedSubnetIds
    }, this.parentOpts(this));
new aws.ec2.NetworkAclRule(name}, {
      ruleNumber: 200,
      ruleAction: "allow", protocol: "-1",
      networkAclId: this.isolatedNacl.id,
      cidrBlock: this.publicSubnet.subnet.cidrBlock
    }, opts);
The NACL rule isn't interesting to my app, it just needs to be created.
In the test for my ComponentResource, I want to ensure that the CIDR block of my isolatedNacl's only rule is  the same as the CIDR block of the public subnet. I have a this.publicSubnet.subnet.cidrBlock that I can apply on, all good. But I don't have anything to apply to get the rule's CIDR block. So, I was trying to use the stub code in my Mocha test to get it.
let isolatedRuleCidrBlock: CidrBlock; // This is within my outermost "describe" function
    pulumi.runtime.setMocks({
      newResource: function (type: string, name: string, inputs: any): { id: string, state: any } {
        let state = { name: name, ...inputs };
        if (type == 'aws:ec2/networkAclRule:NetworkAclRule') { isolatedRuleCidrBlock = state; } // Remember the rule for later
        return {
          id: `${name}_id`,
          state: state,
        };
      },
      call: (token: string, args: any, provider?: string) => {
        switch (token) {
          case "aws:index/getAvailabilityZones:getAvailabilityZones":
            return {
              names: ["ap-southeast-2a", "ap-southeast-2b"],
              zoneIds: ["southeast2a", "southeast2b"],
            };
        }
        return args;
      },
    });
Then my test can be something like:
it('should allow access to the isolated subnets from the public subnet', async function check_isolated_public_access() {
      pulumi.output(objectUnderTest.publicSubnet.subnet.cidrBlock).apply((subnetCidr)) => {
        expect(subnetCidir).to.eql(isolatedRuleCidrBlock);
      }little-cartoon-10569
06/25/2020, 9:41 PMpulumi.all() at the same time as my subnet CIDR block). This is working, but it's more app code than I need...little-cartoon-10569
06/25/2020, 9:44 PMnewResource function, but it's not there at the right time: my test can't see it. The Pulumi engine creates it correctly, my test is just running too soon because it hasn't run apply on the right thing.