Skip to content

Commit

Permalink
fix(command): make cuddle incompatible with both trash and output (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Feb 16, 2024
1 parent 22ffbcd commit ae10b53
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 9 deletions.
15 changes: 15 additions & 0 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,21 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
//
// shrinkCommand.Args = validatePositionalArgs

// If we allowed --output to be specified with --cuddle, then that would
// mean the result files would be written to the output location and then input
// files would have to follow the results, leaving the origin without
// the input or the output. This could be seen as excessive and unnecessary.
// The cuddle option is most useful to the user when running a sample to
// enable easier comparison of the result with the input. If the user
// really wants to cuddle, then there should be no need to specify an output.
// We need to reduce the number of permutations to reduce complexity and
// the number of required unit tests; particularly for the path-finder.
// The same logic applies to cuddle with trash, except that's its even more
// acute in this usage scenario, because you never want your new results
// to be cuddled into the trash location.
paramSet.Command.MarkFlagsMutuallyExclusive("output", "cuddle")
paramSet.Command.MarkFlagsMutuallyExclusive("trash", "cuddle")

return shrinkCommand
}

Expand Down
46 changes: 37 additions & 9 deletions src/app/command/shrink-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ type commandTE struct {
outputFlag string
outputValue string
configPath string
expectError bool
}

type shrinkTE struct {
commandTE
directory string
}

func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root string) {
func assertShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root string) {
bootstrap := command.Bootstrap{
Vfs: vfs,
}
Expand Down Expand Up @@ -69,9 +70,16 @@ func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root
}

_, err := tester.Execute()
Expect(err).Error().To(BeNil(),
"should pass validation due to all flag being valid",
)

if entry.expectError {
Expect(err).Error().NotTo(BeNil(),
"expected error due to invalid flag combination",
)
} else {
Expect(err).Error().To(BeNil(),
"should pass validation due to all flag being valid",
)
}
}

var _ = Describe("ShrinkCmd", Ordered, func() {
Expand Down Expand Up @@ -99,7 +107,8 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
func(entry *shrinkTE) {
entry.directory = BackyardWorldsPlanet9Scan01
entry.configPath = configPath
expectValidShrinkCmdInvocation(vfs, entry, root)

assertShrinkCmdInvocation(vfs, entry, root)
},
func(entry *shrinkTE) string {
return fmt.Sprintf("🧪 ===> given: '%v'", entry.message)
Expand Down Expand Up @@ -242,6 +251,25 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}),

Entry(nil, &shrinkTE{
commandTE: commandTE{
message: "expect error since cuddle not compatible with output",
expectError: true,
args: []string{
"--cuddle", "--output", "results",
},
},
}),

Entry(nil, &shrinkTE{
commandTE: commandTE{
message: "expect error since cuddle not compatible with trash",
expectError: true,
args: []string{
"--cuddle", "--trash", "results",
},
},
}),
// <----
)

Expand All @@ -261,7 +289,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
assertShrinkCmdInvocation(vfs, entry, root)
})

It("🧪 should: execute successfully", func() {
Expand All @@ -276,7 +304,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
assertShrinkCmdInvocation(vfs, entry, root)
})
})

Expand All @@ -293,7 +321,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
assertShrinkCmdInvocation(vfs, entry, root)
})

It("🧪 should: execute successfully", func() {
Expand All @@ -308,7 +336,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
assertShrinkCmdInvocation(vfs, entry, root)
})
})
})
33 changes: 33 additions & 0 deletions src/app/proxy/filing/path-finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,39 @@ var _ = Describe("PathFinder", Ordered, func() {
},
}),

//
// === TRANSPARENT / ADHOC
//
Entry(nil, &pfTE{
given: "🌀 TRANSFER: transparent/adhoc/non-cuddled",
should: "redirect input to supplemented folder // filename not modified",
reasons: reasons{
folder: "transparency, result should take place of input in same folder",
file: "file should be moved out of the way and not cuddled",
},
supplements: supplements{
folder: filepath.Join("$TRASH$", "ADHOC"),
},
actionTransfer: true,
assert: func(folder, file string, pi *common.PathInfo, statics *common.StaticInfo, entry *pfTE) {
Expect(folder).To(Equal(filepath.Join(pi.Origin, entry.supplements.folder)), because(entry.reasons.folder))
Expect(file).To(Equal(pi.Item.Extension.Name), because(entry.reasons.file))
},
}),

Entry(nil, &pfTE{
given: "🎁 RESULT: transparent/adhoc",
should: "not modify folder // not modify filename",
reasons: reasons{
folder: "transparency, result should take place of input",
file: "file should be moved out of the way and not cuddled",
},
assert: func(folder, file string, pi *common.PathInfo, statics *common.StaticInfo, entry *pfTE) {
Expect(folder).To(Equal(pi.Origin), because(entry.reasons.folder))
Expect(file).To(Equal(pi.Item.Extension.Name), because(entry.reasons.file))
},
}),

//
// NON-TRANSPARENT
//
Expand Down

0 comments on commit ae10b53

Please sign in to comment.