inspektor-gadget

Форк
0
69 строк · 1.5 Кб
1
// Copyright 2019-2021 The Inspektor Gadget authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package tracer
16

17
import (
18
	"testing"
19
)
20

21
func TestParsing(t *testing.T) {
22
	word10 := []byte{9, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}
23
	output10 := "abcdefghi."
24
	word250 := []byte{}
25
	output250 := ""
26
	for i := 0; i < 25; i++ {
27
		word250 = append(word250, word10...)
28
		output250 += output10
29
	}
30

31
	table := []struct {
32
		input  []byte
33
		output string
34
	}{
35
		{
36
			input: []byte{
37
				3, 'w', 'w', 'w',
38
				7, 'k', 'i', 'n', 'v', 'o', 'l', 'k',
39
				2, 'i', 'o',
40
				0,
41
				// trailing garbage is ignored
42
				0x42, 0x42,
43
			},
44
			output: "www.kinvolk.io.",
45
		},
46
		{
47
			input: []byte{
48
				3, 'w', 'w', 'w',
49
				255, // overflow
50
			},
51
			output: "www.",
52
		},
53
		{
54
			input: append(word250,
55
				[]byte{
56
					3, 'z', 'z', 'z',
57
					0,
58
				}...),
59
			output: output250 + "zzz.",
60
		},
61
	}
62

63
	for _, entry := range table {
64
		output := parseLabelSequence(entry.input)
65
		if output != entry.output {
66
			t.Fatalf("Failed to parse DNS string: got %q, expected %q", output, entry.output)
67
		}
68
	}
69
}
70

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.