-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_test.go
87 lines (74 loc) · 1.67 KB
/
session_test.go
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
82
83
84
85
86
87
// SPDX-FileCopyrightText: 2021 M. Shulhan <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
//go:build !integration
package awwan
import (
"fmt"
"os"
"path/filepath"
"testing"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
)
func TestSession_generatePaths(t *testing.T) {
type testCase struct {
scriptPath string
expError string
exp []string
}
var (
ses = &Session{}
err error
)
ses.BaseDir, err = os.Getwd()
if err != nil {
t.Fatal(err)
}
var cases = []testCase{{
scriptPath: "/tmp/test.aww",
expError: fmt.Sprintf(`generatePaths: %q must be under %q`, "/tmp", ses.BaseDir),
}, {
scriptPath: "../test.aww",
expError: fmt.Sprintf(`generatePaths: %q must be under %q`, "..", ses.BaseDir),
}, {
scriptPath: "test.aww",
exp: []string{
ses.BaseDir,
},
}, {
scriptPath: "testdata/test.aww",
exp: []string{
ses.BaseDir,
filepath.Join(ses.BaseDir, "testdata"),
},
}, {
scriptPath: "./testdata/a/test.aww",
exp: []string{
ses.BaseDir,
filepath.Join(ses.BaseDir, "testdata"),
filepath.Join(ses.BaseDir, "testdata", "a"),
},
}, {
scriptPath: "testdata/../testdata/a/test.aww",
exp: []string{
ses.BaseDir,
filepath.Join(ses.BaseDir, "testdata"),
filepath.Join(ses.BaseDir, "testdata", "a"),
},
}}
var (
c testCase
scriptPath string
)
for _, c = range cases {
t.Log(c.scriptPath)
scriptPath = filepath.Clean(c.scriptPath)
ses.ScriptDir = filepath.Dir(scriptPath)
ses.hostname = filepath.Base(ses.ScriptDir)
err = ses.generatePaths()
if err != nil {
test.Assert(t, "error", c.expError, err.Error())
continue
}
test.Assert(t, "generatePaths:", c.exp, ses.paths)
}
}