-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathparser_internal_test.go
62 lines (54 loc) · 2.07 KB
/
parser_internal_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
// Copyright (c) 2016 Pagoda Box Inc
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v.
// 2.0. If a copy of the MPL was not distributed with this file, You can obtain one
// at http://mozilla.org/MPL/2.0/.
//
package lvs
// import (
// "bufio"
// "strings"
// "testing"
// )
// var (
// header = `IP Virtual Server version 1.0.10 (size=4096)
// Prot LocalAddress:Port Scheduler Flags
// -> RemoteAddress:Port Forward Weight ActiveConn InActConn
// `
// cmd = `TCP 212.204.230.98:80 wrr persistent 360
// -> 127.0.0.1:80 Masq 200 25 44
// -> 127.0.0.2:80 Masq 200 12 27
// TCP 212.204.230.98:443 wrr persistent 123
// -> 127.0.0.1:443 Local 100 0 0
// -> 127.0.0.2:443 Local 100 0 0
// `
// )
// func TestEmpty(test *testing.T) {
// reader := strings.NewReader(header)
// scanner := bufio.NewScanner(reader)
// scanner.Split(bufio.ScanWords)
// vips, err := parseAll(scanner)
// assert(test, err == nil, "there was an error %v", err)
// assert(test, len(vips) == 0, "wrong number of vips was returned %v", vips)
// }
// func TestParser(test *testing.T) {
// all := []string{header, cmd}
// reader := strings.NewReader(strings.Join(all, ""))
// scanner := bufio.NewScanner(reader)
// scanner.Split(bufio.ScanWords)
// vips, err := parseAll(scanner)
// if err != nil {
// test.Fatal(err)
// }
// assert(test, len(vips) == 2, "should have 2 vips, only have %v", len(vips))
// assert(test, vips[0].Host == "212.204.230.98", "incorrect host for vip 0: %v", vips[0].Host)
// assert(test, vips[1].Host == "212.204.230.98", "incorrect host for vip 1: %v", vips[1].Host)
// assert(test, len(vips[0].Servers) == 2, "wrong number of servers for vip 0: %v", len(vips[0].Servers))
// assert(test, len(vips[1].Servers) == 2, "wrong number of servers for vip 1: %v", len(vips[1].Servers))
// }
// func assert(test *testing.T, check bool, fmt string, args ...interface{}) {
// if !check {
// test.Logf(fmt, args...)
// test.FailNow()
// }
// }