-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheme_test.go
43 lines (36 loc) · 1.09 KB
/
scheme_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
// SPDX-FileCopyrightText: 2023 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package urlegit
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSchemeOption(t *testing.T) {
tests := []sharedTest{
{
description: "just the scheme",
opt: OnlyAllowSchemes("http", "https"),
noHttp: true,
hosts: []string{"http://example.com", "https://example.com"},
},
{
description: "ftp doesn't match http/s",
opt: OnlyAllowSchemes("ftp"),
noHttp: true,
hosts: []string{"http://example.com", "https://example.com"},
expectedErr: ErrSchemeNotAllowed,
},
{
description: "ftp doesn't match http/s",
noHttp: true,
hosts: []string{"ftp://example.com", "http://example.com", "https://example.com"},
},
}
testCommon(t, tests)
}
func TestSchemeOptionString(t *testing.T) {
opt := OnlyAllowSchemes("http")
assert.Equal(t, "OnlyAllowSchemes('http')", opt.String())
opt = OnlyAllowSchemes("http", "https")
assert.Equal(t, "OnlyAllowSchemes('http', 'https')", opt.String())
}