aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/html/urlutil/urls_test.go
blob: a8782c35e34de04dfb344f7f2172506b40475280 (plain)
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
// Copyright 2023 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package urlutil

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestDropParam(t *testing.T) {
	tests := []struct {
		in    string
		key   string
		value string
		out   string
	}{
		{
			in:    `/upstream?first=a&second=b`,
			key:   `first`,
			value: ``,
			out:   `/upstream?second=b`,
		},
		{
			in:    `/upstream?first=a&first=b&second=c`,
			key:   `second`,
			value: ``,
			out:   `/upstream?first=a&first=b`,
		},
		{
			in:    `/upstream?first=a&first=b&second=c`,
			key:   `first`,
			value: ``,
			out:   `/upstream?second=c`,
		},
		{
			in:    `/upstream?first=a&first=b&second=c`,
			key:   `first`,
			value: `b`,
			out:   `/upstream?first=a&second=c`,
		},
	}

	for _, test := range tests {
		got := DropParam(test.in, test.key, test.value)
		assert.Equal(t, test.out, got)
	}
}