Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean: clean up test config and notice writer #248

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x/psiphon/psiphon.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func (d *Dialer) runController(ctx context.Context, pConfig *psi.Config, onTunne
}
}
}))
defer psi.SetNoticeWriter(io.Discard)

err := pConfig.Commit(true)
if err != nil {
Expand Down
37 changes: 25 additions & 12 deletions x/psiphon/psiphon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"io"
"os"
"testing"
"time"

Expand All @@ -28,6 +29,15 @@ import (
"github.com/stretchr/testify/require"
)

func newTestConfig(tb testing.TB, providerConfig string) (*DialerConfig, func()) {
tempDir, err := os.MkdirTemp("", "psiphon")
require.NoError(tb, err)
return &DialerConfig{
DataRootDirectory: tempDir,
ProviderConfig: json.RawMessage(providerConfig),
}, func() { os.RemoveAll(tempDir) }
}

func TestNewPsiphonConfig_ParseCorrectly(t *testing.T) {
config, err := newPsiphonConfig(&DialerConfig{
ProviderConfig: json.RawMessage(`{
Expand Down Expand Up @@ -62,10 +72,11 @@ func TestNewPsiphonConfig_RejectBadOptions(t *testing.T) {

func TestDialer_StartSuccessful(t *testing.T) {
// Create minimal config.
cfg := &DialerConfig{ProviderConfig: json.RawMessage(`{
"PropagationChannelId": "test",
"SponsorId": "test"
}`)}
cfg, delete := newTestConfig(t, `{
"PropagationChannelId": "test",
"SponsorId": "test"
}`)
defer delete()

// Intercept notice writer.
dialer := GetSingletonDialer()
Expand Down Expand Up @@ -100,10 +111,11 @@ func TestDialer_StartSuccessful(t *testing.T) {
}

func TestDialerStart_Cancelled(t *testing.T) {
cfg := &DialerConfig{ProviderConfig: json.RawMessage(`{
"PropagationChannelId": "test",
"SponsorId": "test"
}`)}
cfg, delete := newTestConfig(t, `{
"PropagationChannelId": "test",
"SponsorId": "test"
}`)
defer delete()
errCh := make(chan error)
ctx, cancel := context.WithCancel(context.Background())
go func() {
Expand All @@ -115,10 +127,11 @@ func TestDialerStart_Cancelled(t *testing.T) {
}

func TestDialerStart_Timeout(t *testing.T) {
cfg := &DialerConfig{ProviderConfig: json.RawMessage(`{
"PropagationChannelId": "test",
"SponsorId": "test"
}`)}
cfg, delete := newTestConfig(t, `{
"PropagationChannelId": "test",
"SponsorId": "test"
}`)
defer delete()
errCh := make(chan error)
ctx, cancel := context.WithDeadline(context.Background(), time.Now())
defer cancel()
Expand Down
Loading