turbo-editors/turbo-moonbitpublic Fork
⑂ main
Commits
⬇ Clone ▾
git clone https://git.rickub.com/turbo-editors/turbo-moonbit.git
git clone ssh://git@rickub.com/turbo-editors/turbo-moonbit.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
📦 Turbo MoonBit ac56478 · on main · k33g · 24d ago
ssh_test.go · 81 lines · 2.5 KBGo Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main

import (
	"errors"
	"flag"
	"io"
	"testing"

	"rickub.com/turbo-editors/turbo-core/fsys"
	"rickub.com/turbo-editors/turbo-core/fsys/fsystest"
	"rickub.com/turbo-editors/turbo-core/remote"
	"rickub.com/turbo-editors/turbo-core/settings"

	"rickub.com/turbo-editors/turbo-moonbit/internal/moonbitlang"
)

// parse reads a command line the way main does, into a flag set of its own.
func parse(t *testing.T, arguments ...string) options {
	t.Helper()
	flags := flag.NewFlagSet("turbo-moonbit", flag.ContinueOnError)
	flags.SetOutput(io.Discard)
	return parseArguments(flags, arguments)
}

func TestTheSSHFlagIsReadWithOneDashOrTwo(t *testing.T) {
	cases := []struct {
		arguments []string
		want      string
	}{
		{[]string{"-ssh", "bob@machine"}, "bob@machine"},
		{[]string{"--ssh", "bob@machine:/srv/app"}, "bob@machine:/srv/app"},
		{[]string{"--ssh=demo:workspace"}, "demo:workspace"},
	}
	for _, c := range cases {
		if got := parse(t, c.arguments...).ssh; got != c.want {
			t.Errorf("%v: ssh = %q, want %q", c.arguments, got, c.want)
		}
	}
}

func TestFilesAfterTheSSHFlagAreStillFiles(t *testing.T) {
	opts := parse(t, "-ssh", "bob@machine", "main.x", "other.x")
	if len(opts.files) != 2 || opts.files[0] != "main.x" {
		t.Errorf("files = %v, want the two named after the flag", opts.files)
	}
}

func TestWithoutSSHTheEditorStaysLocal(t *testing.T) {
	session, err := connectRemote("")
	if session != nil || err != nil {
		t.Errorf("connectRemote(\"\") = %v, %v; want nothing at all", session, err)
	}
	if !fsys.IsLocal() {
		t.Error("the file system is no longer the local disk")
	}
}

func TestABadSSHTargetIsRefusedBeforeAnythingIsStarted(t *testing.T) {
	_, err := connectRemote("-oProxyCommand=evil")
	if !errors.Is(err, remote.ErrBadTarget) {
		t.Errorf("err = %v, want remote.ErrBadTarget", err)
	}
	if !fsys.IsLocal() {
		t.Error("a refused target still switched the file system")
	}
}

// Under -ssh the project is the remote directory: the settings are read
// through fsys, from wherever it points.
func TestProjectSettingsAreReadFromTheCurrentFileSystem(t *testing.T) {
	p := moonbitlang.Profile()
	memory := fsystest.New("/home/bob/project")
	previous := fsys.Use(memory)
	t.Cleanup(func() { fsys.Use(previous) })
	memory.AddFile(settings.Path(p, "/home/bob/project"), "[editor]\ntheme = \"turbo-dark\"\n")

	project, loaded := loadProjectSettings(p)
	if project != "/home/bob/project" || loaded.Theme != "turbo-dark" {
		t.Errorf("loadProjectSettings = %q, %+v; want the remote project and its theme", project, loaded)
	}
}