Exemplo n.º 1
0
 public Task init_docker_only_for_csx_project()
 {
     return(CliTester.Run(new RunConfiguration
     {
         Commands = new[]
         {
             $"init . --worker-runtime dotnet --csx",
             $"init . --docker-only --csx",
         },
         CheckFiles = new[]
         {
             new FileResult
             {
                 Name = "Dockerfile",
                 ContentNotContains = new[] { "dotnet publish" },
                 ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/dotnet:2.0" }
             }
         },
         OutputContains = new[] { "Dockerfile" }
     }, _output));
 }
Exemplo n.º 2
0
        public async Task start_loglevel_overrriden_in_host_json()
        {
            var functionName = "HttpTriggerCSharp";

            await CliTester.Run(new RunConfiguration[]
            {
                new RunConfiguration
                {
                    Commands = new[]
                    {
                        "init . --worker-runtime dotnet",
                        $"new --template Httptrigger --name {functionName}",
                    },
                    Test = async(workingDir, p) =>
                    {
                        var filePath           = Path.Combine(workingDir, "host.json");
                        string hostJsonContent = "{\"version\": \"2.0\",\"logging\": {\"logLevel\": {\"Default\": \"Debug\"}}}";
                        await File.WriteAllTextAsync(filePath, hostJsonContent);
                    },
                },
                new RunConfiguration
                {
                    Commands = new[]
                    {
                        "start"
                    },
                    ExpectExit     = false,
                    OutputContains = new []
                    {
                        "Workers Directory set to"
                    },
                    Test = async(_, p) =>
                    {
                        // give the host time to load functions and print any errors
                        await Task.Delay(TimeSpan.FromSeconds(10));
                        p.Kill();
                    }
                },
            }, _output, startHost : true);
        }
 public async Task start_nodejs_with_inspect()
 {
     await CliTester.Run(new RunConfiguration
     {
         Commands = new[]
         {
             "init . --worker-runtime node",
             "new --template \"Http trigger\" --name HttpTrigger",
             "start --language-worker -- \"--inspect=5050\""
         },
         ExpectExit     = false,
         OutputContains = new[]
         {
             "Debugger listening on ws://127.0.0.1:5050"
         },
         Test = async(_, p) =>
         {
             await Task.Delay(TimeSpan.FromSeconds(15));
             p.Kill();
         },
     }, _output);
 }
Exemplo n.º 4
0
        public Task init_with_worker_runtime(string workerRuntime)
        {
            var files = new List <FileResult>
            {
                new FileResult
                {
                    Name            = "local.settings.json",
                    ContentContains = new []
                    {
                        "FUNCTIONS_WORKER_RUNTIME",
                        workerRuntime
                    }
                },
            };

            if (workerRuntime == "powershell")
            {
                files.Add(new FileResult
                {
                    Name            = "profile.ps1",
                    ContentContains = new[] { "# Azure Functions profile.ps1" }
                });
            }

            return(CliTester.Run(new RunConfiguration
            {
                Commands = new[] { $"init . --worker-runtime {workerRuntime}" },
                CheckFiles = files.ToArray(),
                OutputContains = new[]
                {
                    "Writing .gitignore",
                    "Writing host.json",
                    "Writing local.settings.json",
                    $".vscode{Path.DirectorySeparatorChar}extensions.json",
                },
                OutputDoesntContain = new[] { "Initialized empty Git repository" }
            }, _output));
        }
Exemplo n.º 5
0
 public Task init_python_app_twice()
 {
     return(CliTester.Run(new RunConfiguration
     {
         Commands = new[]
         {
             "init \"anapp\" --worker-runtime python",
             "init \"anapp\" --worker-runtime python"
         },
         OutputContains = new[]
         {
             "Writing .gitignore",
             "Writing host.json",
             "Writing local.settings.json",
             $".vscode{Path.DirectorySeparatorChar}extensions.json",
             "requirements.txt already exists. Skipped!",
             ".gitignore already exists. Skipped!",
             "host.json already exists. Skipped!",
             "local.settings.json already exists. Skipped!",
             $".vscode{Path.DirectorySeparatorChar}extensions.json already exists. Skipped!"
         }
     }, _output));
 }
