Skip to content

Commit

Permalink
Remove fileOptionArray sort() function as there's no priorities anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Kubaczyk committed Mar 31, 2023
1 parent 80ffa89 commit 7a72623
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 53 deletions.
10 changes: 0 additions & 10 deletions internal/app/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"os"
"sort"
"strings"
)

Expand Down Expand Up @@ -45,14 +44,6 @@ func (f *fileOptionArray) Set(value string) error {
return nil
}

func (f fileOptionArray) sort() {
log.Verbose("Sorting files listed in the -spec file based on their priorities... ")

sort.SliceStable(f, func(i, j int) bool {
return (f)[i].priority < (f)[j].priority
})
}

func (i *stringArray) String() string {
return strings.Join(*i, " ")
}
Expand Down Expand Up @@ -279,7 +270,6 @@ func (c *cli) readState(s *State) error {
}
c.files = append(c.files, fo)
}
c.files.sort()
}

// read the TOML/YAML desired state file
Expand Down
43 changes: 0 additions & 43 deletions internal/app/spec_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,3 @@ func Test_specFromYAML(t *testing.T) {
})
}
}

func Test_specFileSort(t *testing.T) {
type args struct {
files fileOptionArray
}
tests := []struct {
name string
args args
want [3]int
}{
{
name: "test case 1 -- Files sorted by priority",
args: args{
files: fileOptionArray(
[]fileOption{
{"third.yaml", 0},
{"first.yaml", -20},
{"second.yaml", -10},
}),
},
want: [3]int{-20, -10, 0},
},
}

teardownTestCase, err := setupStateFileTestCase(t)
if err != nil {
t.Fatal(err)
}
defer teardownTestCase(t)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.args.files.sort()

got := [3]int{}
for i, f := range tt.args.files {
got[i] = f.priority
}
if got != tt.want {
t.Errorf("files from spec file are not sorted by priority = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 7a72623

Please sign in to comment.