Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
tests: start adding test for oauth package
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Feb 10, 2020
1 parent a9a02f0 commit 8658d14
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions oauth/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package oauth

import (
"encoding/base64"
"io/ioutil"
"net/http/httptest"
"reflect"
"testing"

Expand Down Expand Up @@ -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: "<strong>hello {{ .world }}</strong>",
},
"<strong>hello world</strong>",
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)
}
})
}
}

0 comments on commit 8658d14

Please sign in to comment.