generated from snivilised/astrolib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: formalise bootstrap phases (#29)
- Loading branch information
1 parent
9d75d11
commit 2e0ef67
Showing
31 changed files
with
1,104 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package traverse | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/snivilised/traverse/core" | ||
"github.com/snivilised/traverse/internal/types" | ||
"github.com/snivilised/traverse/pref" | ||
) | ||
|
||
type buildArtefacts struct { | ||
o *pref.Options | ||
nav core.Navigator | ||
plugins []types.Plugin | ||
} | ||
|
||
type Builders struct { | ||
ob optionsBuilder | ||
nb navigatorBuilder | ||
pb pluginsBuilder | ||
} | ||
|
||
func (bs *Builders) buildAll() (*buildArtefacts, error) { | ||
o, optionsErr := bs.ob.build() | ||
if optionsErr != nil { | ||
return nil, optionsErr | ||
} | ||
|
||
nav, navErr := bs.nb.build(o) | ||
if navErr != nil { | ||
return nil, navErr | ||
} | ||
|
||
plugins, pluginsErr := bs.pb.build(o) | ||
if pluginsErr != nil { | ||
return nil, pluginsErr | ||
} | ||
|
||
if host, ok := nav.(types.UsePlugin); ok { | ||
es := []error{} | ||
for _, p := range plugins { | ||
registrationErr := host.Register(p) | ||
es = append(es, registrationErr) | ||
} | ||
|
||
if pluginErr := errors.Join(es...); pluginErr != nil { | ||
return nil, pluginErr | ||
} | ||
} | ||
|
||
return &buildArtefacts{ | ||
o: o, | ||
nav: nav, | ||
plugins: plugins, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type UsingError struct { | ||
message string | ||
} | ||
|
||
func (e UsingError) Error() string { | ||
// TODO: i18n | ||
return fmt.Sprintf("using error: %v", e.message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package core | ||
|
||
type FilterDef struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package traverse_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" //nolint:revive // ok | ||
. "github.com/onsi/gomega" //nolint:revive // ok | ||
|
||
"github.com/snivilised/traverse" | ||
"github.com/snivilised/traverse/internal/services" | ||
) | ||
|
||
type traverseErrorTE struct { | ||
given string | ||
using *traverse.Using | ||
as *traverse.As | ||
} | ||
|
||
var _ = Describe("director error", Ordered, func() { | ||
var handler traverse.Client | ||
|
||
BeforeAll(func() { | ||
handler = func(_ *traverse.Node) error { | ||
return nil | ||
} | ||
}) | ||
|
||
BeforeEach(func() { | ||
services.Reset() | ||
}) | ||
|
||
DescribeTable("Validate", | ||
func(entry *traverseErrorTE) { | ||
if entry.using != nil { | ||
Expect(entry.using.Validate()).NotTo(Succeed()) | ||
|
||
return | ||
} | ||
|
||
if entry.as != nil { | ||
Expect(entry.as.Validate()).NotTo(Succeed()) | ||
|
||
return | ||
} | ||
}, | ||
func(entry *traverseErrorTE) string { | ||
return fmt.Sprintf("given: %v, 🧪 should fail", entry.given) | ||
}, | ||
Entry(nil, &traverseErrorTE{ | ||
given: "using missing root path", | ||
using: &traverse.Using{ | ||
Subscription: traverse.SubscribeFiles, | ||
Handler: handler, | ||
}, | ||
}), | ||
|
||
Entry(nil, &traverseErrorTE{ | ||
given: "using missing subscription", | ||
using: &traverse.Using{ | ||
Root: "/root-traverse-path", | ||
Handler: handler, | ||
}, | ||
}), | ||
|
||
Entry(nil, &traverseErrorTE{ | ||
given: "using missing handler", | ||
using: &traverse.Using{ | ||
Root: "/root-traverse-path", | ||
Subscription: traverse.SubscribeFiles, | ||
}, | ||
}), | ||
|
||
Entry(nil, &traverseErrorTE{ | ||
given: "as missing restore from path", | ||
as: &traverse.As{ | ||
Using: traverse.Using{ | ||
Root: "/root-traverse-path", | ||
Subscription: traverse.SubscribeFiles, | ||
Handler: handler, | ||
}, | ||
Strategy: traverse.ResumeStrategySpawn, | ||
}, | ||
}), | ||
|
||
Entry(nil, &traverseErrorTE{ | ||
given: "as missing resume strategy", | ||
as: &traverse.As{ | ||
Using: traverse.Using{ | ||
Root: "/root-traverse-path", | ||
Subscription: traverse.SubscribeFiles, | ||
Handler: handler, | ||
}, | ||
From: "/restore-from-path", | ||
}, | ||
}), | ||
) | ||
}) |
Oops, something went wrong.