mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-02 03:33:05 +00:00
tests: use tailcfg.DERPMap
instead of []byte
This commit is contained in:
parent
c726224e53
commit
b6adc84dc6
3 changed files with 36 additions and 20 deletions
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/juanfont/headscale/integration/hsic"
|
"github.com/juanfont/headscale/integration/hsic"
|
||||||
"github.com/juanfont/headscale/integration/integrationutil"
|
"github.com/juanfont/headscale/integration/integrationutil"
|
||||||
"github.com/juanfont/headscale/integration/tsic"
|
"github.com/juanfont/headscale/integration/tsic"
|
||||||
|
"tailscale.com/tailcfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDERPVerifyEndpoint(t *testing.T) {
|
func TestDERPVerifyEndpoint(t *testing.T) {
|
||||||
|
@ -44,25 +45,32 @@ func TestDERPVerifyEndpoint(t *testing.T) {
|
||||||
)
|
)
|
||||||
assertNoErr(t, err)
|
assertNoErr(t, err)
|
||||||
|
|
||||||
derpConfig := "regions:\n"
|
derpMap := tailcfg.DERPMap{
|
||||||
derpConfig += " 900:\n"
|
Regions: map[int]*tailcfg.DERPRegion{
|
||||||
derpConfig += " regionid: 900\n"
|
900: {
|
||||||
derpConfig += " regioncode: test-derpverify\n"
|
RegionID: 900,
|
||||||
derpConfig += " regionname: TestDerpVerify\n"
|
RegionCode: "test-derpverify",
|
||||||
derpConfig += " nodes:\n"
|
RegionName: "TestDerpVerify",
|
||||||
derpConfig += " - name: TestDerpVerify\n"
|
Nodes: []*tailcfg.DERPNode{
|
||||||
derpConfig += " regionid: 900\n"
|
{
|
||||||
derpConfig += " hostname: " + derper.GetHostname() + "\n"
|
Name: "TestDerpVerify",
|
||||||
derpConfig += " stunport: " + derper.GetSTUNPort() + "\n"
|
RegionID: 900,
|
||||||
derpConfig += " stunonly: false\n"
|
HostName: derper.GetHostname(),
|
||||||
derpConfig += " derpport: " + derper.GetDERPPort() + "\n"
|
STUNPort: derper.GetSTUNPort(),
|
||||||
|
STUNOnly: false,
|
||||||
|
DERPPort: derper.GetDERPPort(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
headscale, err := scenario.Headscale(
|
headscale, err := scenario.Headscale(
|
||||||
hsic.WithHostname(hostname),
|
hsic.WithHostname(hostname),
|
||||||
hsic.WithPort(headscalePort),
|
hsic.WithPort(headscalePort),
|
||||||
hsic.WithCustomTLS(certHeadscale, keyHeadscale),
|
hsic.WithCustomTLS(certHeadscale, keyHeadscale),
|
||||||
hsic.WithHostnameAsServerURL(),
|
hsic.WithHostnameAsServerURL(),
|
||||||
hsic.WithCustomDERPServerOnly([]byte(derpConfig)),
|
hsic.WithDERPConfig(derpMap),
|
||||||
)
|
)
|
||||||
assertNoErrHeadscaleEnv(t, err)
|
assertNoErrHeadscaleEnv(t, err)
|
||||||
|
|
||||||
|
|
|
@ -267,18 +267,18 @@ func (t *DERPServerInContainer) GetHostname() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSTUNPort returns the STUN port of the DERPer instance.
|
// GetSTUNPort returns the STUN port of the DERPer instance.
|
||||||
func (t *DERPServerInContainer) GetSTUNPort() string {
|
func (t *DERPServerInContainer) GetSTUNPort() int {
|
||||||
return strconv.Itoa(t.stunPort)
|
return t.stunPort
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDERPPort returns the DERP port of the DERPer instance.
|
// GetDERPPort returns the DERP port of the DERPer instance.
|
||||||
func (t *DERPServerInContainer) GetDERPPort() string {
|
func (t *DERPServerInContainer) GetDERPPort() int {
|
||||||
return strconv.Itoa(t.derpPort)
|
return t.derpPort
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForRunning blocks until the DERPer instance is ready to be used.
|
// WaitForRunning blocks until the DERPer instance is ready to be used.
|
||||||
func (t *DERPServerInContainer) WaitForRunning() error {
|
func (t *DERPServerInContainer) WaitForRunning() error {
|
||||||
url := "https://" + net.JoinHostPort(t.GetHostname(), t.GetDERPPort()) + "/"
|
url := "https://" + net.JoinHostPort(t.GetHostname(), strconv.Itoa(t.GetDERPPort())) + "/"
|
||||||
log.Printf("waiting for DERPer to be ready at %s", url)
|
log.Printf("waiting for DERPer to be ready at %s", url)
|
||||||
|
|
||||||
insecureTransport := http.DefaultTransport.(*http.Transport).Clone() //nolint
|
insecureTransport := http.DefaultTransport.(*http.Transport).Clone() //nolint
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/juanfont/headscale/integration/integrationutil"
|
"github.com/juanfont/headscale/integration/integrationutil"
|
||||||
"github.com/ory/dockertest/v3"
|
"github.com/ory/dockertest/v3"
|
||||||
"github.com/ory/dockertest/v3/docker"
|
"github.com/ory/dockertest/v3/docker"
|
||||||
|
"tailscale.com/tailcfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -216,10 +217,17 @@ func WithEmbeddedDERPServerOnly() Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithCustomDERPServerOnly configures Headscale use a custom
|
// WithDERPConfig configures Headscale use a custom
|
||||||
// DERP server only.
|
// DERP server only.
|
||||||
func WithCustomDERPServerOnly(contents []byte) Option {
|
func WithDERPConfig(derpMap tailcfg.DERPMap) Option {
|
||||||
return func(hsic *HeadscaleInContainer) {
|
return func(hsic *HeadscaleInContainer) {
|
||||||
|
contents, err := json.Marshal(derpMap)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to marshal DERP map: %s", err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
hsic.env["HEADSCALE_DERP_PATHS"] = "/etc/headscale/derp.yml"
|
hsic.env["HEADSCALE_DERP_PATHS"] = "/etc/headscale/derp.yml"
|
||||||
hsic.filesInContainer = append(hsic.filesInContainer,
|
hsic.filesInContainer = append(hsic.filesInContainer,
|
||||||
fileInContainer{
|
fileInContainer{
|
||||||
|
|
Loading…
Reference in a new issue