forked from lyft/protoc-gen-star
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_test.go
78 lines (60 loc) · 2.05 KB
/
path_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
package pgs
import (
"testing"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/golang/protobuf/protoc-gen-go/generator"
"github.com/stretchr/testify/assert"
)
func TestGoPackageOption(t *testing.T) {
t.Parallel()
fd := &generator.FileDescriptor{
FileDescriptorProto: &descriptor.FileDescriptorProto{
Options: &descriptor.FileOptions{}}}
impPath, pkg, ok := goPackageOption(fd)
assert.Empty(t, impPath)
assert.Empty(t, pkg)
assert.False(t, ok)
fd.Options.GoPackage = proto.String("foobar")
impPath, pkg, ok = goPackageOption(fd)
assert.Empty(t, impPath)
assert.Equal(t, "foobar", pkg)
assert.True(t, ok)
fd.Options.GoPackage = proto.String("fizz/buzz")
impPath, pkg, ok = goPackageOption(fd)
assert.Equal(t, "fizz/buzz", impPath)
assert.Equal(t, "buzz", pkg)
assert.True(t, ok)
fd.Options.GoPackage = proto.String("foo/bar;baz")
impPath, pkg, ok = goPackageOption(fd)
assert.Equal(t, "foo/bar", impPath)
assert.Equal(t, "baz", pkg)
assert.True(t, ok)
}
func TestGoFileName(t *testing.T) {
t.Parallel()
fd := &generator.FileDescriptor{
FileDescriptorProto: &descriptor.FileDescriptorProto{
Name: proto.String("dir/file.proto"),
Options: &descriptor.FileOptions{},
},
}
assert.Equal(t, "dir/file.pb.go", goFileName(fd, ImportPath))
fd.FileDescriptorProto.Options.GoPackage = proto.String("other/path")
assert.Equal(t, "other/path/file.pb.go", goFileName(fd, ImportPath))
assert.Equal(t, "dir/file.pb.go", goFileName(fd, SourceRelative))
}
func TestGoImportPath(t *testing.T) {
t.Parallel()
fd := &generator.FileDescriptor{
FileDescriptorProto: &descriptor.FileDescriptorProto{
Name: proto.String("dir/file.proto"),
Options: &descriptor.FileOptions{},
},
}
g := &generator.Generator{ImportMap: map[string]string{}}
assert.Equal(t, generator.GoImportPath("dir"), goImportPath(g, fd))
g.ImportMap[fd.GetName()] = "other/pkg"
g.ImportPrefix = "github.com/example"
assert.Equal(t, generator.GoImportPath("github.com/example/other/pkg"), goImportPath(g, fd))
}