From 8658d14e097151f9dbb69b27b5b5c5170457f425 Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Mon, 10 Feb 2020 22:36:07 +0300 Subject: [PATCH] tests: start adding test for oauth package --- oauth/oauth_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/oauth/oauth_test.go b/oauth/oauth_test.go index bff2ccb..5f19eba 100644 --- a/oauth/oauth_test.go +++ b/oauth/oauth_test.go @@ -3,6 +3,8 @@ package oauth import ( "encoding/base64" + "io/ioutil" + "net/http/httptest" "reflect" "testing" @@ -103,3 +105,52 @@ func Test_getGoogleOAuthConfig(t *testing.T) { }) } } + +func Test_writeHTMLOutput(t *testing.T) { + type args struct { + data interface{} + html string + } + tests := []struct { + name string + args args + wantW string + wantErr bool + }{ + { + "Simple String Test", + args{ + data: map[string]string{ + "world": "world", + }, + html: "hello {{ .world }}", + }, + "hello world", + false, + }, + { + "HTML String Test", + args{ + data: map[string]string{ + "world": "world", + }, + html: "hello {{ .world }}", + }, + "hello world", + false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + w := httptest.NewRecorder() + if err := writeHTMLOutput(w, tt.args.data, tt.args.html); (err != nil) != tt.wantErr { + t.Errorf("writeHTMLOutput() error = %v, wantErr %v", err, tt.wantErr) + return + } + body, _ := ioutil.ReadAll(w.Body) + if gotW := string(body); gotW != tt.wantW { + t.Errorf("writeHTMLOutput() = %v, want %v", gotW, tt.wantW) + } + }) + } +}