~hristoast/wem

wem/exe/main_test.go -rw-r--r-- 1.0 KiB
e4496baaHristos N. Triantafillou Changelog for the DNS flag 14 days ago
                                                                                
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
package exe_test

import (
	"fmt"
	"os"
	"path/filepath"
	"testing"

	"git.sr.ht/~hristoast/wem/exe"
)

func TestExe(t *testing.T) {
	// Setup
	dir := t.TempDir()
	os.Setenv("HOME", dir)
	stuffDir := filepath.Join(os.Getenv("HOME"), "stuff")
	thingsDir := filepath.Join(stuffDir, "things")
	dirDir := filepath.Join(stuffDir, "dir")

	os.MkdirAll(thingsDir, 0755)
	os.MkdirAll(dirDir, 0755)

	t.Run("Do a quick exe", func(t *testing.T) {
		expected := `dir
things
`
		out, err := exe.QuickExe("ls", []string{stuffDir}...)
		if err != nil {
			t.Errorf("Got an error: %v\n", err)
		}
		if out != expected {
			fmt.Println(out)
			t.Errorf("got: %s; expected: %s", out, expected)
		}
	})

	t.Run("Use an ExeCtx", func(t *testing.T) {
		e := &exe.ExeCtx{
			Args:    []string{stuffDir},
			Command: "ls",
			Stderr:  os.Stderr,
			Stdout:  os.Stdout,
			Title:   "Test!",
			WorkDir: os.Getenv("HOME"),
		}
		err := e.Execute()
		if err != nil {
			t.Errorf("Got an error: %v\n", err)
		}
	})

	//TODO: Test GenPrefix; this will require an X server

	os.RemoveAll(dir)

}