Skip to content

Commit

Permalink
fix(proxy): non transparent with output path finder unit tests (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Feb 16, 2024
1 parent b6983af commit 1e943b8
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/app/proxy/filing/filing-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func SupplementFilename(name, supp string, statics *common.StaticInfo) string {
return statics.FileSupplement(withoutExt, supp) + path.Ext(name)
}

func SupplementDirectory(directory, supp string) string {
func SupplementFolder(directory, supp string) string {
return filepath.Join(directory, supp)
}
34 changes: 19 additions & 15 deletions src/app/proxy/filing/path-finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,15 @@ func (f *PathFinder) Scheme() string {
func (f *PathFinder) Transfer(info *common.PathInfo) (folder, file string) {
folder = func() string {
if info.Cuddle {
return info.Origin
return info.Origin // should we return empty string here?
}

if info.Output != "" && info.Trash == "" {
// When output folder is specified, then the results will be diverted there.
// This means there is no need to transfer the input, unless trash has
// also been specified.
//
return ""
}

segments := pfTemplates[pfPathInputTransferFolder]
Expand All @@ -284,6 +292,14 @@ func (f *PathFinder) Transfer(info *common.PathInfo) (folder, file string) {
}()

file = func() string {
if info.Output != "" && info.Trash == "" {
// When output folder is specified, then the results will be diverted there.
// This means there is no need to transfer the input, unless trash has
// also been specified.
//
return ""
}

if info.Cuddle {
supp := fmt.Sprintf("%v.%v", f.Stats.DejaVu(), f.fileSupplement(info.Profile))

Expand Down Expand Up @@ -340,7 +356,7 @@ func (f *PathFinder) Result(info *common.PathInfo) (folder, file string) {
}, segments...)
},
func() string {
segments := pfTemplates[pfPathInputTransferFolder]
segments := pfTemplates[pfPathResultFolder]
to := lo.TernaryF(f.Output != "",
func() string {
return f.Output
Expand All @@ -350,23 +366,11 @@ func (f *PathFinder) Result(info *common.PathInfo) (folder, file string) {
},
)
// If there is no scheme or profile, then the user is
// only relying flags on the command line, ie running adhoc
// only relying on flags on the command line, ie running adhoc
// so the result path should include an adhoc label. Otherwise,
// the result should reflect the supplementary path.
//

// if arity >1 then we need to use a different field list
// the current one below only works for arity=1.
// when arity > 1 we need the following:

/*
[0]:"${{TRANSFER-DESTINATION}}"
[1]:"${{ITEM-SUB-PATH}}"
[2]:"${{DEJA-VU}}"
[3]:"${{SUPPLEMENT}}"
[4]:"${{TRASH-LABEL}}"
*/

return pfTemplates.evaluate(pfFieldValues{
"${{OUTPUT-ROOT}}": to,
"${{SUPPLEMENT}}": f.folderSupplement(info.Profile),
Expand Down
107 changes: 84 additions & 23 deletions src/app/proxy/filing/path-finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/snivilised/cobrass/src/clif"
"github.com/snivilised/extendio/xfs/nav"
"github.com/snivilised/pixa/src/app/cfg"
"github.com/snivilised/pixa/src/app/proxy/common"
Expand Down Expand Up @@ -69,28 +68,6 @@ var _ = Describe("PathFinder", Ordered, func() {
},
}

profiles := cfg.MsProfilesConfig{
Profiles: cfg.ProfilesConfigMap{
"blur": clif.ChangedFlagsMap{
"strip": "true",
"interlace": "plane",
"gaussian-blur": "0.25",
},
"sf": clif.ChangedFlagsMap{
"strip": "true",
"gaussian-blur": "0.25",
"adaptive-resize": "60",
},
"adaptive": clif.ChangedFlagsMap{
"strip": "true",
"interlace": "plane",
"gaussian-blur": "0.25",
"adaptive-resize": "60",
},
},
}
_ = profiles

advanced = &cfg.MsAdvancedConfig{
Abort: false,
LabelsCFG: cfg.MsLabelsConfig{
Expand Down Expand Up @@ -444,5 +421,89 @@ var _ = Describe("PathFinder", Ordered, func() {
//
// NON-TRANSPARENT --output SPECIFIED
//

Entry(nil, &pfTE{
given: "🌀 TRANSFER: profile/output",
should: "return empty folder and file",
reasons: reasons{
folder: "no transfer required",
file: "input file left alone",
},
profile: "blur",
output: filepath.Join("foo", "sessions", "scan01", "results"),
supplements: supplements{
folder: filepath.Join("$TRASH$", "blur"),
},
actionTransfer: true,
assert: func(folder, file string, pi *common.PathInfo, statics *common.StaticInfo, entry *pfTE) {
Expect(folder).To(BeEmpty(), because(entry.reasons.folder, folder))
Expect(file).To(BeEmpty(), because(entry.reasons.file))
},
}),

Entry(nil, &pfTE{
given: "🎁 RESULT: profile/output",
should: "redirect result to output // supplement folder // not modify filename",
reasons: reasons{
folder: "result should be send to supplemented output folder",
file: "filename only needs to match input filename because the folder is supplemented",
},
profile: "blur",
output: filepath.Join("foo", "sessions", "scan01", "results"),
supplements: supplements{
folder: "blur",
},
assert: func(folder, file string, pi *common.PathInfo, statics *common.StaticInfo, entry *pfTE) {
supplemented := filing.SupplementFolder(
entry.output, entry.supplements.folder,
)
Expect(folder).To(Equal(supplemented), because(entry.reasons.folder, folder))
Expect(file).To(Equal(pi.Item.Extension.Name), because(entry.reasons.file))
},
}),

// === NON-TRANSPARENT / SCHEME (non-cuddle) [BLUE]

Entry(nil, &pfTE{
given: "🌀 TRANSFER: profile/output",
should: "return empty folder and file",
reasons: reasons{
folder: "no transfer required",
file: "input file left alone",
},
scheme: "blur-sf",
profile: "blur",
output: filepath.Join("foo", "sessions", "scan01", "results"),
supplements: supplements{
folder: filepath.Join("rubbish", "$TRASH$", "blur-sf", "blur"),
},
actionTransfer: true,
assert: func(folder, file string, pi *common.PathInfo, statics *common.StaticInfo, entry *pfTE) {
Expect(folder).To(BeEmpty(), because(entry.reasons.folder))
Expect(file).To(BeEmpty(), because(entry.reasons.file))
},
}),

// ...

Entry(nil, &pfTE{
given: "🌀 TRANSFER: profile/output",
should: "return empty folder and file",
reasons: reasons{
folder: "no transfer required",
file: "input file left alone",
},
scheme: "blur-sf",
profile: "sf",
output: filepath.Join("foo", "sessions", "scan01", "results"),
supplements: supplements{
folder: filepath.Join("rubbish", "$TRASH$", "blur-sf", "sf"),
},
actionTransfer: true,
assert: func(folder, file string, pi *common.PathInfo, statics *common.StaticInfo, entry *pfTE) {
Expect(folder).To(BeEmpty(), because(entry.reasons.folder))
Expect(file).To(BeEmpty(), because(entry.reasons.file))
},
}),
)
})

0 comments on commit 1e943b8

Please sign in to comment.