Exemplo n.º 6
0
 public async Task start_nodejs_loglevel_overrriden_in_settings()
 {
     await CliTester.Run(new RunConfiguration
     {
         Commands = new[]
         {
             "init . --worker-runtime node",
             "settings add AzureFunctionsJobHost__logging__logLevel__Default Debug",
             "new --template \"Http trigger\" --name HttpTrigger",
             "start"
         },
         ExpectExit     = false,
         OutputContains = new[]
         {
             "Worker path for language worker node"
         },
         Test = async(_, p) =>
         {
             await Task.Delay(TimeSpan.FromSeconds(15));
             p.Kill();
         },
     }, _output);
 }
Exemplo n.º 7
0
 public async Task add_setting_plain_text()
 {
     await CliTester.Run(new RunConfiguration
     {
         Commands = new[]
         {
             "init . --worker-runtime node",
             "settings add testKey valueValue"
         },
         CheckFiles = new[]
         {
             new FileResult
             {
                 Name            = "local.settings.json",
                 ContentContains = new[]
                 {
                     "\"IsEncrypted\": false",
                     "\"testKey\": \"valueValue\""
                 }
             }
         }
     }, _output);
 }
 public async Task create_template_function_sanitization_dotnet()
 {
     await CliTester.Run(new RunConfiguration
     {
         Commands = new[]
         {
             "init 12n.ew-file$ --worker-runtime dotnet",
             "new --prefix 12n.ew-file$ --template HttpTrigger --name [email protected]$"
         },
         CheckFiles = new[]
         {
             new FileResult
             {
                 Name            = "12n.ew-file$/_12_n_other_file_.cs",
                 ContentContains = new[]
                 {
                     "namespace _12n.ew_file_",
                     "public static class _12_n_other_file_"
                 }
             }
         }
     }, _output);
 }
Exemplo n.º 9
0
 public Task init_function_app_powershell_supports_managed_dependencies()
 {
     return(CliTester.Run(new RunConfiguration
     {
         Commands = new[] { "init . --worker-runtime powershell --managed-dependencies" },
         CheckFiles = new FileResult[]
         {
             new FileResult
             {
                 Name = "host.json",
                 ContentContains = new []
                 {
                     "managedDependency",
                     "enabled",
                     "true"
                 }
             },
             new FileResult
             {
                 Name = "requirements.psd1",
                 ContentContains = new []
                 {
                     "Az",
                 }
             }
         },
         OutputContains = new[]
         {
             "Writing profile.ps1",
             "Writing requirements.psd1",
             "Writing .gitignore",
             "Writing host.json",
             "Writing local.settings.json",
             $".vscode{Path.DirectorySeparatorChar}extensions.json",
         }
     }, _output));
 }
Exemplo n.º 10
0
 public async Task start_nodejs()
 {
     await CliTester.Run(new RunConfiguration
     {
         Commands = new[]
         {
             "init . --worker-runtime node",
             "new --template \"Http trigger\" --name HttpTrigger",
             "start"
         },
         ExpectExit     = false,
         OutputContains = new[]
         {
             "Functions:",
             "HttpTrigger: [GET,POST] http://localhost:7071/api/HttpTrigger"
         },
         OutputDoesntContain = new string[]
         {
             "Initializing function HTTP routes",
             "Content root path:"     // ASPNETCORE_SUPPRESSSTATUSMESSAGES is set to true by default
         },
         Test = async(workingDir, p) =>
         {
             using (var client = new HttpClient()
             {
                 BaseAddress = new Uri("http://localhost:7071/")
             })
             {
                 (await WaitUntilReady(client)).Should().BeTrue(because: _serverNotReady);
                 var response = await client.GetAsync("/api/HttpTrigger?name=Test");
                 var result   = await response.Content.ReadAsStringAsync();
                 p.Kill();
                 result.Should().Be("Hello, Test. This HTTP triggered function executed successfully.", because: "response from default function should be 'Hello, {name}. This HTTP triggered function executed successfully.'");
             }
         },
     }, _output);
 }
 public Task try_install_with_a_version()
 {
     return(CliTester.Run(new RunConfiguration
     {
         Commands = new[] {
             "init . --worker-runtime node --no-bundle",
             "new --template SendGrid --name testfunc",
             "extensions install",
             "extensions install -p Microsoft.Azure.WebJobs.Extensions.Storage -v 3.0.8"
         },
         OutputContains = new[]
         {
             "Restoring packages for",
             "Restore completed"
         },
         OutputDoesntContain = new[]
         {
             "No action performed because no functions in your app require extensions"
         },
         CheckFiles = new[]
         {
             new FileResult
             {
                 Name = "extensions.csproj",
                 Exists = true,
                 ContentContains = new[]
                 {
                     "Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator",
                     "Microsoft.Azure.WebJobs.Extensions.SendGrid",
                     "Include=\"Microsoft.Azure.WebJobs.Extensions.Storage\" Version=\"3.0.8\""
                 }
             }
         },
         CommandTimeout = TimeSpan.FromMinutes(1)
     }, _output));
 }
