mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-29 18: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/integrationutil"
|
||||
"github.com/juanfont/headscale/integration/tsic"
|
||||
"tailscale.com/tailcfg"
|
||||
)
|
||||
|
||||
func TestDERPVerifyEndpoint(t *testing.T) {
|
||||
|
@ -44,25 +45,32 @@ func TestDERPVerifyEndpoint(t *testing.T) {
|
|||
)
|
||||
assertNoErr(t, err)
|
||||
|
||||
derpConfig := "regions:\n"
|
||||
derpConfig += " 900:\n"
|
||||
derpConfig += " regionid: 900\n"
|
||||
derpConfig += " regioncode: test-derpverify\n"
|
||||
derpConfig += " regionname: TestDerpVerify\n"
|
||||
derpConfig += " nodes:\n"
|
||||
derpConfig += " - name: TestDerpVerify\n"
|
||||
derpConfig += " regionid: 900\n"
|
||||
derpConfig += " hostname: " + derper.GetHostname() + "\n"
|
||||
derpConfig += " stunport: " + derper.GetSTUNPort() + "\n"
|
||||
derpConfig += " stunonly: false\n"
|
||||
derpConfig += " derpport: " + derper.GetDERPPort() + "\n"
|
||||
derpMap := tailcfg.DERPMap{
|
||||
Regions: map[int]*tailcfg.DERPRegion{
|
||||
900: {
|
||||
RegionID: 900,
|
||||
RegionCode: "test-derpverify",
|
||||
RegionName: "TestDerpVerify",
|
||||
Nodes: []*tailcfg.DERPNode{
|
||||
{
|
||||
Name: "TestDerpVerify",
|
||||
RegionID: 900,
|
||||
HostName: derper.GetHostname(),
|
||||
STUNPort: derper.GetSTUNPort(),
|
||||
STUNOnly: false,
|
||||
DERPPort: derper.GetDERPPort(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
headscale, err := scenario.Headscale(
|
||||
hsic.WithHostname(hostname),
|
||||
hsic.WithPort(headscalePort),
|
||||
hsic.WithCustomTLS(certHeadscale, keyHeadscale),
|
||||
hsic.WithHostnameAsServerURL(),
|
||||
hsic.WithCustomDERPServerOnly([]byte(derpConfig)),
|
||||
hsic.WithDERPConfig(derpMap),
|
||||
)
|
||||
assertNoErrHeadscaleEnv(t, err)
|
||||
|
||||
|
|
|
@ -267,18 +267,18 @@ func (t *DERPServerInContainer) GetHostname() string {
|
|||
}
|
||||
|
||||
// GetSTUNPort returns the STUN port of the DERPer instance.
|
||||
func (t *DERPServerInContainer) GetSTUNPort() string {
|
||||
return strconv.Itoa(t.stunPort)
|
||||
func (t *DERPServerInContainer) GetSTUNPort() int {
|
||||
return t.stunPort
|
||||
}
|
||||
|
||||
// GetDERPPort returns the DERP port of the DERPer instance.
|
||||
func (t *DERPServerInContainer) GetDERPPort() string {
|
||||
return strconv.Itoa(t.derpPort)
|
||||
func (t *DERPServerInContainer) GetDERPPort() int {
|
||||
return t.derpPort
|
||||
}
|
||||
|
||||
// WaitForRunning blocks until the DERPer instance is ready to be used.
|
||||
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)
|
||||
|
||||
insecureTransport := http.DefaultTransport.(*http.Transport).Clone() //nolint
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/juanfont/headscale/integration/integrationutil"
|
||||
"github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3/docker"
|
||||
"tailscale.com/tailcfg"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -216,10 +217,17 @@ func WithEmbeddedDERPServerOnly() Option {
|
|||
}
|
||||
}
|
||||
|
||||
// WithCustomDERPServerOnly configures Headscale use a custom
|
||||
// WithDERPConfig configures Headscale use a custom
|
||||
// DERP server only.
|
||||
func WithCustomDERPServerOnly(contents []byte) Option {
|
||||
func WithDERPConfig(derpMap tailcfg.DERPMap) Option {
|
||||
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.filesInContainer = append(hsic.filesInContainer,
|
||||
fileInContainer{
|
||||
|
|
Loading…
Reference in a new issue