mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
* Add templates
* Move API structs to codersdk
* Back to green tests!
* It all works, but now with tea! 🧋
* It works!
* Add cancellation to provisionerd
* Tests pass!
* Add deletion of workspaces and projects
* Fix agent lock
* Add clog
* Fix linting errors
* Remove unused CLI tests
* Rename daemon to start
* Fix leaking command
* Fix promptui test
* Update agent connection frequency
* Skip login tests on Windows
* Increase tunnel connect timeout
* Fix templater
* Lower test requirements
* Fix embed
* Disable promptui tests for Windows
* Fix write newline
* Fix PTY write newline
* Fix CloseReader
* Fix compilation on Windows
* Fix linting error
* Remove bubbletea
* Cleanup readwriter
* Use embedded templates instead of serving over API
* Move templates to examples
* Improve workspace create flow
* Fix Windows build
* Fix tests
* Fix linting errors
* Fix untar with extracting max size
* Fix newline char
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package tunnel_test
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/coderd/tunnel"
|
|
)
|
|
|
|
// The tunnel leaks a few goroutines that aren't impactful to production scenarios.
|
|
// func TestMain(m *testing.M) {
|
|
// goleak.VerifyTestMain(m)
|
|
// }
|
|
|
|
func TestTunnel(t *testing.T) {
|
|
t.Parallel()
|
|
if testing.Short() {
|
|
t.Skip()
|
|
return
|
|
}
|
|
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
defer cancelFunc()
|
|
url, _, err := tunnel.New(ctx, srv.URL)
|
|
require.NoError(t, err)
|
|
t.Log(url)
|
|
|
|
require.Eventually(t, func() bool {
|
|
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
|
require.NoError(t, err)
|
|
res, err := http.DefaultClient.Do(req)
|
|
var dnsErr *net.DNSError
|
|
// The name might take a bit to resolve!
|
|
if xerrors.As(err, &dnsErr) {
|
|
return false
|
|
}
|
|
require.NoError(t, err)
|
|
defer res.Body.Close()
|
|
return res.StatusCode == http.StatusOK
|
|
}, 5*time.Minute, 3*time.Second)
|
|
}
|