Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample list: sort samples by name #103

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions acceptance/scenario_sample_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func TestAcc_Cmd_Scenario_Sample_List(t *testing.T) {
Samples: []*pb.Ref_Sample{
{
Id: &pb.Sample_ID{
Name: "minimal",
Name: "complex",
},
},
{
Id: &pb.Sample_ID{
Name: "complex",
Name: "minimal",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/flightplan/sample_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (s *sampleSubsetObsSpec) size() int32 {
return s.space + s.taken
}

// Convert our sample frame into a collection of subsetWithCapSpace that we can use for determine
// Convert our sample frame into a collection of subset specs that we can use for determine
// how many elements we should take from each subset.
func sampleFrameToSubsetSpecs(frame *SampleFrame) []*sampleSubsetObsSpec {
subsetSpecs := []*sampleSubsetObsSpec{}
Expand Down
6 changes: 6 additions & 0 deletions internal/server/service_v1_list_samples.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package server

import (
"cmp"
"context"
"slices"

"github.com/hashicorp/enos/internal/diagnostics"
"github.com/hashicorp/enos/internal/flightplan"
Expand Down Expand Up @@ -37,6 +39,10 @@ func (s *ServiceV1) ListSamples(
for _, s := range fp.Samples {
res.Samples = append(res.Samples, s.Ref())
}

slices.SortStableFunc(res.Samples, func(a, b *pb.Ref_Sample) int {
return cmp.Compare(a.GetId().GetName(), b.GetId().GetName())
})
}

return res, nil
Expand Down