From a6e2b33dd0fdae79f5a31a10606d20ba227fe1d5 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Thu, 5 Oct 2017 08:42:19 -0400 Subject: [PATCH] Add a test for limiting security templates returned --- internal/handlers/security_template_test.go | 35 +++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/internal/handlers/security_template_test.go b/internal/handlers/security_template_test.go index a8fb354..14ef459 100644 --- a/internal/handlers/security_template_test.go +++ b/internal/handlers/security_template_test.go @@ -50,18 +50,21 @@ func TestSecurityTemplates(t *testing.T) { var sl handlers.SecurityList response, err := http.Get(server.URL + "/securitytemplate/?search=USD&type=currency") if err != nil { - t.Error(err) + t.Fatal(err) + } + if response.StatusCode != 200 { + t.Fatalf("Unexpected HTTP status code: %d\n", response.StatusCode) } body, err := ioutil.ReadAll(response.Body) response.Body.Close() if err != nil { - t.Error(err) + t.Fatal(err) } err = (&sl).Read(string(body)) if err != nil { - t.Error(err) + t.Fatal(err) } num_usd := 0 @@ -79,3 +82,29 @@ func TestSecurityTemplates(t *testing.T) { t.Fatalf("Expected one USD security template, found %d\n", num_usd) } } + +func TestSecurityTemplateLimit(t *testing.T) { + var sl handlers.SecurityList + response, err := http.Get(server.URL + "/securitytemplate/?search=e&limit=5") + if err != nil { + t.Fatal(err) + } + if response.StatusCode != 200 { + t.Fatalf("Unexpected HTTP status code: %d\n", response.StatusCode) + } + + body, err := ioutil.ReadAll(response.Body) + response.Body.Close() + if err != nil { + t.Fatal(err) + } + + err = (&sl).Read(string(body)) + if err != nil { + t.Fatal(err) + } + + if len(*sl.Securities) > 5 { + t.Fatalf("Requested only 5 securities, received %d\n", len(*sl.Securities)) + } +}