Skip to content

Commit

Permalink
feat(proxy): move program execution to runner (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Dec 4, 2023
1 parent 31e8eef commit 11b3924
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 27 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"govet",
"graffico",
"ineffassign",
"interstella",
"jibberjabber",
"linters",
"lintv",
Expand Down
14 changes: 7 additions & 7 deletions src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Bootstrap struct {

type ConfigureOptionsInfo struct {
Detector LocaleDetector
Executor proxy.Executor
Program proxy.Executor
Config ConfigInfo
}

Expand All @@ -81,7 +81,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {

b.optionsInfo = ConfigureOptionsInfo{
Detector: &Jabber{},
Executor: &ProgramExecutor{
Program: &ProgramExecutor{
Name: "magick",
},
Config: ConfigInfo{
Expand All @@ -92,9 +92,9 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {
},
}

if _, err := b.optionsInfo.Executor.Look(); err != nil {
b.optionsInfo.Executor = &DummyExecutor{
Name: b.optionsInfo.Executor.ProgName(),
if _, err := b.optionsInfo.Program.Look(); err != nil {
b.optionsInfo.Program = &DummyExecutor{
Name: b.optionsInfo.Program.ProgName(),
}
}

Expand All @@ -106,7 +106,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {

// JUST TEMPORARY: make the executor the dummy for safety
//
b.optionsInfo.Executor = &DummyExecutor{
b.optionsInfo.Program = &DummyExecutor{
Name: "magick",
}

Expand All @@ -129,7 +129,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {

// ---> execute root core
//
return proxy.EnterRoot(inputs, b.optionsInfo.Executor, b.optionsInfo.Config.Viper)
return proxy.EnterRoot(inputs, b.optionsInfo.Program, b.optionsInfo.Config.Viper)
},
},
)
Expand Down
2 changes: 1 addition & 1 deletion src/app/command/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var _ = Describe("Bootstrap", Ordered, func() {
bootstrap := command.Bootstrap{}
rootCmd := bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
co.Executor = &ExecutorStub{
co.Program = &ExecutorStub{
Name: "magick",
}
co.Config.Name = helpers.PixaConfigTestFilename
Expand Down
2 changes: 1 addition & 1 deletion src/app/command/root-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var _ = Describe("RootCmd", Ordered, func() {
Args: []string{"./"},
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
co.Executor = &ExecutorStub{
co.Program = &ExecutorStub{
Name: "magick",
}
co.Config.Name = helpers.PixaConfigTestFilename
Expand Down
2 changes: 1 addition & 1 deletion src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob

appErr = proxy.EnterShrink(
inputs,
b.optionsInfo.Executor,
b.optionsInfo.Program,
b.optionsInfo.Config.Viper,
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/app/command/shrink-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func expectValidShrinkCmdInvocation(entry *shrinkTE) {
Args: append(options, entry.args...),
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
co.Executor = &ExecutorStub{
co.Program = &ExecutorStub{
Name: helpers.ProgName,
}
co.Config.Name = helpers.PixaConfigTestFilename
Expand Down
2 changes: 1 addition & 1 deletion src/app/proxy/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func expectValidShrinkCmdInvocation(entry *configTE) {
Args: append(options, entry.args...),
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &helpers.DetectorStub{}
co.Executor = &helpers.ExecutorStub{
co.Program = &helpers.ExecutorStub{
Name: helpers.ProgName,
}
co.Config.Name = helpers.PixaConfigTestFilename
Expand Down
1 change: 1 addition & 0 deletions src/app/proxy/runner-registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewRunnerRegistry(params *NewRunnerParams) *RunnerRegistry {
shared: &SharedRunnerInfo{
Type: params.Type,
Options: params.Options,
program: params.Program,
},
},
}
Expand Down
31 changes: 17 additions & 14 deletions src/app/proxy/sampler-runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
)

type runnerTE struct {
given string
should string
args []string
profile string
directory string
given string
should string
args []string
profile string
relative string
}

type samplerTE struct {
Expand All @@ -35,7 +35,7 @@ var _ = Describe("SamplerRunner", Ordered, func() {
repo string
l10nPath string
configPath string
scientist string
root string
config configuration.ViperConfig
nfs storage.VirtualFS
)
Expand All @@ -50,8 +50,9 @@ var _ = Describe("SamplerRunner", Ordered, func() {
configPath = filepath.Join(repo, "test", "data", "configuration")
Expect(matchers.AsDirectory(configPath)).To(matchers.ExistInFS(nfs))

scientist = helpers.Scientist()
Expect(matchers.AsDirectory(scientist)).To(matchers.ExistInFS(nfs))
root = helpers.Scientist()
Expect(matchers.AsDirectory(root)).To(matchers.ExistInFS(nfs))

})

BeforeEach(func() {
Expand Down Expand Up @@ -88,8 +89,9 @@ var _ = Describe("SamplerRunner", Ordered, func() {

DescribeTable("sampler",
func(entry *samplerTE) {
directory := helpers.Path(root, entry.relative)
options := []string{
helpers.ShrinkCommandName, scientist,
helpers.ShrinkCommandName, directory,
// "--sample-files", "3"
// "--sample-folders", "3"
"--dry-run",
Expand All @@ -102,7 +104,7 @@ var _ = Describe("SamplerRunner", Ordered, func() {
Args: append(options, entry.args...),
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &helpers.DetectorStub{}
co.Executor = &helpers.ExecutorStub{
co.Program = &helpers.ExecutorStub{
Name: helpers.ProgName,
}
co.Config.Name = helpers.PixaConfigTestFilename
Expand All @@ -121,12 +123,13 @@ var _ = Describe("SamplerRunner", Ordered, func() {
)
},

XEntry(nil, &samplerTE{
FEntry(nil, &samplerTE{
runnerTE: runnerTE{
given: "foo",
should: "bar",
given: "scheme",
should: "bar",
relative: "nasa/interstellar/Dark Energy Explorers/sessions/scan-01",
args: []string{
"--strip", "--interlace", "plane", "--quality", "85", "--cpu",
"--strip", "--interlace", "plane", "--quality", "85",
},
},
}),
Expand Down
2 changes: 1 addition & 1 deletion test/data/storage/citizen-scientist-index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
</directory>
</directory>
</directory>
<directory name="interstella">
<directory name="interstellar">
<directory name="Dark Energy Explorers">
<directory name="sessions">
<directory name="scan-01">
Expand Down

0 comments on commit 11b3924

Please sign in to comment.