public async void BadJobIdResponse() { var mockHttpHandler = new MockHttpMessageHandler(); var bldr = SumoClient.New(new SumoLib.Config.EndPointConfig("mock", "mock", "https://mock.mk/api")).Builder; var mockRedirectRes = new HttpResponseMessage(HttpStatusCode.Redirect); mockRedirectRes.Headers.Add("Location", "https://mock.mk/api/v1/search/jobs/29323"); mockHttpHandler.When(HttpMethod.Post, "https://mock.mk/api/v1/search/jobs") .Respond(req => mockRedirectRes); mockHttpHandler.When(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323") .Respond(HttpStatusCode.NotFound, new StringContent(MockedResponses.InvalidJobResponse)); using (HttpClientFactory.SetMockClient(mockHttpHandler.ToHttpClient())) { var query = bldr.FromSource("(_sourceCategory=env*/webapp OR _sourceCategory=env*/batch)") .Filter("Authentication") .And("fields uid,fname") .Build(); var sqe = await Assert.ThrowsAsync <SumoQueryException>(() => query.ForLast(TimeSpan.FromDays(1)).RunAsync(new { uid = "", fname = "" })); Assert.Equal("jobid.invalid", sqe.ErrorCode); } }
public void SimpleQueryBuilderTest() { var bldr = SumoClient.New(new SumoLib.Config.EndPointConfig("mock", "mock", "https://mock.mk")).Builder; var query = bldr.FromSource("(_sourceCategory=env*/webapp OR _sourceCategory=env*/batch)") .Filter("Authentication") .And("fields uid,fname") .Build().Text; Assert.Equal(@"(_sourceCategory=env*/webapp OR _sourceCategory=env*/batch) Authentication|fields uid,fname", query); }
public void WhereClauseBuilderTest() { var bldr = SumoClient.New(new SumoLib.Config.EndPointConfig("mock", "mock", "https://mock.mk")).Builder; var query = bldr.FromSource("(_sourceCategory=env*/webapp OR _sourceCategory=env*/batch)") .Filter("Authentication") .Where("ts").Matches("Monday") .And("fields uid,fname") .Build().Text; Assert.Equal(@"(_sourceCategory=env*/webapp OR _sourceCategory=env*/batch) Authentication| where ts matches ""Monday""|fields uid,fname", query); }
public async void ResultsIterationServerErrorTest() { var mockHttpHandler = new MockHttpMessageHandler(); var bldr = SumoClient.New(new SumoLib.Config.EndPointConfig("mock", "mock", "https://mock.mk/api")).Builder; var mockRedirectRes = new HttpResponseMessage(HttpStatusCode.Redirect); mockRedirectRes.Headers.Add("Location", "https://mock.mk/api/v1/search/jobs/29323"); mockHttpHandler.Expect(HttpMethod.Post, "https://mock.mk/api/v1/search/jobs") .Respond(req => mockRedirectRes); mockHttpHandler.Expect(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323") .Respond(HttpStatusCode.OK, JsonContent.Create(new { state = "NOT STARTED" })); mockHttpHandler.Expect(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323") .Respond(HttpStatusCode.OK, JsonContent.Create(new { state = "GATHERING RESULTS" })); mockHttpHandler.Expect(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323") .Respond(HttpStatusCode.OK, JsonContent.Create(new { state = "DONE GATHERING RESULTS", messageCount = 10 })); mockHttpHandler.Expect(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323/messages?offset=0&limit=10") .Respond(HttpStatusCode.InternalServerError); //.Respond(HttpStatusCode.OK, JsonContent.Create(new {messages = Enumerable.Range(0,10).Select(i=>new {map=new {uid=i,fname=$"name_{i}"} }) })); using (HttpClientFactory.SetMockClient(mockHttpHandler.ToHttpClient())) { var query = bldr.FromSource("(_sourceCategory=env*/webapp OR _sourceCategory=env*/batch)") .Filter("Authentication") .And("fields uid,fname") .Build(); var data = await query.ForLast(TimeSpan.FromDays(1)).RunAsync(new { uid = 0, fname = "" }); var sqe = Assert.Throws <SumoQueryException>(() => data.First()); Assert.Equal("500", sqe.ErrorCode); Assert.Equal("500 - InternalServerError", sqe.Message); mockHttpHandler.VerifyNoOutstandingExpectation(); } }
public async void BadURLTest() { var mockHttpHandler = new MockHttpMessageHandler(); var bldr = SumoClient.New(new SumoLib.Config.EndPointConfig("mock", "mock", "https://mock.mk/api")).Builder; mockHttpHandler.When(HttpMethod.Post, "https://mock.mk/api/v1/search/jobs").Throw(new System.IO.IOException("Remote address not reachable.")); using (HttpClientFactory.SetMockClient(mockHttpHandler.ToHttpClient())) { var query = bldr.FromSource("(_sourceCategory=env*/webapp OR _sourceCategory=env*/batch)") .Filter("Authentication") .And("fields uid,fname") .Build(); var sqe = await Assert.ThrowsAsync <SumoQueryException>(() => query.ForLast(TimeSpan.FromDays(1)).RunAsync(new { uid = "", fname = "" })); Assert.Equal("Remote address not reachable.", sqe.InnerException.Message); } }
public async void ErrorMessageTest() { var mockHttpHandler = new MockHttpMessageHandler(); var bldr = SumoClient.New(new SumoLib.Config.EndPointConfig("mock", "mock", "https://mock.mk/api")).Builder; mockHttpHandler.When(HttpMethod.Post, "https://mock.mk/api/v1/search/jobs").Respond(HttpStatusCode.Unauthorized, new StringContent(MockedResponses.NoAuthHeaderResponse)); using (HttpClientFactory.SetMockClient(mockHttpHandler.ToHttpClient())) { var query = bldr.FromSource("(_sourceCategory=env*/webapp OR _sourceCategory=env*/batch)") .Filter("Authentication") .And("fields uid,fname") .Build(); var sqe = await Assert.ThrowsAsync <SumoQueryException>(() => query.ForLast(TimeSpan.FromDays(1)).RunAsync(new { uid = "", fname = "" })); Assert.Contains("Full authentication is required to access this resource", sqe.Message); } }
public async void WaitIterationFailTest() { var mockHttpHandler = new MockHttpMessageHandler(); var bldr = SumoClient.New(new SumoLib.Config.EndPointConfig("mock", "mock", "https://mock.mk/api")).Builder; var mockRedirectRes = new HttpResponseMessage(HttpStatusCode.Redirect); mockRedirectRes.Headers.Add("Location", "https://mock.mk/api/v1/search/jobs/29323"); mockHttpHandler.Expect(HttpMethod.Post, "https://mock.mk/api/v1/search/jobs") .Respond(req => mockRedirectRes); mockHttpHandler.Expect(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323") .Respond(HttpStatusCode.OK, JsonContent.Create(new { state = "NOT STARTED" })); mockHttpHandler.Expect(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323") .Respond(HttpStatusCode.OK, JsonContent.Create(new { state = "GATHERING RESULTS" })); mockHttpHandler.Expect(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323") .Throw(new System.IO.IOException("Read Timeout")); using (HttpClientFactory.SetMockClient(mockHttpHandler.ToHttpClient())) { var query = bldr.FromSource("(_sourceCategory=env*/webapp OR _sourceCategory=env*/batch)") .Filter("Authentication") .And("fields uid,fname") .Build(); var sqe = await Assert.ThrowsAsync <SumoQueryException>(() => query.ForLast(TimeSpan.FromDays(1)).RunAsync(new { uid = "", fname = "" })); mockHttpHandler.VerifyNoOutstandingExpectation(); Assert.IsType <IOException>(sqe.InnerException); Assert.Equal("Read Timeout", sqe.InnerException.Message); } }
public async void WaitIterationTest() { var mockHttpHandler = new MockHttpMessageHandler(); var bldr = SumoClient.New(new SumoLib.Config.EndPointConfig("mock", "mock", "https://mock.mk/api")).Builder; var mockRedirectRes = new HttpResponseMessage(HttpStatusCode.Redirect); mockRedirectRes.Headers.Add("Location", "https://mock.mk/api/v1/search/jobs/29323"); mockHttpHandler.Expect(HttpMethod.Post, "https://mock.mk/api/v1/search/jobs") .Respond(req => mockRedirectRes); mockHttpHandler.Expect(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323") .Respond(HttpStatusCode.OK, JsonContent.Create(new { state = "NOT STARTED" })); mockHttpHandler.Expect(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323") .Respond(HttpStatusCode.OK, JsonContent.Create(new { state = "GATHERING RESULTS" })); mockHttpHandler.Expect(HttpMethod.Get, "https://mock.mk/api/v1/search/jobs/29323") .Respond(HttpStatusCode.OK, JsonContent.Create(new { state = "DONE GATHERING RESULTS", messageCount = 100 })); using (HttpClientFactory.SetMockClient(mockHttpHandler.ToHttpClient())) { var query = bldr.FromSource("(_sourceCategory=env*/webapp OR _sourceCategory=env*/batch)") .Filter("Authentication") .And("fields uid,fname") .Build(); var data = await query.ForLast(TimeSpan.FromDays(1)).RunAsync(new { uid = "", fname = "" }); mockHttpHandler.VerifyNoOutstandingExpectation(); Assert.Equal(100, data.Stats.MessageCount); } }