Skip to content

Commit

Permalink
test(persist): fix marshal coverage (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Oct 4, 2024
1 parent 5b720eb commit 1811fb7
Show file tree
Hide file tree
Showing 11 changed files with 763 additions and 222 deletions.
2 changes: 1 addition & 1 deletion director-resume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ var _ = Describe("Director(Resume)", Ordered, func() {
Files: files,
Folders: folders,
},
SampleType: enums.SampleTypeSlice,
Type: enums.SampleTypeSlice,
Iteration: pref.SamplingIterationOptions{
Each: func(_ *core.Node) bool { return false },
While: func(_ *pref.FilteredInfo) bool { return false },
Expand Down
4 changes: 2 additions & 2 deletions internal/feat/sampling/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func union(r *readResult) []fs.DirEntry {
)

both := lo.Ternary(
r.o.SampleInReverse, last, first,
r.o.InReverse, last, first,
)(noOfFiles, r.files)

noOfFolders := lo.Ternary(r.o.NoOf.Folders == 0,
uint(len(r.folders)), r.o.NoOf.Folders,
)
both = append(both, lo.Ternary(
r.o.SampleInReverse, last, first,
r.o.InReverse, last, first,
)(noOfFolders, r.folders)...)

return both
Expand Down
6 changes: 3 additions & 3 deletions internal/feat/sampling/navigator-sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ = Describe("feature", Ordered, func() {
},
},
tv.WithSamplingOptions(&pref.SamplingOptions{
SampleType: enums.SampleTypeSlice,
Type: enums.SampleTypeSlice,
NoOf: pref.EntryQuantities{
Files: 2,
Folders: 2,
Expand Down Expand Up @@ -129,8 +129,8 @@ var _ = Describe("feature", Ordered, func() {
},
},
tv.WithSamplingOptions(&pref.SamplingOptions{
SampleType: entry.SampleType,
SampleInReverse: entry.Reverse,
Type: entry.SampleType,
InReverse: entry.Reverse,
NoOf: pref.EntryQuantities{
Files: entry.NoOf.Files,
Folders: entry.NoOf.Folders,
Expand Down
8 changes: 4 additions & 4 deletions internal/opts/json/sampling-options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type (

// SamplingOptions
SamplingOptions struct {
// SampleType the type of sampling to use
SampleType enums.SampleType `json:"sample-type"`
// Type the type of sampling to use
Type enums.SampleType `json:"sample-type"`

// SampleInReverse determines the direction of iteration for the sampling
// InReverse determines the direction of iteration for the sampling
// operation
SampleInReverse bool `json:"sample-in-reverse"`
InReverse bool `json:"sample-in-reverse"`

// NoOf specifies number of items required in each sample (only applies
// when not using Custom iterator options)
Expand Down
16 changes: 8 additions & 8 deletions internal/persist/equals.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,19 @@ func equalBehaviours(o *pref.NavigationBehaviours, jo *json.NavigationBehaviours
}

func equalSampling(o *pref.SamplingOptions, jo *json.SamplingOptions) (bool, error) {
if o.SampleType != jo.SampleType {
if o.Type != jo.Type {
return false, fmt.Errorf("sampling %w", UnequalValueError[enums.SampleType]{
Field: "SampleType",
Value: o.SampleType,
Other: jo.SampleType,
Value: o.Type,
Other: jo.Type,
})
}

if o.SampleInReverse != jo.SampleInReverse {
if o.InReverse != jo.InReverse {
return false, fmt.Errorf("sampling %w", UnequalValueError[bool]{
Field: "SampleInReverse",
Value: o.SampleInReverse,
Other: jo.SampleInReverse,
Value: o.InReverse,
Other: jo.InReverse,
})
}

Expand Down Expand Up @@ -222,7 +222,7 @@ func equalFilterDef(filterName string,
}

if def != nil && jdef == nil {
return false, fmt.Errorf("filter-def %w",
return false, fmt.Errorf("json-filter-def %w",
UnequalPtrError[core.FilterDef, json.FilterDef]{
Field: "[nil jdef]",
Value: def,
Expand Down Expand Up @@ -291,7 +291,7 @@ func equalFilterDef(filterName string,
)
}

if def.Poly != nil {
if def.Poly != nil && jdef.Poly != nil {
if equal, err := equalFilterDef("poly", &def.Poly.File, &jdef.Poly.File); !equal {
return equal, err
}
Expand Down
20 changes: 16 additions & 4 deletions internal/persist/json-options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func ToJSON(o *pref.Options) *json.Options {
},
},
Sampling: json.SamplingOptions{
SampleType: o.Sampling.SampleType,
SampleInReverse: o.Sampling.SampleInReverse,
Type: o.Sampling.Type,
InReverse: o.Sampling.InReverse,
NoOf: json.EntryQuantities{
Files: o.Sampling.NoOf.Files,
Folders: o.Sampling.NoOf.Folders,
Expand Down Expand Up @@ -93,12 +93,24 @@ func NodeFilterDefToJSON(def *core.FilterDef) *json.FilterDef {
Negate: def.Negate,
Scope: def.Scope,
IfNotApplicable: def.IfNotApplicable,
Poly: NodePolyDefToJSON(def.Poly),
}
},
func() *json.FilterDef { return nil },
)
}

func NodePolyDefToJSON(poly *core.PolyFilterDef) *json.PolyFilterDef {
if poly == nil {
return nil
}

return &json.PolyFilterDef{
File: *NodeFilterDefToJSON(&poly.File),
Folder: *NodeFilterDefToJSON(&poly.Folder),
}
}

func FromJSON(o *json.Options) *pref.Options {
return &pref.Options{
Behaviours: pref.NavigationBehaviours{
Expand All @@ -115,8 +127,8 @@ func FromJSON(o *json.Options) *pref.Options {
},
},
Sampling: pref.SamplingOptions{
SampleType: o.Sampling.SampleType,
SampleInReverse: o.Sampling.SampleInReverse,
Type: o.Sampling.Type,
InReverse: o.Sampling.InReverse,
NoOf: pref.EntryQuantities{
Files: o.Sampling.NoOf.Files,
Folders: o.Sampling.NoOf.Folders,
Expand Down
Loading

0 comments on commit 1811fb7

Please sign in to comment.