Skip to content

Commit

Permalink
ref(proxy): use polt filter and refector tests (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Dec 27, 2023
1 parent b571714 commit 0d0b3e8
Show file tree
Hide file tree
Showing 10 changed files with 417 additions and 346 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/onsi/gomega v1.30.0
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.39.0
github.com/snivilised/extendio v0.5.0
github.com/snivilised/extendio v0.5.1
github.com/snivilised/lorax v0.4.2
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ github.com/snivilised/cobrass v0.4.1 h1:0CpC6eIIxj/x7UW3Ba3BCP35LyEamslOaimGxlTw
github.com/snivilised/cobrass v0.4.1/go.mod h1:WFbmSiPNREW3cP3cuZ3EJrDgMUKgHQw13RNv6rCgyoo=
github.com/snivilised/extendio v0.5.0 h1:XxUW125nGxkluVOekzWWpoE80r5KL0e+MFP2gjiXOhc=
github.com/snivilised/extendio v0.5.0/go.mod h1:jBaeTO9432bNbBKR4mbt2d7OGyrDPY/U45siM3VhTks=
github.com/snivilised/extendio v0.5.1 h1:CHvhyTboVOHLj8rm0ZF5dm3jPViHKPAKQxvnI8WzqAo=
github.com/snivilised/extendio v0.5.1/go.mod h1:jBaeTO9432bNbBKR4mbt2d7OGyrDPY/U45siM3VhTks=
github.com/snivilised/lorax v0.4.2 h1:jPo+o4cP/BUYBkR6sg3oLybHx0j2R+0wMLnvOf/gh0g=
github.com/snivilised/lorax v0.4.2/go.mod h1:vyhM905Fc4fzShAXPvykS8ZRnO6B85hd0emJgZE4iNY=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
Expand Down
25 changes: 10 additions & 15 deletions src/app/command/root-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/pixa/src/app/command"
"github.com/snivilised/pixa/src/internal/helpers"
"github.com/snivilised/pixa/src/internal/matchers"
)

