"use strict";
const assert_1 = require("@aws-cdk/assert");
const cdk_1 = require("@aws-cdk/cdk");
const lib_1 = require("../lib");
module.exports = {
    'Bucket with expiration days'(test) {
        // GIVEN
        const stack = new cdk_1.Stack();
        // WHEN
        new lib_1.Bucket(stack, 'Bucket', {
            lifecycleRules: [{
                    expirationInDays: 30
                }]
        });
        // THEN
        assert_1.expect(stack).to(assert_1.haveResource('AWS::S3::Bucket', {
            LifecycleConfiguration: {
                Rules: [{
                        ExpirationInDays: 30,
                        Status: "Enabled"
                    }]
            }
        }));
        test.done();
    },
    'Can use addLifecycleRule() to add a lifecycle rule'(test) {
        // GIVEN
        const stack = new cdk_1.Stack();
        // WHEN
        const bucket = new lib_1.Bucket(stack, 'Bucket');
        bucket.addLifecycleRule({
            expirationInDays: 30
        });
        // THEN
        assert_1.expect(stack).to(assert_1.haveResource('AWS::S3::Bucket', {
            LifecycleConfiguration: {
                Rules: [{
                        ExpirationInDays: 30,
                        Status: "Enabled"
                    }]
            }
        }));
        test.done();
    },
    'Bucket with expiration date'(test) {
        // GIVEN
        const stack = new cdk_1.Stack();
        // WHEN
        new lib_1.Bucket(stack, 'Bucket', {
            lifecycleRules: [{
                    expirationDate: new Date('2018-01-01')
                }]
        });
        // THEN
        assert_1.expect(stack).to(assert_1.haveResource('AWS::S3::Bucket', {
            LifecycleConfiguration: {
                Rules: [{
                        ExpirationDate: '2018-01-01T00:00:00',
                        Status: "Enabled"
                    }]
            }
        }));
        test.done();
    },
    'Bucket with transition rule'(test) {
        // GIVEN
        const stack = new cdk_1.Stack();
        // WHEN
        new lib_1.Bucket(stack, 'Bucket', {
            lifecycleRules: [{
                    transitions: [{
                            storageClass: lib_1.StorageClass.Glacier,
                            transitionInDays: 30
                        }]
                }]
        });
        // THEN
        assert_1.expect(stack).to(assert_1.haveResource('AWS::S3::Bucket', {
            LifecycleConfiguration: {
                Rules: [{
                        Transitions: [{
                                StorageClass: 'GLACIER',
                                TransitionInDays: 30
                            }],
                        Status: "Enabled"
                    }]
            }
        }));
        test.done();
    },
    'Noncurrent rule on nonversioned bucket fails'(test) {
        // GIVEN
        const stack = new cdk_1.Stack();
        // WHEN: Fail because of lack of versioning
        test.throws(() => {
            new lib_1.Bucket(stack, 'Bucket1', {
                lifecycleRules: [{
                        noncurrentVersionExpirationInDays: 10
                    }]
            });
        });
        // WHEN: Succeeds because versioning is enabled
        new lib_1.Bucket(stack, 'Bucket2', {
            versioned: true,
            lifecycleRules: [{
                    noncurrentVersionExpirationInDays: 10
                }]
        });
        test.done();
    },
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5ydWxlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QucnVsZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUF1RDtBQUN2RCxzQ0FBcUM7QUFFckMsZ0NBQThDO0FBRTlDLGlCQUFTO0lBQ0wsNkJBQTZCLENBQUMsSUFBVTtRQUNwQyxRQUFRO1FBQ1IsTUFBTSxLQUFLLEdBQUcsSUFBSSxXQUFLLEVBQUUsQ0FBQztRQUUxQixPQUFPO1FBQ1AsSUFBSSxZQUFNLENBQUMsS0FBSyxFQUFFLFFBQVEsRUFBRTtZQUN4QixjQUFjLEVBQUUsQ0FBQztvQkFDYixnQkFBZ0IsRUFBRSxFQUFFO2lCQUN2QixDQUFDO1NBQ0wsQ0FBQyxDQUFDO1FBRUgsT0FBTztRQUNQLGVBQU0sQ0FBQyxLQUFLLENBQUMsQ0FBQyxFQUFFLENBQUMscUJBQVksQ0FBQyxpQkFBaUIsRUFBRTtZQUM3QyxzQkFBc0IsRUFBRTtnQkFDcEIsS0FBSyxFQUFFLENBQUM7d0JBQ0osZ0JBQWdCLEVBQUUsRUFBRTt3QkFDcEIsTUFBTSxFQUFFLFNBQVM7cUJBQ3BCLENBQUM7YUFDTDtTQUNKLENBQUMsQ0FBQyxDQUFDO1FBRUosSUFBSS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