-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathgenerator_test.go
50 lines (44 loc) · 1.02 KB
/
generator_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
package turbo
import (
"io"
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUnknownType(t *testing.T) {
defer func() {
if err := recover(); err != nil {
assert.Equal(t, "Invalid server type, should be (grpc|thrift)", err)
} else {
t.Errorf("The code did not panic")
}
}()
g := &Generator{}
g.Generate()
}
func TestValidateServiceRootPath(t *testing.T) {
g := &Creator{PkgPath: "a"}
var r io.Reader
r = strings.NewReader("y\n")
g.validateServiceRootPath(r)
rp, _ := filepath.Abs("../../../")
g = &Creator{FileRootPath: rp, PkgPath: "github.com/vaporz/turbo/test/a"}
p := rp + "/github.com/vaporz/turbo/test/a"
os.MkdirAll(p, 0755)
g.validateServiceRootPath(r)
_, err := os.Stat(p)
assert.True(t, os.IsNotExist(err))
}
func TestInvalidPkgPath(t *testing.T) {
defer func() {
if err := recover(); err != nil {
assert.Equal(t, "pkgPath is blank", err)
} else {
t.Errorf("The code did not panic")
}
}()
g := &Creator{}
g.validateServiceRootPath(nil)
}