type rootTE struct {
Expand All @@ -23,28 +22,24 @@ var _ = Describe("RootCmd", Ordered, func() {
repo string
l10nPath string
configPath string
nfs storage.VirtualFS
tester helpers.CommandTester
vfs storage.VirtualFS

tester helpers.CommandTester
)

BeforeAll(func() {
nfs = storage.UseNativeFS()
repo = helpers.Repo(filepath.Join("..", "..", ".."))

l10nPath = helpers.Path(repo, filepath.Join("test", "data", "l10n"))
Expect(matchers.AsDirectory(l10nPath)).To(matchers.ExistInFS(nfs))

configPath = filepath.Join(repo, "test", "data", "configuration")
Expect(matchers.AsDirectory(configPath)).To(matchers.ExistInFS(nfs))

if err := helpers.UseI18n(l10nPath); err != nil {
Fail(err.Error())
}
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
})

BeforeEach(func() {
vfs, _, _ = helpers.SetupTest(
"nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent,
)

bootstrap := command.Bootstrap{
Vfs: nfs,
Vfs: vfs,
}
tester = helpers.CommandTester{
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
Expand Down
111 changes: 60 additions & 51 deletions src/app/command/shrink-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,51 @@ import (

"github.com/snivilised/pixa/src/app/command"
"github.com/snivilised/pixa/src/internal/helpers"
"github.com/snivilised/pixa/src/internal/matchers"

"github.com/snivilised/extendio/xfs/storage"
)

const (
BackyardWorldsPlanet9Scan01 = "nasa/exo/Backyard Worlds - Planet 9/sessions/scan-01"
)

type commandTE struct {
message string
args []string
configPath string
message string
args []string
trashFlag string
trashValue string
outputFlag string
outputValue string
configPath string
}

type shrinkTE struct {
commandTE
directory string
}

func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE) {
func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root string) {
bootstrap := command.Bootstrap{
Vfs: vfs,
}

// we also prepend the directory name to the command line
//
options := append([]string{helpers.ShrinkCommandName, entry.directory}, []string{
directory := helpers.Path(root, entry.directory)
args := append([]string{helpers.ShrinkCommandName, directory}, []string{
"--dry-run", "--mode", "tidy",
}...)

if entry.outputFlag != "" && entry.outputValue != "" {
output := helpers.Path(root, entry.outputValue)
args = append(args, entry.outputFlag, output)
}

if entry.trashFlag != "" && entry.trashValue != "" {
trash := helpers.Path(root, entry.trashValue)
args = append(args, entry.trashFlag, trash)
}

tester := helpers.CommandTester{
Args: append(options, entry.args...),
Args: append(args, entry.args...),
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
co.Program = &ExecutorStub{
Expand All @@ -59,34 +75,27 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
repo string
l10nPath string
configPath string
nfs storage.VirtualFS
root string
vfs storage.VirtualFS
)

BeforeAll(func() {
nfs = storage.UseNativeFS()
repo = helpers.Repo(filepath.Join("..", "..", ".."))

l10nPath = helpers.Path(repo, filepath.Join("test", "data", "l10n"))
Expect(matchers.AsDirectory(l10nPath)).To(matchers.ExistInFS(nfs))

configPath = filepath.Join(repo, "test", "data", "configuration")
Expect(matchers.AsDirectory(configPath)).To(matchers.ExistInFS(nfs))
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
})

BeforeEach(func() {
if err := helpers.UseI18n(l10nPath); err != nil {
Fail(err.Error())
}
vfs, root, _ = helpers.SetupTest(
"nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent,
)
})

DescribeTable("ShrinkCmd",
func(entry *shrinkTE) {
// set directory here, because during discovery phase of unit test ,
// l10nPath is not set, so we can't set it inside the Entry
//
entry.directory = l10nPath
entry.directory = BackyardWorldsPlanet9Scan01
entry.configPath = configPath
expectValidShrinkCmdInvocation(nfs, entry)
expectValidShrinkCmdInvocation(vfs, entry, root)
},
func(entry *shrinkTE) string {
return fmt.Sprintf("🧪 ===> given: '%v'", entry.message)
Expand Down Expand Up @@ -177,64 +186,64 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
When("with general long form parameters", func() {
It("🧪 should: execute successfully", func() {
entry := &shrinkTE{
directory: l10nPath,
directory: BackyardWorldsPlanet9Scan01,
commandTE: commandTE{
message: "with general long form parameters",
args: []string{
"--output", l10nPath,
},
configPath: configPath,
message: "with general long form parameters",
args: []string{},
outputFlag: "--output",
outputValue: "output",
configPath: configPath,
},
}

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

It("🧪 should: execute successfully", func() {
entry := &shrinkTE{
directory: l10nPath,
directory: BackyardWorldsPlanet9Scan01,
commandTE: commandTE{
message: "with general long form parameters",
args: []string{
"--trash", l10nPath,
},
message: "with general long form parameters",
args: []string{},
trashFlag: "--trash",
trashValue: "discard",
configPath: configPath,
},
}

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

When("with general short form parameters", func() {
It("🧪 should: execute successfully", func() {
entry := &shrinkTE{
directory: l10nPath,
directory: BackyardWorldsPlanet9Scan01,
commandTE: commandTE{
message: "with general short form parameters",
args: []string{
"-o", l10nPath,
},
configPath: configPath,
message: "with general short form parameters",
args: []string{},
outputFlag: "-o",
outputValue: "output",
configPath: configPath,
},
}

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

It("🧪 should: execute successfully", func() {
entry := &shrinkTE{
directory: l10nPath,
directory: BackyardWorldsPlanet9Scan01,
commandTE: commandTE{
message: "with general short form parameters",
args: []string{
"-t", l10nPath,
},
message: "with general short form parameters",
args: []string{},
trashFlag: "-t",
trashValue: "discard",
configPath: configPath,
},
}

expectValidShrinkCmdInvocation(nfs, entry)
expectValidShrinkCmdInvocation(vfs, entry, root)
})
})
})
Loading

0 comments on commit 0d0b3e8

Please sign in to comment.