Example #1
0
        private static (AzFunctionInfo, PowerShellManager) PrepareFunction(string scriptFile, string entryPoint)
        {
            s_functionLoadRequest.Metadata.ScriptFile = scriptFile;
            s_functionLoadRequest.Metadata.EntryPoint = entryPoint;
            s_functionLoadRequest.Metadata.Directory  = Path.GetDirectoryName(scriptFile);

            FunctionLoader.LoadFunction(s_functionLoadRequest);
            var funcInfo  = FunctionLoader.GetFunctionInfo(s_functionLoadRequest.FunctionId);
            var psManager = NewTestPowerShellManager(s_testLogger);

            return(funcInfo, psManager);
        }
Example #2
0
        public void TestFunctionLoaderGetInfo()
        {
            var functionId         = Guid.NewGuid().ToString();
            var directory          = "/Users/tylerleonhardt/Desktop/Tech/PowerShell/AzureFunctions/azure-functions-powershell-worker/examples/PSCoreApp/MyHttpTrigger";
            var scriptPathExpected = $"{directory}/run.ps1";
            var name     = "MyHttpTrigger";
            var metadata = new RpcFunctionMetadata
            {
                Name       = name,
                EntryPoint = "",
                Directory  = directory,
                ScriptFile = scriptPathExpected
            };

            metadata.Bindings.Add("req", new BindingInfo
            {
                Direction = BindingInfo.Types.Direction.In,
                Type      = "httpTrigger"
            });
            metadata.Bindings.Add("res", new BindingInfo
            {
                Direction = BindingInfo.Types.Direction.Out,
                Type      = "http"
            });

            var functionLoadRequest = new FunctionLoadRequest {
                FunctionId = functionId,
                Metadata   = metadata
            };

            var functionLoader = new FunctionLoader();

            functionLoader.Load(functionLoadRequest);

            var funcInfo = functionLoader.GetFunctionInfo(functionId);

            Assert.Equal(directory, funcInfo.Directory);
            Assert.Equal(name, funcInfo.FunctionName);
            Assert.Equal(2, funcInfo.AllBindings.Count);
            Assert.Single(funcInfo.OutputBindings);
        }
Example #3
0
        public void TestFunctionLoaderGetFuncWithRequires()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "FuncWithRequires.ps1");
            var entryPointToUse     = string.Empty;
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            FunctionLoader.LoadFunction(functionLoadRequest);
            var funcInfo = FunctionLoader.GetFunctionInfo(functionLoadRequest.FunctionId);

            Assert.Equal(scriptFileToUse, funcInfo.ScriptPath);
            Assert.Equal(string.Empty, funcInfo.EntryPoint);

            Assert.Null(funcInfo.FuncScriptBlock);

            Assert.Equal(2, funcInfo.FuncParameters.Count);
            Assert.True(funcInfo.FuncParameters.ContainsKey("req"));
            Assert.True(funcInfo.FuncParameters.ContainsKey("inputBlob"));

            Assert.Equal(3, funcInfo.AllBindings.Count);
            Assert.Equal(2, funcInfo.InputBindings.Count);
            Assert.Single(funcInfo.OutputBindings);
        }
        public void TestFunctionLoaderGetFuncWithEntryPoint()
        {
            var functionId         = Guid.NewGuid().ToString();
            var directory          = "/Users/azure/PSCoreApp/MyHttpTrigger";
            var scriptPathExpected = $"{directory}/run.ps1";
            var entryPointExpected = "Foo";
            var metadata           = new RpcFunctionMetadata
            {
                Name       = "MyHttpTrigger",
                EntryPoint = entryPointExpected,
                Directory  = directory,
                ScriptFile = scriptPathExpected
            };

            metadata.Bindings.Add("req", new BindingInfo
            {
                Direction = BindingInfo.Types.Direction.In,
                Type      = "httpTrigger"
            });
            metadata.Bindings.Add("res", new BindingInfo
            {
                Direction = BindingInfo.Types.Direction.Out,
                Type      = "http"
            });

            var functionLoadRequest = new FunctionLoadRequest {
                FunctionId = functionId,
                Metadata   = metadata
            };

            var functionLoader = new FunctionLoader();

            functionLoader.Load(functionLoadRequest);

            var funcInfo = functionLoader.GetFunctionInfo(functionId);

            Assert.Equal(scriptPathExpected, funcInfo.ScriptPath);
            Assert.Equal(entryPointExpected, funcInfo.EntryPoint);
        }
Example #5
0
        public void TestFunctionLoaderGetFunc()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "BasicFuncScript.ps1");
            var entryPointToUse     = string.Empty;
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            var functionLoader = new FunctionLoader();

            functionLoader.LoadFunction(functionLoadRequest);

            var funcInfo = functionLoader.GetFunctionInfo(functionLoadRequest.FunctionId);

            Assert.Equal(scriptFileToUse, funcInfo.ScriptPath);
            Assert.Equal(string.Empty, funcInfo.EntryPoint);

            Assert.Equal(2, funcInfo.FuncParameters.Count);
            Assert.Contains("req", funcInfo.FuncParameters);
            Assert.Contains("inputBlob", funcInfo.FuncParameters);

            Assert.Equal(3, funcInfo.AllBindings.Count);
            Assert.Equal(2, funcInfo.InputBindings.Count);
            Assert.Single(funcInfo.OutputBindings);
        }
        public void TestFunctionLoaderGetFuncWithEntryPoint()
        {
            var scriptFileToUse     = Path.Join(_functionDirectory, "FuncWithEntryPoint.psm1");
            var entryPointToUse     = "Run";
            var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse);

            var functionLoader = new FunctionLoader();

            functionLoader.LoadFunction(functionLoadRequest);

            var funcInfo = functionLoader.GetFunctionInfo(functionLoadRequest.FunctionId);

            Assert.Equal(scriptFileToUse, funcInfo.ScriptPath);
            Assert.Equal(entryPointToUse, funcInfo.EntryPoint);

            Assert.Equal(2, funcInfo.FuncParameters.Count);
            Assert.True(funcInfo.FuncParameters.ContainsKey("req"));
            Assert.True(funcInfo.FuncParameters.ContainsKey("inputBlob"));

            Assert.Equal(3, funcInfo.AllBindings.Count);
            Assert.Equal(2, funcInfo.InputBindings.Count);
            Assert.Single(funcInfo.OutputBindings);
        }