2021-02-20 06:15:41 +00:00
|
|
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package portmapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateOrGetMapping(t *testing.T) {
|
|
|
|
if v, _ := strconv.ParseBool(os.Getenv("HIT_NETWORK")); !v {
|
|
|
|
t.Skip("skipping test without HIT_NETWORK=1")
|
|
|
|
}
|
2021-07-09 17:01:50 +00:00
|
|
|
c := NewClient(t.Logf, nil)
|
2021-02-20 06:15:41 +00:00
|
|
|
c.SetLocalPort(1234)
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
if i > 0 {
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
2021-07-09 17:01:50 +00:00
|
|
|
ext, err := c.createOrGetMapping(context.Background())
|
2021-02-20 06:15:41 +00:00
|
|
|
t.Logf("Got: %v, %v", ext, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientProbe(t *testing.T) {
|
|
|
|
if v, _ := strconv.ParseBool(os.Getenv("HIT_NETWORK")); !v {
|
|
|
|
t.Skip("skipping test without HIT_NETWORK=1")
|
|
|
|
}
|
2021-07-09 17:01:50 +00:00
|
|
|
c := NewClient(t.Logf, nil)
|
2021-02-20 06:15:41 +00:00
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
if i > 0 {
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
res, err := c.Probe(context.Background())
|
|
|
|
t.Logf("Got: %+v, %v", res, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientProbeThenMap(t *testing.T) {
|
|
|
|
if v, _ := strconv.ParseBool(os.Getenv("HIT_NETWORK")); !v {
|
|
|
|
t.Skip("skipping test without HIT_NETWORK=1")
|
|
|
|
}
|
2021-07-09 17:01:50 +00:00
|
|
|
c := NewClient(t.Logf, nil)
|
2021-02-20 06:15:41 +00:00
|
|
|
c.SetLocalPort(1234)
|
|
|
|
res, err := c.Probe(context.Background())
|
|
|
|
t.Logf("Probe: %+v, %v", res, err)
|
2021-07-09 17:01:50 +00:00
|
|
|
ext, err := c.createOrGetMapping(context.Background())
|
|
|
|
t.Logf("createOrGetMapping: %v, %v", ext, err)
|
2021-02-20 06:15:41 +00:00
|
|
|
}
|