public AsyncConfigUnitTests() { Console.WriteLine("AsyncConfigUnitTests Setup ....."); Service = "destination-suite" + TestConfig.RandomString(8); Function = "function-py" + TestConfig.RandomString(8); tf = new TestConfig(); }
public void TestInvokeFunction() { tf.Client.CreateService(new CreateServiceRequest(Service)); string name = "test-csharp-func" + TestConfig.RandomString(8); byte[] contents = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/hello.zip"); var code = new Code(Convert.ToBase64String(contents)); tf.Client.CreateFunction(new CreateFunctionRequest(Service, name, "python3", "index.handler", code, "desc")); byte[] hello = Encoding.UTF8.GetBytes("hello csharp world"); var response = tf.Client.InvokeFunction(new InvokeFunctionRequest(Service, name, null, hello)); Assert.Equal("hello csharp world", response.Content); Assert.Equal(hello, response.Data); var response2 = tf.Client.PublishVersion(new PublishVersionRequest(Service, "C# fc sdk 1")); Assert.Equal(200, response2.StatusCode); var response3 = tf.Client.CreateAlias(new CreateAliasRequest(Service, "staging", response2.Data.VersionId, "alias desc")); Assert.Equal(200, response3.StatusCode); var response4 = tf.Client.InvokeFunction(new InvokeFunctionRequest(Service, name, "staging", hello)); Assert.Equal("hello csharp world", response4.Content); Assert.Equal(hello, response4.Data); var response5 = tf.Client.InvokeFunction(new InvokeFunctionRequest(Service, name, response2.Data.VersionId, hello)); Assert.Equal("hello csharp world", response5.Content); Assert.Equal(hello, response5.Data); }
public TriggerUnitTests() { Console.WriteLine("TriggerUnitTests Setup ....."); Service = "test-csharp-" + TestConfig.RandomString(8); Function = Service; tf = new TestConfig(); }
public void TestFunctionInvoke() { tf.Client.CreateService( new CreateServiceRequest(Service) ); string name = "test-charp-func" + TestConfig.RandomString(8); byte[] contents = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/hello.zip"); var code = new Code(Convert.ToBase64String(contents)); var response = tf.Client.CreateFunction(new CreateFunctionRequest(Service, name, "python3", "index.handler", code, "desc")); Assert.True(200 == response.StatusCode); byte[] hello = Encoding.UTF8.GetBytes("hello csharp world"); var response2 = tf.Client.InvokeFunction(new InvokeFunctionRequest(Service, name, null, hello)); //Console.WriteLine(response2.Content); Assert.Equal("hello csharp world", response2.Content); Assert.Equal(hello, response2.Data); var customHeaders = new Dictionary <string, string> { { "x-fc-invocation-type", "Async" } }; var response3 = tf.Client.InvokeFunction(new InvokeFunctionRequest(Service, name, null, hello, customHeaders)); Assert.Equal(202, response3.StatusCode); }
public void TestFunctionInvokeWithClientTimeout() { Console.WriteLine("test invoke with sleep 120s ....."); tf.Client.CreateService( new CreateServiceRequest(Service) ); string name = "test-csharp-func" + TestConfig.RandomString(8); byte[] contents = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/sleep.zip"); var code = new Code(Convert.ToBase64String(contents)); var response = tf.Client.CreateFunction(new CreateFunctionRequest(Service, name, "python3", "index.handler", code, "desc", 256, 600)); Assert.True(200 == response.StatusCode); // RestClient use HttpWebRequest default Timeout 100s as default timeout when RestClient.Timeout is zero. Console.WriteLine(string.Format("client default timeout {0} ms .....", tf.Client.GetClientTimeout())); byte[] hello = Encoding.UTF8.GetBytes("hello csharp world"); var response2 = tf.Client.InvokeFunction(new InvokeFunctionRequest(Service, name, null, hello)); Console.WriteLine(response.Headers); Assert.True(200 == response2.StatusCode); Assert.True("" != response2.GetRequestID()); tf.Client.SetClientTimeout(3000); // 3 second Console.WriteLine(string.Format("client timeout {0} ms .....", tf.Client.GetClientTimeout())); var response3 = tf.Client.InvokeFunction(new InvokeFunctionRequest(Service, name, null, hello)); Console.WriteLine(string.Format("invoke response statusCode: {0}, content: {1}, data: {2} .....", response3.StatusCode, response3.Content, response3.Data)); Assert.True("" == response3.GetRequestID()); Assert.True(0 == response3.StatusCode); }
public void TestServiceCRUD() { string name = "test-csharp-" + TestConfig.RandomString(8); this.ServiceNames.Add(name); string desc = "create by c# sdk"; CreateServiceResponse response = tf.Client.CreateService( new CreateServiceRequest( name, desc, tf.ServiceRole, tf.LogConfig, true, tf.VpcConfig, tf.NasConfig ) ); Console.WriteLine(response.Content); Console.WriteLine(response.Headers); Assert.Equal(name, response.Data.ServiceName); Assert.Equal(desc, response.Data.Description); Assert.Equal(tf.ServiceRole, response.Data.Role); Assert.True(response.Data.InternetAccess); Assert.Equal(tf.LogConfig, response.Data.LogConfig); Assert.Equal(tf.VpcConfig, response.Data.VpcConfig); Assert.Equal(tf.NasConfig, response.Data.NasConfig); string newDesc = "create by c# sdk new update"; UpdateServiceResponse response2 = tf.Client.UpdateService( new UpdateServiceRequest( name, newDesc) ); Assert.Equal(name, response2.Data.ServiceName); Assert.Equal(newDesc, response2.Data.Description); Assert.Equal(tf.ServiceRole, response2.Data.Role); Assert.True(response2.Data.InternetAccess); Assert.Equal(tf.LogConfig, response2.Data.LogConfig); Assert.Equal(tf.VpcConfig, response2.Data.VpcConfig); Assert.Equal(tf.NasConfig, response2.Data.NasConfig); GetServiceResponse response3 = tf.Client.GetService( new GetServiceRequest(name) ); Assert.Equal(name, response3.Data.ServiceName); Assert.Equal(newDesc, response3.Data.Description); Assert.Equal(tf.ServiceRole, response3.Data.Role); Assert.True(response3.Data.InternetAccess); Assert.Equal(tf.LogConfig, response3.Data.LogConfig); Assert.Equal(tf.VpcConfig, response3.Data.VpcConfig); Assert.Equal(tf.NasConfig, response3.Data.NasConfig); var response4 = tf.Client.DeleteService(new DeleteServiceRequest(name)); this.ServiceNames.Remove(name); Assert.Equal(204, response4.StatusCode); }
public void TestFunctionCRUD() { tf.Client.CreateService(new CreateServiceRequest(Service)); string name = "test-csharp-func" + TestConfig.RandomString(8); byte[] contents = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/hello.zip"); var code = new Code(Convert.ToBase64String(contents)); var response = tf.Client.CreateFunction(new CreateFunctionRequest(Service, name, "python3", "index.handler", code, "desc")); //Console.WriteLine(response.Content); Assert.True(200 == response.StatusCode); Assert.Equal(200, response.StatusCode); Assert.Equal(response.Data.FunctionName, name); Assert.Equal("python3", response.Data.Runtime); Assert.Equal("index.handler", response.Data.Handler); Assert.Equal("desc", response.Data.Description); Assert.True(!string.IsNullOrEmpty(response.Data.FunctionId)); Assert.True(!string.IsNullOrEmpty(response.Data.CodeChecksum)); Assert.True(!string.IsNullOrEmpty(response.Data.CreatedTime)); Assert.True(!string.IsNullOrEmpty(response.Data.LastModifiedTime)); Assert.True(response.Data.CodeSize > 0); Assert.True(response.Data.MemorySize == 256); var response2 = tf.Client.GetFunction(new GetFunctionRequest(Service, name)); Assert.Equal(response.Data.FunctionName, name); Assert.Equal("python3", response.Data.Runtime); Assert.Equal("index.handler", response.Data.Handler); Assert.Equal("desc", response.Data.Description); Assert.True(!string.IsNullOrEmpty(response.Data.FunctionId)); Assert.True(!string.IsNullOrEmpty(response.Data.CodeChecksum)); Assert.True(!string.IsNullOrEmpty(response.Data.CreatedTime)); Assert.True(!string.IsNullOrEmpty(response.Data.LastModifiedTime)); Assert.True(response.Data.CodeSize > 0); Assert.True(response.Data.MemorySize == 256); var resp = tf.Client.GetFunctionCode(new GetFunctionCodeRequest(Service, name)); Assert.False(resp.Data.Url.Contains(@"\u0026")); var response3 = tf.Client.UpdateFunction(new UpdateFunctionRequest(Service, name, "python3", "index.handler", code, "new-desc")); //Console.WriteLine(response3.Content); Assert.Equal("new-desc", response3.Data.Description); var response4 = tf.Client.DeleteFunction(new DeleteFunctionRequest(Service, name)); Assert.Equal(204, response4.StatusCode); }
public TagUnitTests() { Console.WriteLine("TagUnitTests Setup ....."); tf = new TestConfig(); for (int i = 0; i < 3; i++) { string SvrName = "test-csharp-" + TestConfig.RandomString(8); var resp = tf.Client.CreateService(new CreateServiceRequest(SvrName)); Assert.Equal(200, resp.StatusCode); Services.Add(SvrName); } }
public void TestFunctionHttpInvoke() { tf.Client.CreateService( new CreateServiceRequest(Service) ); string name = "test-csharp-func" + TestConfig.RandomString(8); byte[] contents = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/hello.zip"); var code = new Code(Convert.ToBase64String(contents)); var response = tf.Client.CreateFunction(new CreateFunctionRequest(Service, name, "python3", "index.wsgi_echo_handler", code, "desc")); Assert.True(200 == response.StatusCode); tf.Client.CreateTrigger(new CreateTriggerRequest(Service, name, "my-http-trigger", "http", "dummy_arn", "", new HttpTriggerConfig(HttpAuthType.ANONYMOUS, new HttpMethod[] { HttpMethod.GET, HttpMethod.POST }))); byte[] hello = Encoding.UTF8.GetBytes("hello csharp world"); var customHeaders = new Dictionary <string, string> { { "Foo", "Bar" } }; Dictionary <string, string[]> unescapedQueries = new Dictionary <string, string[]> { { "key", new string[] { "value" } }, { "key with space", new string[] { "value with space" } }, }; var response3 = tf.Client.InvokeHttpFunction(new HttpInvokeFunctionRequest(Service, name, "POST", "/action%20with%20space", null, hello, unescapedQueries, customHeaders)); var obj = JsonConvert.DeserializeObject <HttpInvokeResult>(response3.Content); Assert.Equal("POST", obj.Method); Assert.Equal("/action with space", obj.Path); Assert.Equal(202, response3.StatusCode); var response4 = tf.Client.InvokeHttpFunction(new HttpInvokeFunctionRequest(Service, name, "POST", "/action%20with%20space", null, null, null, null)); var obj2 = JsonConvert.DeserializeObject <HttpInvokeResult>(response4.Content); Assert.Equal("POST", obj2.Method); Assert.Equal("/action with space", obj2.Path); Assert.Equal(202, response4.StatusCode); tf.Client.DeleteTrigger(new DeleteTriggerRequest(Service, name, "my-http-trigger")); }
public void TestGetFunction() { tf.Client.CreateService(new CreateServiceRequest(Service)); string name = "test-charp-func" + TestConfig.RandomString(8); byte[] contents = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/hello.zip"); var code = new Code(Convert.ToBase64String(contents)); var response = tf.Client.CreateFunction(new CreateFunctionRequest(Service, name, "python3", "index.handler", code, "desc")); Assert.Equal(200, response.StatusCode); var response2 = tf.Client.PublishVersion(new PublishVersionRequest(Service, "C# fc sdk 1")); Assert.Equal(200, response2.StatusCode); var response3 = tf.Client.CreateAlias(new CreateAliasRequest(Service, "staging", response2.Data.VersionId, "alias desc")); Assert.Equal(200, response3.StatusCode); var response4 = tf.Client.GetFunction(new GetFunctionRequest(Service, name)); Assert.Equal("desc", response4.Data.Description); var response5 = tf.Client.GetFunction(new GetFunctionRequest(Service, name, response2.Data.VersionId)); Assert.Equal("desc", response5.Data.Description); var response6 = tf.Client.GetFunction(new GetFunctionRequest(Service, name, "staging")); Assert.Equal("desc", response6.Data.Description); tf.Client.UpdateFunction(new UpdateFunctionRequest(Service, name, "python3", "index.handler", code, "new-desc")); var response7 = tf.Client.PublishVersion(new PublishVersionRequest(Service, "C# fc sdk 2")); tf.Client.CreateAlias(new CreateAliasRequest(Service, "prod", response7.Data.VersionId, "alias desc 2")); var response8 = tf.Client.GetFunction(new GetFunctionRequest(Service, name, response7.Data.VersionId)); Assert.Equal("new-desc", response8.Data.Description); var response9 = tf.Client.GetFunction(new GetFunctionRequest(Service, name, "prod")); Assert.Equal("new-desc", response9.Data.Description); }
public void TestGetFunction() { tf.Client.CreateService(new CreateServiceRequest(Service)); string name = "test-csharp-func" + TestConfig.RandomString(8); byte[] contents = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/hello.zip"); var code = new Code(Convert.ToBase64String(contents)); var response = tf.Client.CreateFunction(new CreateFunctionRequest(Service, name, "python3", "index.handler", code, "desc")); Assert.Equal(200, response.StatusCode); var response2 = tf.Client.PublishVersion(new PublishVersionRequest(Service, "C# fc sdk 1")); Assert.Equal(200, response2.StatusCode); var response3 = tf.Client.CreateAlias(new CreateAliasRequest(Service, "staging", response2.Data.VersionId, "alias desc")); Assert.Equal(200, response3.StatusCode); var resp1 = tf.Client.PutProvisionConfig(new PutProvisionConfigRequest(Service, "staging", name, 10)); Assert.Equal(200, resp1.StatusCode); Assert.Equal(10, resp1.Data.Target); var resp2 = tf.Client.GetProvisionConfig(new GetProvisionConfigRequest(Service, "staging", name)); Assert.Equal(200, resp2.StatusCode); Assert.Equal(10, resp2.Data.Target); var resp3 = tf.Client.ListProvisionConfigs(new ListProvisionConfigsRequest(Service, "staging")); Assert.Equal(200, resp3.StatusCode); Assert.Equal(1, resp3.Data.ProvisionConfigs.GetLength(0)); Assert.Equal(10, resp3.Data.ProvisionConfigs[0].Target); Assert.True(string.IsNullOrEmpty(resp3.Data.NextToken)); resp1 = tf.Client.PutProvisionConfig(new PutProvisionConfigRequest(Service, "staging", name, 0)); Assert.Equal(200, resp1.StatusCode); Assert.Equal(0, resp1.Data.Target); var response4 = tf.Client.GetFunction(new GetFunctionRequest(Service, name)); Assert.Equal("desc", response4.Data.Description); var response5 = tf.Client.GetFunction(new GetFunctionRequest(Service, name, response2.Data.VersionId)); Assert.Equal("desc", response5.Data.Description); var response6 = tf.Client.GetFunction(new GetFunctionRequest(Service, name, "staging")); Assert.Equal("desc", response6.Data.Description); tf.Client.UpdateFunction(new UpdateFunctionRequest(Service, name, "python3", "index.handler", code, "new-desc")); var response7 = tf.Client.PublishVersion(new PublishVersionRequest(Service, "C# fc sdk 2")); tf.Client.CreateAlias(new CreateAliasRequest(Service, "prod", response7.Data.VersionId, "alias desc 2")); var response8 = tf.Client.GetFunction(new GetFunctionRequest(Service, name, response7.Data.VersionId)); Assert.Equal("new-desc", response8.Data.Description); var response9 = tf.Client.GetFunction(new GetFunctionRequest(Service, name, "prod")); Assert.Equal("new-desc", response9.Data.Description); }
public VersionUnitTests() { Console.WriteLine("VersionUnitTests Setup ....."); Service = "test-csharp-" + TestConfig.RandomString(8); tf = new TestConfig(); }
public void TestListServices() { string prefix = "csharp_test_list_" + TestConfig.RandomString(8); string[] names = { prefix + "abc", prefix + "abd", prefix + "ade", prefix + "bcd", prefix + "bde", prefix + "zzz" }; int i = 0; Dictionary <string, string> tags; foreach (string element in names) { var resp = tf.Client.CreateService(new CreateServiceRequest(element)); Assert.Equal(200, resp.StatusCode); string resArn = String.Format("services/{0}", element); tags = new Dictionary <string, string> { { "k3", "v3" }, { "k1", "v1" }, }; if (i % 2 == 1) { tags = new Dictionary <string, string> { { "k3", "v3" }, { "k2", "v2" }, }; } var tResp = tf.Client.TagResource(new TagResourceRequest(resArn, tags)); Assert.Equal(200, tResp.StatusCode); Assert.NotNull(tResp.GetRequestID()); this.ServiceNames.Add(element); i++; } var response1 = tf.Client.ListServices(new ListServicesRequest(2, prefix + "b")); Assert.Equal(2, response1.Data.Services.GetLength(0)); Assert.Equal(prefix + "bcd", response1.Data.Services[0].ServiceName); Assert.Equal(prefix + "bde", response1.Data.Services[1].ServiceName); var response2 = tf.Client.ListServices(new ListServicesRequest(100, prefix)); Assert.Equal(6, response2.Data.Services.GetLength(0)); tags = new Dictionary <string, string> { { "k3", "v3" }, }; var response = tf.Client.ListServices(new ListServicesRequest(20, prefix + "a", null, null, null, tags)); Assert.Equal(3, response.Data.Services.GetLength(0)); tags = new Dictionary <string, string> { { "k1", "v1" }, }; response = tf.Client.ListServices(new ListServicesRequest(20, prefix + "a", null, null, null, tags)); Assert.Equal(2, response.Data.Services.GetLength(0)); tags = new Dictionary <string, string> { { "k2", "v2" }, }; response = tf.Client.ListServices(new ListServicesRequest(20, prefix + "a", null, null, null, tags)); Assert.Equal(1, response.Data.Services.GetLength(0)); tags = new Dictionary <string, string> { { "k1", "v1" }, { "k2", "v2" }, }; response = tf.Client.ListServices(new ListServicesRequest(20, prefix + "a", null, null, null, tags)); Assert.Equal(0, response.Data.Services.GetLength(0)); }