Exemple #1
0
        public async Task CreateLayer()
        {
            var logger = new TestToolLogger(_testOutputHelper);

            var command = new PublishLayerCommand(logger, _singleLayerFunctionPath, new string[0]);

            command.Region             = "us-east-1";
            command.TargetFramework    = "netcoreapp2.1";
            command.S3Bucket           = this._testFixture.Bucket;
            command.DisableInteractive = true;
            command.LayerName          = "DotnetTest-CreateLayer";
            command.LayerType          = LambdaConstants.LAYER_TYPE_RUNTIME_PACKAGE_STORE;
            command.PackageManifest    = _singleLayerFunctionPath;

            try
            {
                Assert.True(await command.ExecuteAsync());
                Assert.NotNull(command.NewLayerVersionArn);

                var getResponse = await this._testFixture.LambdaClient.GetLayerVersionAsync(new GetLayerVersionRequest { LayerName = command.NewLayerArn, VersionNumber = command.NewLayerVersionNumber });

                Assert.NotNull(getResponse.Description);


                var data = JsonMapper.ToObject <LayerDescriptionManifest>(getResponse.Description);
                Assert.Equal(LayerDescriptionManifest.ManifestType.RuntimePackageStore, data.Nlt);
                Assert.NotNull(data.Dir);
                Assert.Equal(this._testFixture.Bucket, data.Buc);
                Assert.NotNull(data.Key);


                using (var getManifestResponse = await this._testFixture.S3Client.GetObjectAsync(data.Buc, data.Key))
                    using (var reader = new StreamReader(getManifestResponse.ResponseStream))
                    {
                        var xml = await reader.ReadToEndAsync();

                        Assert.Contains("AWSSDK.S3", xml);
                        Assert.Contains("Amazon.Lambda.Core", xml);
                    }
            }
            finally
            {
                await this._testFixture.LambdaClient.DeleteLayerVersionAsync(new DeleteLayerVersionRequest { LayerName = command.NewLayerArn, VersionNumber = command.NewLayerVersionNumber });
            }
        }
Exemple #2
0
        private async Task <PublishLayerCommand> PublishLayerAsync(string projectDirectory, string optDirectory)
        {
            var logger = new TestToolLogger(_testOutputHelper);

            var publishLayerCommand = new PublishLayerCommand(logger, projectDirectory, new string[0]);

            publishLayerCommand.Region             = "us-east-1";
            publishLayerCommand.TargetFramework    = "netcoreapp2.1";
            publishLayerCommand.S3Bucket           = this._testFixture.Bucket;
            publishLayerCommand.DisableInteractive = true;
            publishLayerCommand.LayerName          = "Dotnet-IntegTest-";
            publishLayerCommand.LayerType          = LambdaConstants.LAYER_TYPE_RUNTIME_PACKAGE_STORE;
            publishLayerCommand.OptDirectory       = optDirectory;
//            publishLayerCommand.PackageManifest = _singleLayerFunctionPath;

            if (!(await publishLayerCommand.ExecuteAsync()))
            {
                throw publishLayerCommand.LastToolsException;
            }

            return(publishLayerCommand);
        }
Exemple #3
0
        // This test behaves different depending on the OS the test is running on which means
        // all code paths are not always being tested. Future work is needed to figure out how to
        // mock the underlying calls to the dotnet CLI.
        public async Task AttemptToCreateAnOptmizedLayer()
        {
            var logger   = new TestToolLogger(_testOutputHelper);
            var assembly = this.GetType().GetTypeInfo().Assembly;

            var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/TestLayerExample");
            var command  = new PublishLayerCommand(logger, fullPath, new string[] { "--enable-package-optimization", "true" });

            command.Region             = "us-east-1";
            command.TargetFramework    = "netcoreapp2.1";
            command.S3Bucket           = this._testFixture.Bucket;
            command.DisableInteractive = true;
            command.LayerName          = "DotnetTest-AttemptToCreateAnOptmizedLayer";
            command.LayerType          = LambdaConstants.LAYER_TYPE_RUNTIME_PACKAGE_STORE;
            command.PackageManifest    = fullPath;

            bool success = false;

            try
            {
                success = await command.ExecuteAsync();

                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Assert.False(success);
                    Assert.Equal(LambdaToolsException.LambdaErrorCode.UnsupportedOptimizationPlatform.ToString(), command.LastToolsException.Code);
                }
                else
                {
                    Assert.True(success);
                    Assert.NotNull(command.NewLayerVersionArn);

                    var getResponse = await this._testFixture.LambdaClient.GetLayerVersionAsync(new GetLayerVersionRequest { LayerName = command.NewLayerArn, VersionNumber = command.NewLayerVersionNumber });

                    Assert.NotNull(getResponse.Description);


                    var data = JsonMapper.ToObject <LayerDescriptionManifest>(getResponse.Description);
                    Assert.Equal(LayerDescriptionManifest.ManifestType.RuntimePackageStore, data.Nlt);
                    Assert.NotNull(data.Dir);
                    Assert.Equal(this._testFixture.Bucket, data.Buc);
                    Assert.NotNull(data.Key);


                    using (var getManifestResponse = await this._testFixture.S3Client.GetObjectAsync(data.Buc, data.Key))
                        using (var reader = new StreamReader(getManifestResponse.ResponseStream))
                        {
                            var xml = await reader.ReadToEndAsync();

                            Assert.Contains("AWSSDK.S3", xml);
                            Assert.Contains("Amazon.Lambda.Core", xml);
                        }
                }
            }
            finally
            {
                if (success)
                {
                    await this._testFixture.LambdaClient.DeleteLayerVersionAsync(new DeleteLayerVersionRequest { LayerName = command.NewLayerArn, VersionNumber = command.NewLayerVersionNumber });
                }
            }
        }