I'm having trouble testing a resource that relies ...
# general
w
I'm having trouble testing a resource that relies on an input. e.g. i have
Copy code
export class BucketPolicy extends aws.s3.BucketPolicy {
    constructor(name: string, bucket: aws.s3.Bucket) {
        const bucketPolicyArgs = {
            bucket: bucket.id,
            policy: "",
        }
        super(name, bucketPolicyArgs);
    }
}
and in my test i have
Copy code
describe("BucketPolicy", function() {
    describe("constructor", function() {
        let testBucket = new infra.Bucket("test");
        let bucketPolicy = new infra.BucketPolicy("test", testBucket);
        it("should attach to the given bucket", function(done) {
            bucketPolicy.bucket.apply(bucketId => {  // this hangs
                if (bucketId == "test") {
                    done()
                } else {
                    done(new Error(`wrong bucket id ${bucketId}`))
                }
            })
        });
the test hangs when it tries to retrieve the bucket output from bucketPolicy
pulumi preview
doesn't seem to have any problem with this when i instantiate BucketPolicy — it's just the test that seems to have trouble resolving the output
w
Interesting. At first, I thought this was due to https://github.com/pulumi/pulumi/pull/2638#issuecomment-483809925 (I'm sure in some form or another it still is). But looking at the actual code, I would have expected this case to work, since you are reading a property that you set in the constructor. Do you see the same if you use
aws.s3.BucketPolicy
instead of creating a subclass of it?
w
i'll try that now
yes, still hangs if i change the test to:
Copy code
describe("constructor", function() {
        let testBucket = new aws.s3.Bucket("test");
        let bucketPolicy = new aws.s3.BucketPolicy("test", {
            bucket: testBucket.id,
            policy: ""
        });
        it("should attach to the given bucket", function(done) {
            bucketPolicy.bucket.apply(bucketId => {
                if (bucketId == "test") {
                    done();
                } else {
                    done(new Error(`wrong bucket id ${bucketId}`))
                }
            })
        });
w
Thanks - we'll have to look deeper - opened https://github.com/pulumi/pulumi/issues/2785.
👍 1
w
thanks
Luke can you recommend a workaround for this? I'm not sure how to test this part of my code.