Skip to content

Action changelogs are not sorted by version numbers #5351

@mcwarman

Description

@mcwarman

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When testing a PR I noticed the sort doesn't work for version numbers.

I was testing with updatecli with an update from v0.99.0 to v0.100.0

The version numbers where outputted in the following order:

  • v0.100.0
  • v0.101.0
  • v0.99.0

Expected Behavior

  • v0.101.0
  • v0.100.0
  • v0.99.0

Steps To Reproduce

pkg/core/reports/action_test.go

func TestToActionSort(t *testing.T) {
	tests := []struct {
		name           string
		report         Action
		expectedOutput Action
	}{
		{
			name: "version sort",
			report: Action{
				Targets: []ActionTarget{
					{
						Changelogs: []ActionTargetChangelog{
							{
								Title: "v0.100.0",
							},
							{
								Title: "v0.99.0",
							},
							{
								Title: "v0.101.0",
							},
						},
					},
				},
			},
			expectedOutput: Action{
				Targets: []ActionTarget{
					{
						Changelogs: []ActionTargetChangelog{
							{
								Title: "v0.101.0",
							},
							{
								Title: "v0.100.0",
							},
							{
								Title: "v0.99.0",
							},
						},
					},
				},
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			report := tt.report
			report.sort()
			assert.Equal(t, tt.expectedOutput, report)
		})
	}
}
go test
--- FAIL: TestToActionSort (0.00s)
    --- FAIL: TestToActionSort/version_sort (0.00s)
        action_test.go:638: 
                Error Trace:    /home/matthew/code/src/github.com/updatecli/updatecli/pkg/core/reports/action_test.go:638
                Error:          Not equal: 
                                expected: reports.Action{ID:"", Title:"", PipelineTitle:"", Description:"", Targets:[]reports.ActionTarget{reports.ActionTarget{ID:"", Title:"", Description:"", Changelogs:[]reports.ActionTargetChangelog{reports.ActionTargetChangelog{Title:"v0.101.0", Description:""}, reports.ActionTargetChangelog{Title:"v0.100.0", Description:""}, reports.ActionTargetChangelog{Title:"v0.99.0", Description:""}}}}, PipelineURL:(*reports.PipelineURL)(nil), Link:""}
                                actual  : reports.Action{ID:"", Title:"", PipelineTitle:"", Description:"", Targets:[]reports.ActionTarget{reports.ActionTarget{ID:"", Title:"", Description:"", Changelogs:[]reports.ActionTargetChangelog{reports.ActionTargetChangelog{Title:"v0.100.0", Description:""}, reports.ActionTargetChangelog{Title:"v0.101.0", Description:""}, reports.ActionTargetChangelog{Title:"v0.99.0", Description:""}}}}, PipelineURL:(*reports.PipelineURL)(nil), Link:""}
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -12,3 +12,3 @@
                                     (reports.ActionTargetChangelog) {
                                -     Title: (string) (len=8) "v0.101.0",
                                +     Title: (string) (len=8) "v0.100.0",
                                      Description: (string) ""
                                @@ -16,3 +16,3 @@
                                     (reports.ActionTargetChangelog) {
                                -     Title: (string) (len=8) "v0.100.0",
                                +     Title: (string) (len=8) "v0.101.0",
                                      Description: (string) ""
                Test:           TestToActionSort/version_sort
FAIL
exit status 1
FAIL    github.com/updatecli/updatecli/pkg/core/reports 0.008s

Environment

- OS: WSL Debian
- updatecli: v0.101.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions