generated from clevergo/pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbadge_test.go
66 lines (61 loc) · 1.82 KB
/
badge_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2020 CleverGo. All rights reserved.
// Use of this source code is governed by a MIT style license that can be found
// in the LICENSE file.
package shields
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNew(t *testing.T) {
cases := []struct {
label string
message string
}{
{"foo", "bar"},
{"fizz", "buzz"},
}
for _, test := range cases {
badge := New(test.label, test.message)
assert.Equal(t, 1, badge.Version)
assert.Equal(t, test.label, badge.Label)
assert.Equal(t, test.message, badge.Message)
}
}
func TestFromRequest(t *testing.T) {
label := "foo"
message := "bar"
values := url.Values{}
values.Set("schemaVersion", "2") // ignored
values.Set("label", "fizz")
values.Set("labelColor", ColorGreen)
values.Set("message", "buzz") // ignored
values.Set("color", ColorBlue)
values.Set("isError", "1") // ignored
values.Set("namedLogo", "go")
values.Set("logoSvg", "logoSvg")
values.Set("logoColor", "white")
values.Set("logoWidth", "40")
values.Set("logoPosition", "left")
values.Set("style", StylePlastic)
values.Set("cacheSeconds", "500") // ignored
req := httptest.NewRequest(http.MethodGet, "/?"+values.Encode(), nil)
badge := New(label, message)
err := badge.ParseRequest(req)
assert.Nil(t, err)
assert.Equal(t, "fizz", badge.Label)
assert.Equal(t, ColorGreen, badge.LabelColor)
assert.Equal(t, message, badge.Message)
assert.Equal(t, 1, badge.Version)
assert.Equal(t, ColorBlue, badge.Color)
assert.Equal(t, false, badge.IsError)
assert.Equal(t, "go", badge.NamedLogo)
assert.Equal(t, "white", badge.LogoColor)
assert.Equal(t, "40", badge.LogoWidth)
assert.Equal(t, "left", badge.LogoPosition)
assert.Equal(t, "logoSvg", badge.LogoSvg)
assert.Equal(t, StylePlastic, badge.Style)
assert.Equal(t, 0, badge.CacheSeconds)
}