01fa51110b
- reject option-like :git URLs and refs; pass -- before git positionals - link modules without following symlinks; reject nested module paths - judge worktree completeness by an out-of-tree done file - key git mirrors by URL hash and forge releases by forge base - bound every git and forge call with the -j semaphore
113 lines
3.6 KiB
Go
113 lines
3.6 KiB
Go
package deploy
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestParsePuppetfileEstate(t *testing.T) {
|
|
pf, err := ParsePuppetfile(`forge 'forge.puppetlabs.com'
|
|
moduledir 'external_modules'
|
|
|
|
# puppetlabs
|
|
mod 'puppetlabs-stdlib', '9.7.0'
|
|
mod 'puppetlabs-yumrepo_core', '2.1.0' # trailing comment
|
|
|
|
mod 'bind',
|
|
:git => 'https://git.unkin.net/unkinben/puppet-bind.git',
|
|
:tag => '1.0'
|
|
`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if pf.Forge != "forge.puppetlabs.com" || pf.Moduledir != "external_modules" {
|
|
t.Fatalf("header: %+v", pf)
|
|
}
|
|
want := []Module{
|
|
{Owner: "puppetlabs", Name: "stdlib", Version: "9.7.0"},
|
|
{Owner: "puppetlabs", Name: "yumrepo_core", Version: "2.1.0"},
|
|
{Name: "bind", Git: "https://git.unkin.net/unkinben/puppet-bind.git", RefKind: "tag", Ref: "1.0"},
|
|
}
|
|
if !reflect.DeepEqual(pf.Modules, want) {
|
|
t.Fatalf("modules:\n got %+v\nwant %+v", pf.Modules, want)
|
|
}
|
|
if p := pf.Modules[2].Path(pf); p != "external_modules/bind" {
|
|
t.Fatalf("path %s", p)
|
|
}
|
|
}
|
|
|
|
func TestParsePuppetfileForms(t *testing.T) {
|
|
pf, err := ParsePuppetfile(`
|
|
mod "puppet/systemd", "8.1.0"
|
|
mod 'saz-sudo', :latest
|
|
mod 'saz-ssh'
|
|
mod 'a-b', 'latest'
|
|
mod('x',
|
|
git: 'https://example/x.git',
|
|
branch: 'main')
|
|
mod 'y', :git => "file:///y#not-a-comment", :ref => 'v1'
|
|
mod 'z', :git => 'g', :commit => 'abc123', :install_path => 'site'
|
|
mod 'h', :git => 'g2'
|
|
`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := []Module{
|
|
{Owner: "puppet", Name: "systemd", Version: "8.1.0"},
|
|
{Owner: "saz", Name: "sudo"},
|
|
{Owner: "saz", Name: "ssh"},
|
|
{Owner: "a", Name: "b"},
|
|
{Name: "x", Git: "https://example/x.git", RefKind: "branch", Ref: "main"},
|
|
{Name: "y", Git: "file:///y#not-a-comment", RefKind: "ref", Ref: "v1"},
|
|
{Name: "z", Git: "g", RefKind: "commit", Ref: "abc123", InstallPath: "site"},
|
|
{Name: "h", Git: "g2"},
|
|
}
|
|
if !reflect.DeepEqual(pf.Modules, want) {
|
|
t.Fatalf("modules:\n got %+v\nwant %+v", pf.Modules, want)
|
|
}
|
|
if pf.Moduledir != "modules" {
|
|
t.Fatalf("default moduledir %q", pf.Moduledir)
|
|
}
|
|
if p := pf.Modules[6].Path(pf); p != "site/z" {
|
|
t.Fatalf("install_path %s", p)
|
|
}
|
|
}
|
|
|
|
func TestParsePuppetfileErrors(t *testing.T) {
|
|
for name, in := range map[string]string{
|
|
"unterminated": "mod 'a-b",
|
|
"unknown stmt": "require 'x'",
|
|
"unknown option": "mod 'x', :git => 'g', :default_branch => 'main'",
|
|
"two refs": "mod 'x', :git => 'g', :tag => 'a', :branch => 'b'",
|
|
"ref without git": "mod 'a-b', :tag => '1'",
|
|
"git version": "mod 'x', '1.0', :git => 'g'",
|
|
"no owner": "mod 'stdlib', '1.0'",
|
|
"bad name": "mod 'a-B@d', '1.0'",
|
|
"bad version": "mod 'a-b', '../../etc'",
|
|
"abs moduledir": "moduledir '/etc'",
|
|
"escape moduledir": "moduledir '../x'",
|
|
"escape install": "mod 'x', :git => 'g', :install_path => '../../x'",
|
|
"duplicate": "mod 'a-b', '1'\nmod 'c-b', '2'",
|
|
"final moduledir": "mod 'a-x', '1'\nmoduledir 'site'\nmod 'x', :git => 'g', :install_path => 'site'",
|
|
"nested": "mod 'a-thing', '1'\nmod 'metadata', :git => 'g', :install_path => 'modules/thing'",
|
|
"option git": "mod 'x', :git => '--upload-pack=touch /tmp/x'",
|
|
"option ref": "mod 'x', :git => 'g', :branch => '--output=/tmp/x'",
|
|
"trailing junk": "mod 'a-b', '1' 'c'",
|
|
"bad char": "mod 'a-b', '1'; x",
|
|
} {
|
|
if _, err := ParsePuppetfile(in); err == nil {
|
|
t.Errorf("%s: expected error", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParsePuppetfileFinalModuledir(t *testing.T) {
|
|
pf, err := ParsePuppetfile("mod 'a-x', '1'\nmoduledir 'site'\nmod 'x', :git => 'g', :install_path => 'modules'\n")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if p := pf.Modules[0].Path(pf); p != "site/x" {
|
|
t.Fatalf("forge module path %s, want final moduledir", p)
|
|
}
|
|
}
|