|
|
|
|
@ -19,6 +19,18 @@ func TestResolver_Resolve(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg.Children = map[string]*configs.Config{
|
|
|
|
|
"foo": &configs.Config{
|
|
|
|
|
Path: addrs.Module{"foo"},
|
|
|
|
|
Parent: cfg,
|
|
|
|
|
Children: make(map[string]*configs.Config),
|
|
|
|
|
SourceAddr: addrs.ModuleSourceLocal("./foo"),
|
|
|
|
|
Module: &configs.Module{
|
|
|
|
|
ModuleCalls: map[string]*configs.ModuleCall{},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
manifest := modsdir.Manifest{
|
|
|
|
|
"foo": modsdir.Record{
|
|
|
|
|
Key: "foo",
|
|
|
|
|
@ -48,12 +60,27 @@ func TestResolver_ResolveNestedChildren(t *testing.T) {
|
|
|
|
|
cfg.Children = make(map[string]*configs.Config)
|
|
|
|
|
cfg.Module = &configs.Module{
|
|
|
|
|
ModuleCalls: map[string]*configs.ModuleCall{
|
|
|
|
|
"foo": {Name: "foo"},
|
|
|
|
|
"foo": {Name: "foo"},
|
|
|
|
|
"fellowship": {Name: "fellowship"},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg.Children["foo"] = &configs.Config{
|
|
|
|
|
Path: addrs.Module{"foo"},
|
|
|
|
|
Parent: cfg,
|
|
|
|
|
SourceAddr: addrs.ModuleSourceLocal("./foo"),
|
|
|
|
|
Children: make(map[string]*configs.Config),
|
|
|
|
|
Module: &configs.Module{
|
|
|
|
|
ModuleCalls: map[string]*configs.ModuleCall{},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
childCfg := &configs.Config{
|
|
|
|
|
Path: addrs.Module{"fellowship"},
|
|
|
|
|
childCfgFellowship := &configs.Config{
|
|
|
|
|
Path: addrs.Module{"fellowship"},
|
|
|
|
|
Parent: cfg,
|
|
|
|
|
SourceAddr: addrs.ModuleSourceRemote{
|
|
|
|
|
Package: addrs.ModulePackage("fellowship"),
|
|
|
|
|
},
|
|
|
|
|
Children: make(map[string]*configs.Config),
|
|
|
|
|
Module: &configs.Module{
|
|
|
|
|
ModuleCalls: map[string]*configs.ModuleCall{
|
|
|
|
|
@ -61,9 +88,26 @@ func TestResolver_ResolveNestedChildren(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
cfg.Children["fellowship"] = childCfgFellowship
|
|
|
|
|
|
|
|
|
|
childCfgFellowship.Children["frodo"] = &configs.Config{
|
|
|
|
|
Path: addrs.Module{"fellowship", "frodo"},
|
|
|
|
|
Parent: childCfgFellowship,
|
|
|
|
|
SourceAddr: addrs.ModuleSourceRemote{
|
|
|
|
|
Package: addrs.ModulePackage("fellowship/frodo"),
|
|
|
|
|
},
|
|
|
|
|
Children: make(map[string]*configs.Config),
|
|
|
|
|
Module: &configs.Module{
|
|
|
|
|
ModuleCalls: map[string]*configs.ModuleCall{},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
childCfg2 := &configs.Config{
|
|
|
|
|
Path: addrs.Module{"fellowship", "weapons"},
|
|
|
|
|
childCfgWeapons := &configs.Config{
|
|
|
|
|
Path: addrs.Module{"fellowship", "weapons"},
|
|
|
|
|
Parent: childCfgFellowship,
|
|
|
|
|
SourceAddr: addrs.ModuleSourceRemote{
|
|
|
|
|
Package: addrs.ModulePackage("fellowship/weapons"),
|
|
|
|
|
},
|
|
|
|
|
Children: make(map[string]*configs.Config),
|
|
|
|
|
Module: &configs.Module{
|
|
|
|
|
ModuleCalls: map[string]*configs.ModuleCall{
|
|
|
|
|
@ -71,9 +115,19 @@ func TestResolver_ResolveNestedChildren(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
childCfgFellowship.Children["weapons"] = childCfgWeapons
|
|
|
|
|
|
|
|
|
|
cfg.Children["fellowship"] = childCfg
|
|
|
|
|
childCfg.Children["weapons"] = childCfg2
|
|
|
|
|
childCfgWeapons.Children["sting"] = &configs.Config{
|
|
|
|
|
Path: addrs.Module{"fellowship", "weapons", "sting"},
|
|
|
|
|
Parent: childCfgWeapons,
|
|
|
|
|
SourceAddr: addrs.ModuleSourceRemote{
|
|
|
|
|
Package: addrs.ModulePackage("fellowship/weapons/sting"),
|
|
|
|
|
},
|
|
|
|
|
Children: make(map[string]*configs.Config),
|
|
|
|
|
Module: &configs.Module{
|
|
|
|
|
ModuleCalls: map[string]*configs.ModuleCall{},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
manifest := modsdir.Manifest{
|
|
|
|
|
"foo": modsdir.Record{
|
|
|
|
|
@ -84,10 +138,18 @@ func TestResolver_ResolveNestedChildren(t *testing.T) {
|
|
|
|
|
Key: "bar",
|
|
|
|
|
SourceAddr: "./bar",
|
|
|
|
|
},
|
|
|
|
|
"fellowship": modsdir.Record{
|
|
|
|
|
Key: "fellowship",
|
|
|
|
|
SourceAddr: "fellowship",
|
|
|
|
|
},
|
|
|
|
|
"fellowship.frodo": modsdir.Record{
|
|
|
|
|
Key: "fellowship.frodo",
|
|
|
|
|
SourceAddr: "fellowship/frodo",
|
|
|
|
|
},
|
|
|
|
|
"fellowship.weapons": modsdir.Record{
|
|
|
|
|
Key: "fellowship.weapons",
|
|
|
|
|
SourceAddr: "fellowship/weapons",
|
|
|
|
|
},
|
|
|
|
|
"fellowship.weapons.sting": modsdir.Record{
|
|
|
|
|
Key: "fellowship.weapons.sting",
|
|
|
|
|
SourceAddr: "fellowship/weapons/sting",
|
|
|
|
|
@ -100,23 +162,36 @@ func TestResolver_ResolveNestedChildren(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
resolver := NewResolver(manifest)
|
|
|
|
|
result := resolver.Resolve(cfg)
|
|
|
|
|
|
|
|
|
|
if len(result.Records) != 3 {
|
|
|
|
|
t.Fatalf("expected the resolved number of entries to equal 3, got: %d", len(result.Records))
|
|
|
|
|
recordsCount, sources := countAndListSources(result.Records)
|
|
|
|
|
if recordsCount != 5 {
|
|
|
|
|
t.Fatalf("expected the resolved number of entries to equal 5, got: %d", recordsCount)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assertions := map[string]bool{
|
|
|
|
|
"foo": true,
|
|
|
|
|
"bar": false,
|
|
|
|
|
"fellowship.frodo": true,
|
|
|
|
|
"fellowship.weapons.sting": true,
|
|
|
|
|
"fellowship.weapons.anduril": false,
|
|
|
|
|
"./foo": true,
|
|
|
|
|
"./bar": false,
|
|
|
|
|
"fellowship": true,
|
|
|
|
|
"fellowship/frodo": true,
|
|
|
|
|
"fellowship/weapons": true,
|
|
|
|
|
"fellowship/weapons/sting": true,
|
|
|
|
|
"fellowship/weapons/anduril": false,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, record := range result.Records {
|
|
|
|
|
referenced, ok := assertions[record.Key]
|
|
|
|
|
for _, source := range sources {
|
|
|
|
|
referenced, ok := assertions[source]
|
|
|
|
|
if !ok || !referenced {
|
|
|
|
|
t.Fatalf("expected to find referenced entry with key: %s", record.Key)
|
|
|
|
|
t.Fatalf("expected to find referenced entry with key: %s", source)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func countAndListSources(records []*Record) (count int, sources []string) {
|
|
|
|
|
for _, record := range records {
|
|
|
|
|
sources = append(sources, record.Source.String())
|
|
|
|
|
count++
|
|
|
|
|
childCount, childSources := countAndListSources(record.Children)
|
|
|
|
|
count += childCount
|
|
|
|
|
sources = append(sources, childSources...)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|