Skip to content

Commit

Permalink
test(kernel): add universal navigator tests (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Jul 2, 2024
1 parent 7d5815d commit fbfe00a
Show file tree
Hide file tree
Showing 28 changed files with 339 additions and 122 deletions.
10 changes: 5 additions & 5 deletions builders.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tv

import (
"github.com/snivilised/traverse/core"
"github.com/snivilised/traverse/internal/kernel"
"github.com/snivilised/traverse/internal/types"
"github.com/snivilised/traverse/measure"
Expand All @@ -10,7 +9,7 @@ import (

type buildArtefacts struct {
o *pref.Options
nav core.Navigator
nav types.KernelController
plugins []types.Plugin
ext extent
}
Expand Down Expand Up @@ -60,7 +59,8 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {
//
plugins, pluginsErr := bs.plugins.build(o,
artefacts.Mediator,
ext.plugin(artefacts.Mediator),
artefacts.Controller,
ext.plugin(artefacts),
)

if pluginsErr != nil {
Expand All @@ -77,7 +77,7 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {
if bindErr := p.Init(); bindErr != nil {
return &buildArtefacts{
o: o,
nav: artefacts.Navigator,
nav: artefacts.Controller,
plugins: plugins,
ext: ext,
}, bindErr
Expand All @@ -86,7 +86,7 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {

return &buildArtefacts{
o: o,
nav: artefacts.Navigator,
nav: artefacts.Controller,
plugins: plugins,
ext: ext,
}, nil
Expand Down
15 changes: 10 additions & 5 deletions director.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ifActive func(o *pref.Options, mediator types.Mediator) types.Plugin
// to activate features according to option selections. other plugins will
// be initialised after primary plugins
func activated(o *pref.Options, mediator types.Mediator,
kc types.KernelController,
others ...types.Plugin,
) (plugins []types.Plugin, err error) {
var (
Expand All @@ -42,7 +43,7 @@ func activated(o *pref.Options, mediator types.Mediator,
}

for _, plugin := range plugins {
err = plugin.Register()
err = plugin.Register(kc)

if err != nil {
return nil, err
Expand Down Expand Up @@ -88,8 +89,10 @@ func Prime(using *pref.Using, settings ...pref.Option) *Builders {

return ext.options(settings...)
}),
navigator: kernel.Builder(func(o *pref.Options, res *types.Resources) (*kernel.Artefacts, error) {
return kernel.New(using, o, &kernel.Benign{}, res), nil
navigator: kernel.Builder(func(o *pref.Options,
resources *types.Resources,
) (*kernel.Artefacts, error) {
return kernel.New(using, o, &kernel.Benign{}, resources), nil
}),
plugins: features(activated), // swap over features & activated
}
Expand Down Expand Up @@ -132,8 +135,10 @@ func Resume(was *Was, settings ...pref.Option) *Builders {

return ext.options(settings...)
}),
navigator: kernel.Builder(func(o *pref.Options, res *types.Resources) (*kernel.Artefacts, error) {
artefacts := kernel.New(&was.Using, o, resume.GetSealer(was), res)
navigator: kernel.Builder(func(o *pref.Options,
resources *types.Resources,
) (*kernel.Artefacts, error) {
artefacts := kernel.New(&was.Using, o, resume.GetSealer(was), resources)

return resume.NewController(was, artefacts), nil
}),
Expand Down
2 changes: 1 addition & 1 deletion driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (d *driver) init() {
_ = m.Data
// now invoke session.finish
},
Matcher: services.TopicTraverseResult,
Matcher: services.TopicNavigationComplete,
})
}

Expand Down
23 changes: 18 additions & 5 deletions extent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
type extent interface {
using() *pref.Using
was() *pref.Was
plugin(types.Mediator) types.Plugin
plugin(*kernel.Artefacts) types.Plugin // !!! *kernel.Artefacts
options(...pref.Option) (*pref.Options, error)
navFS() fs.FS
resFS() fs.FS
complete() bool
}

type fileSystems struct {
Expand Down Expand Up @@ -48,18 +49,23 @@ func (ex *primeExtent) was() *pref.Was {
return nil
}

func (ex *primeExtent) plugin(types.Mediator) types.Plugin {
func (ex *primeExtent) plugin(*kernel.Artefacts) types.Plugin {
return nil
}

func (ex *primeExtent) options(settings ...pref.Option) (*pref.Options, error) {
return pref.Get(settings...)
}

func (ex *primeExtent) complete() bool {
return true
}

type resumeExtent struct {
baseExtent
w *pref.Was
loaded *pref.LoadInfo
rp *resume.Plugin
}

func (ex *resumeExtent) using() *pref.Using {
Expand All @@ -70,12 +76,15 @@ func (ex *resumeExtent) was() *pref.Was {
return ex.w
}

func (ex *resumeExtent) plugin(mediator types.Mediator) types.Plugin {
return &resume.Plugin{
func (ex *resumeExtent) plugin(artefacts *kernel.Artefacts) types.Plugin {
ex.rp = &resume.Plugin{
BasePlugin: kernel.BasePlugin{
Mediator: mediator,
Mediator: artefacts.Mediator,
},
Complete: artefacts.Completion,
}

return ex.rp
}

func (ex *resumeExtent) options(settings ...pref.Option) (*pref.Options, error) {
Expand All @@ -88,3 +97,7 @@ func (ex *resumeExtent) options(settings ...pref.Option) (*pref.Options, error)
//
return loaded.O, err
}

func (ex *resumeExtent) complete() bool {
return ex.rp.Complete()
}
22 changes: 17 additions & 5 deletions internal-traverse-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,25 @@ func (fn optionals) build(ext extent) (*pref.Options, error) {

// pluginsBuilder
type pluginsBuilder interface {
build(*pref.Options, types.Mediator, ...types.Plugin) ([]types.Plugin, error)
build(*pref.Options,
types.Mediator,
types.KernelController,
...types.Plugin,
) ([]types.Plugin, error)
}

type features func(*pref.Options, types.Mediator, ...types.Plugin) ([]types.Plugin, error)

func (fn features) build(o *pref.Options, mediator types.Mediator, others ...types.Plugin) ([]types.Plugin, error) {
return fn(o, mediator, others...)
type features func(*pref.Options,
types.Mediator,
types.KernelController,
...types.Plugin,
) ([]types.Plugin, error)

func (fn features) build(o *pref.Options,
mediator types.Mediator,
kc types.KernelController,
others ...types.Plugin,
) ([]types.Plugin, error) {
return fn(o, mediator, kc, others...)
}

type fsBuilder interface {
Expand Down
4 changes: 3 additions & 1 deletion internal/hiber/hibernate-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func (p *Plugin) Name() string {
return "hibernation"
}

func (p *Plugin) Register() error {
func (p *Plugin) Register(kc types.KernelController) error {
p.Controller = kc

return nil
}

Expand Down
3 changes: 2 additions & 1 deletion internal/kernel/base-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import (
)

type BasePlugin struct {
Mediator types.Mediator
Mediator types.Mediator
Controller types.KernelController
}
18 changes: 12 additions & 6 deletions internal/kernel/builder.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
package kernel

import (
"github.com/snivilised/traverse/core"
"github.com/snivilised/traverse/internal/types"
"github.com/snivilised/traverse/pref"
)

type (
Artefacts struct {
Navigator core.Navigator
Controller types.KernelController
Mediator types.Mediator
Facilities types.Facilities
Resources *types.Resources
Completion types.Completion
}

NavigatorBuilder interface {
Build(o *pref.Options, res *types.Resources) (*Artefacts, error)
Build(o *pref.Options,
resources *types.Resources,
) (*Artefacts, error)
}

Builder func(o *pref.Options, res *types.Resources) (*Artefacts, error)
Builder func(o *pref.Options,
resources *types.Resources,
) (*Artefacts, error)
)

func (fn Builder) Build(o *pref.Options, res *types.Resources) (*Artefacts, error) {
return fn(o, res)
func (fn Builder) Build(o *pref.Options,
resources *types.Resources,
) (*Artefacts, error) {
return fn(o, resources)
}
14 changes: 10 additions & 4 deletions internal/kernel/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ type (
invocationIt = collections.Iterator[types.Link]
)

type owned struct {
mums measure.Mutables
}

// anchor is a specialised link that should always be the
// last in the chain and contains the original client's handler.
type anchor struct {
target core.Client
mums measure.Mutables
owned owned
}

func (t *anchor) Next(node *core.Node) (bool, error) {
if metric := lo.Ternary(node.IsFolder(),
t.mums[enums.MetricNoFoldersInvoked],
t.mums[enums.MetricNoFilesInvoked],
t.owned.mums[enums.MetricNoFoldersInvoked],
t.owned.mums[enums.MetricNoFilesInvoked],
); metric != nil {
metric.Tick()
}
Expand Down Expand Up @@ -67,7 +71,9 @@ func newGuardian(callback core.Client,
stack := collections.NewStack[types.Link]()
stack.Push(&anchor{
target: callback,
mums: mums,
owned: owned{
mums: mums,
},
})

return &guardian{
Expand Down
4 changes: 4 additions & 0 deletions internal/kernel/kernel-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
type (
// NavigatorImpl
NavigatorImpl interface {
Starting(session types.Session)

// Top
Top(ctx context.Context,
ns *navigationStatic,
Expand All @@ -24,6 +26,8 @@ type (
ns *navigationStatic,
current *core.Node,
) (bool, error)

Result(ctx context.Context, err error) *types.KernelResult
}

// NavigatorDriver
Expand Down
64 changes: 64 additions & 0 deletions internal/kernel/kernel-support_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
package kernel_test

import (
"io/fs"

. "github.com/onsi/ginkgo/v2" //nolint:revive // ok
. "github.com/onsi/gomega" //nolint:revive // ok
"github.com/snivilised/traverse/core"
"github.com/snivilised/traverse/cycle"
"github.com/snivilised/traverse/enums"
"github.com/snivilised/traverse/internal/helpers"
)

const (
RootPath = "traversal-root-path"
RestorePath = "/from-restore-path"
)

type recordingMap map[string]int
type recordingScopeMap map[string]enums.FilterScope
type recordingOrderMap map[string]int

type directoryQuantities struct {
files uint
folders uint
children map[string]int
}

type naviTE struct {
message string
should string
relative string
once bool
visit bool
caseSensitive bool
subscription enums.Subscription
callback core.Client
mandatory []string
prohibited []string
expectedNoOf directoryQuantities
}

func begin(em string) cycle.BeginHandler {
return func(root string) {
GinkgoWriter.Printf(
"---> %v [traverse-navigator-test:BEGIN], root: '%v'\n", em, root,
)
}
}

func universalCallback(name string) core.Client {
return func(node *core.Node) error {
depth := node.Extension.Depth
GinkgoWriter.Printf(
"---> 🌊 UNIVERSAL//%v-CALLBACK: (depth:%v) '%v'\n", name, depth, node.Path,
)
Expect(node.Extension).NotTo(BeNil(), helpers.Reason(node.Path))
return nil
}
}

func subscribes(subscription enums.Subscription, de fs.DirEntry) bool {
isAnySubscription := (subscription == enums.SubscribeUniversal)

files := (subscription == enums.SubscribeFiles) && (!de.IsDir())
folders := ((subscription == enums.SubscribeFolders) ||
subscription == enums.SubscribeFoldersWithFiles) && (de.IsDir())

return isAnySubscription || files || folders
}
Loading

0 comments on commit fbfe00a

Please sign in to comment.