-
Notifications
You must be signed in to change notification settings - Fork 2
/
html_test.go
63 lines (55 loc) · 1.92 KB
/
html_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
package salt
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHtmlParagraph(t *testing.T) {
// This is the slightly simplified HTML response from Salt when a login is rejected.
var bodyHit = `
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<title>401 Unauthorized</title>
</head>
<body>
<h2>401 Unauthorized</h2>
<p>Could not authenticate using provided credentials</p>
<pre id="traceback"></pre>
<div id="powered_by">
<span>
Powered by <a href="http://www.cherrypy.org">CherryPy 18.6.0</a>
</span>
</div>
</body>
</html>
`
var bodyMiss = `
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<title>401 Unauthorized</title>
</head>
<body>
<h2>401 Unauthorized</h2>
<b>Could not authenticate using provided credentials</b>
<pre id="traceback"></pre>
<div id="powered_by">
<span>
Powered by <a href="http://www.cherrypy.org">CherryPy 18.6.0</a>
</span>
</div>
</body>
</html>
`
var bodyInvalid = `invalid html`
var tests = map[string]string{
bodyHit: "Could not authenticate using provided credentials",
bodyMiss: "",
bodyInvalid: "",
}
for body, expect := range tests {
actual := htmlParagraph(strings.NewReader(body))
assert.Equal(t, expect, actual)
}
}