Ai
5 Star 11 Fork 7

Gitee 极速下载/go-git

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/src-d/go-git
克隆/下载
modules_test.go 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
package config
import . "gopkg.in/check.v1"
type ModulesSuite struct{}
var _ = Suite(&ModulesSuite{})
func (s *ModulesSuite) TestValidateMissingURL(c *C) {
m := &Submodule{Path: "foo"}
c.Assert(m.Validate(), Equals, ErrModuleEmptyURL)
}
func (s *ModulesSuite) TestValidateBadPath(c *C) {
input := []string{
`..`,
`../`,
`../bar`,
`/..`,
`/../bar`,
`foo/..`,
`foo/../`,
`foo/../bar`,
}
for _, p := range input {
m := &Submodule{
Path: p,
URL: "https://example.com/",
}
c.Assert(m.Validate(), Equals, ErrModuleBadPath)
}
}
func (s *ModulesSuite) TestValidateMissingName(c *C) {
m := &Submodule{URL: "bar"}
c.Assert(m.Validate(), Equals, ErrModuleEmptyPath)
}
func (s *ModulesSuite) TestMarshall(c *C) {
input := []byte(`[submodule "qux"]
path = qux
url = baz
branch = bar
`)
cfg := NewModules()
cfg.Submodules["qux"] = &Submodule{Path: "qux", URL: "baz", Branch: "bar"}
output, err := cfg.Marshal()
c.Assert(err, IsNil)
c.Assert(output, DeepEquals, input)
}
func (s *ModulesSuite) TestUnmarshall(c *C) {
input := []byte(`[submodule "qux"]
path = qux
url = https://github.com/foo/qux.git
[submodule "foo/bar"]
path = foo/bar
url = https://github.com/foo/bar.git
branch = dev
[submodule "suspicious"]
path = ../../foo/bar
url = https://github.com/foo/bar.git
`)
cfg := NewModules()
err := cfg.Unmarshal(input)
c.Assert(err, IsNil)
c.Assert(cfg.Submodules, HasLen, 2)
c.Assert(cfg.Submodules["qux"].Name, Equals, "qux")
c.Assert(cfg.Submodules["qux"].URL, Equals, "https://github.com/foo/qux.git")
c.Assert(cfg.Submodules["foo/bar"].Name, Equals, "foo/bar")
c.Assert(cfg.Submodules["foo/bar"].URL, Equals, "https://github.com/foo/bar.git")
c.Assert(cfg.Submodules["foo/bar"].Branch, Equals, "dev")
}
func (s *ModulesSuite) TestUnmarshallMarshall(c *C) {
input := []byte(`[submodule "foo/bar"]
path = foo/bar
url = https://github.com/foo/bar.git
ignore = all
`)
cfg := NewModules()
err := cfg.Unmarshal(input)
c.Assert(err, IsNil)
output, err := cfg.Marshal()
c.Assert(err, IsNil)
c.Assert(string(output), DeepEquals, string(input))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/go-git.git
git@gitee.com:mirrors/go-git.git
mirrors
go-git
go-git
v4.7.0

搜索帮助