From e1f8ea2a889494859a61a9259110e40c70002d55 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Fri, 20 Sep 2019 16:46:10 -0400 Subject: Simplify examples --- client/client.go | 4 ---- client/client_test.go | 36 +----------------------------------- 2 files changed, 1 insertion(+), 39 deletions(-) (limited to 'client') diff --git a/client/client.go b/client/client.go index af7c2d8..b68b2be 100644 --- a/client/client.go +++ b/client/client.go @@ -16,9 +16,6 @@ type CaesarClient struct { // Endpoint is the URL to which HTTP requests should be made Endpoint string - // Token is an authorization token to supply to the server - Token string - c *http.Client once sync.Once } @@ -33,7 +30,6 @@ func (c *CaesarClient) EncodeMessage(r io.Reader) (io.Reader, error) { if err != nil { return nil, err } - req.Header.Set("authorization", "token "+c.Token) req.Header.Set("user-agent", "caesar-client/1.0") resp, err := c.c.Do(req) if err != nil { diff --git a/client/client_test.go b/client/client_test.go index 9ccc149..b6af2b9 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -8,40 +8,6 @@ import ( "testing" ) -func TestBadAuth(t *testing.T) { - var hf http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("authorization") != "token TEST-TOKEN" { - w.WriteHeader(http.StatusUnauthorized) - return - } - w.Write([]byte("encoded yay")) - } - tests := []struct { - name string - tok string - expectErr bool - expectBody bool - }{ - {"valid token", "TEST-TOKEN", false, true}, - {"empty token", "", true, false}, - {"invalid token", "bad token", true, false}, - } - server := httptest.NewServer(hf) - defer server.Close() - c := CaesarClient{Endpoint: server.URL} - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - r, err := c.EncodeMessage(strings.NewReader("secret message")) - if err == nil { - t.Errorf("should have gotten error") - } - if r != nil { - t.Errorf("should not have gotten a reader") - } - }) - } -} - func TestEncode(t *testing.T) { var hf http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("response")) @@ -54,7 +20,7 @@ func TestEncode(t *testing.T) { t.Errorf("should not have gotten error: %v", err) } if r == nil { - t.Errorf("should have gotten a reader") + t.Fatalf("should have gotten a reader") } resp, err := ioutil.ReadAll(r) if err != nil { -- cgit v1.2.3