Exemplo n.º 12
0
 public Task init_function_app_powershell_enable_managed_dependencies_and_set_default_version()
 {
     return(CliTester.Run(new RunConfiguration
     {
         Commands = new[] { "init . --worker-runtime powershell --managed-dependencies" },
         CheckFiles = new FileResult[]
         {
             new FileResult
             {
                 Name = "host.json",
                 ContentContains = new []
                 {
                     "logging",
                     "applicationInsights",
                     "extensionBundle",
                     "managedDependency",
                     "enabled",
                     "true"
                 }
             },
             new FileResult
             {
                 Name = "requirements.psd1",
                 ContentContains = new []
                 {
                     "Az",
                 }
             },
             new FileResult
             {
                 Name = "profile.ps1",
                 ContentContains = new []
                 {
                     "env:MSI_SECRET",
                     "Disable-AzContextAutosave",
                     "Connect-AzAccount -Identity"
                 }
             },
             new FileResult
             {
                 Name = "local.settings.json",
                 ContentContains = new []
                 {
                     "FUNCTIONS_WORKER_RUNTIME",
                     "powershell",
                     "FUNCTIONS_WORKER_RUNTIME_VERSION",
                     "~6"
                 }
             }
         },
         OutputContains = new[]
         {
             "Writing profile.ps1",
             "Writing requirements.psd1",
             "Writing .gitignore",
             "Writing host.json",
             "Writing local.settings.json",
             $".vscode{Path.DirectorySeparatorChar}extensions.json",
         }
     }, _output));
 }
        public Task pack_python_from_cache()
        {
            var syncDirMessage = "Directory .python_packages already in sync with requirements.txt. Skipping restoring dependencies...";

            return(CliTester.Run(new[] {
                // Create a Python function
                new RunConfiguration
                {
                    Commands = new[]
                    {
                        "init . --worker-runtime python",
                        "new --template \"Httptrigger\" --name httptrigger",
                    },
                    CheckFiles = new FileResult[]
                    {
                        new FileResult
                        {
                            Name = "local.settings.json",
                            ContentContains = new []
                            {
                                "FUNCTIONS_WORKER_RUNTIME",
                                "python"
                            }
                        }
                    },
                    OutputContains = new[]
                    {
                        "Writing .gitignore",
                        "Writing host.json",
                        "Writing local.settings.json"
                    }
                },
                // Make sure pack works
                new RunConfiguration
                {
                    Commands = new[]
                    {
                        "pack",
                    },
                    OutputContains = new[]
                    {
                        "Creating a new package"
                    },
                    CheckFiles = new FileResult[]
                    {
                        new FileResult
                        {
                            Name = Path.Combine(".python_packages", "requirements.txt.md5")
                        }
                    },
                    OutputDoesntContain = new[]
                    {
                        syncDirMessage
                    },
                    CommandTimeout = TimeSpan.FromMinutes(2)
                },
                // Without changing requirements.txt, make sure pack does not restore again
                new RunConfiguration
                {
                    Commands = new[]
                    {
                        "pack",
                    },
                    OutputContains = new[]
                    {
                        "Creating a new package",
                        syncDirMessage
                    },
                    CheckFiles = new FileResult[]
                    {
                        new FileResult
                        {
                            Name = Path.Combine(".python_packages", "requirements.txt.md5")
                        }
                    },
                    CommandTimeout = TimeSpan.FromMinutes(2)
                },
                // Update requirements.txt and make sure pack restores the dependencies
                new RunConfiguration
                {
                    PreTest = (workingDir) =>
                    {
                        var reqTxt = Path.Combine(workingDir, "requirements.txt");
                        _output.WriteLine($"Writing to file {reqTxt}");
                        FileSystemHelpers.WriteAllTextToFile(reqTxt, "requests");
                    },
                    Commands = new[]
                    {
                        "pack",
                    },
                    OutputContains = new[]
                    {
                        "Creating a new package"
                    },
                    CheckFiles = new FileResult[]
                    {
                        new FileResult
                        {
                            Name = Path.Combine(".python_packages", "requirements.txt.md5")
                        }
                    },
                    OutputDoesntContain = new[]
                    {
                        syncDirMessage
                    },
                    CommandTimeout = TimeSpan.FromMinutes(2)
                }
            }, _output));
        }