~hduran-8/+junk/caddy

« back to all changes in this revision

Viewing changes to debian/gocode/src/github.com/mholt/caddy/caddy_test.go

  • Committer: Horacio Durán
  • Date: 2017-01-20 16:21:20 UTC
  • Revision ID: horacio.duran@canonical.com-20170120162120-l82mfqwmsclnk838
Upgrade to 0.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package caddy
2
2
 
3
 
import "testing"
 
3
import (
 
4
        "net"
 
5
        "strconv"
 
6
        "testing"
 
7
)
4
8
 
5
9
/*
6
10
// TODO
56
60
                }
57
61
        }
58
62
}
 
63
 
 
64
func TestListenerAddrEqual(t *testing.T) {
 
65
        ln1, err := net.Listen("tcp", "[::]:0")
 
66
        if err != nil {
 
67
                t.Fatal(err)
 
68
        }
 
69
        defer ln1.Close()
 
70
 
 
71
        ln1port := strconv.Itoa(ln1.Addr().(*net.TCPAddr).Port)
 
72
 
 
73
        ln2, err := net.Listen("tcp", "127.0.0.1:0")
 
74
        if err != nil {
 
75
                t.Fatal(err)
 
76
        }
 
77
        defer ln2.Close()
 
78
 
 
79
        ln2port := strconv.Itoa(ln2.Addr().(*net.TCPAddr).Port)
 
80
 
 
81
        for i, test := range []struct {
 
82
                ln     net.Listener
 
83
                addr   string
 
84
                expect bool
 
85
        }{
 
86
                {ln1, ":1234", false},
 
87
                {ln1, "0.0.0.0:1234", false},
 
88
                {ln1, "0.0.0.0", false},
 
89
                {ln1, ":" + ln1port + "", true},
 
90
                {ln1, "0.0.0.0:" + ln1port + "", true},
 
91
                {ln2, ":" + ln2port + "", false},
 
92
                {ln2, "127.0.0.1:1234", false},
 
93
                {ln2, "127.0.0.1", false},
 
94
                {ln2, "127.0.0.1:" + ln2port + "", true},
 
95
        } {
 
96
                if got, want := listenerAddrEqual(test.ln, test.addr), test.expect; got != want {
 
97
                        t.Errorf("Test %d (%s == %s): expected %v but was %v", i, test.addr, test.ln.Addr().String(), want, got)
 
98
                }
 
99
        }
 
100
}