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

Add tests and fix major version comment #95

Merged
merged 2 commits into from
Nov 30, 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
10 changes: 4 additions & 6 deletions post_results/misc-checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ type versionRecord struct {
type versionRecordSlice []versionRecord

func (s versionRecordSlice) MajorVersionChanges() string {
if len(s) == 0 {
return fmt.Sprintf("No major YANG version changes in commit %s", commitSHA)
}

var b strings.Builder
b.WriteString(fmt.Sprintf("Major YANG version changes in commit %s:\n", commitSHA))
for _, change := range s {
if change.OldMajorVersion != change.NewMajorVersion || change.NewVersion == "" {
b.WriteString(fmt.Sprintf("%s: `%s` -> `%s`\n", change.File, change.OldVersion, change.NewVersion))
}
}
return b.String()
if b.Len() == 0 {
return fmt.Sprintf("No major YANG version changes in commit %s", commitSHA)
}
return fmt.Sprintf("Major YANG version changes in commit %s:\n%s", commitSHA, b.String())
}

func (s versionRecordSlice) hasBreaking() bool {
Expand Down
81 changes: 81 additions & 0 deletions post_results/misc-checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,84 @@ func TestHasBreaking(t *testing.T) {
})
}
}

func TestMajorVersionChanges(t *testing.T) {
prevCommitSHA := commitSHA
commitSHA = "a0"
defer func() {
commitSHA = prevCommitSHA
}()
tests := []struct {
desc string
inVersions versionRecordSlice
wantMajorVersionChanges string
}{{
desc: "deleted",
inVersions: versionRecordSlice{{
File: "openconfig-deleted.yang",
OldMajorVersion: 1,
NewMajorVersion: 0,
OldVersion: "1.0.0",
NewVersion: "",
}},
wantMajorVersionChanges: "Major YANG version changes in commit a0:\nopenconfig-deleted.yang: `1.0.0` -> ``\n",
}, {
desc: "minor",
inVersions: versionRecordSlice{{
File: "openconfig-acl-submodule.yang",
OldMajorVersion: 1,
NewMajorVersion: 1,
OldVersion: "1.1.3",
NewVersion: "1.2.3",
}},
wantMajorVersionChanges: `No major YANG version changes in commit a0`,
}, {
desc: "patch",
inVersions: versionRecordSlice{{
File: "openconfig-acl.yang",
OldMajorVersion: 1,
NewMajorVersion: 1,
OldVersion: "1.2.2",
NewVersion: "1.2.3",
}},
wantMajorVersionChanges: `No major YANG version changes in commit a0`,
}, {
desc: "one",
inVersions: versionRecordSlice{{
File: "openconfig-interface-submodule.yang",
OldMajorVersion: 0,
NewMajorVersion: 1,
OldVersion: "0.5.0",
NewVersion: "1.0.0",
}},
wantMajorVersionChanges: "Major YANG version changes in commit a0:\nopenconfig-interface-submodule.yang: `0.5.0` -> `1.0.0`\n",
}, {
desc: "major",
inVersions: versionRecordSlice{{
File: "openconfig-interface.yang",
OldMajorVersion: 1,
NewMajorVersion: 2,
OldVersion: "1.1.3",
NewVersion: "2.0.0",
}},
wantMajorVersionChanges: "Major YANG version changes in commit a0:\nopenconfig-interface.yang: `1.1.3` -> `2.0.0`\n",
}, {
desc: "minor",
inVersions: versionRecordSlice{{
File: "openconfig-packet-match.yang",
OldMajorVersion: 1,
NewMajorVersion: 1,
OldVersion: "1.1.2",
NewVersion: "1.2.0",
}},
wantMajorVersionChanges: `No major YANG version changes in commit a0`,
}}

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
if got, want := tt.inVersions.MajorVersionChanges(), tt.wantMajorVersionChanges; got != want {
t.Errorf("got %v, want %v", got, want)
}
})
}
}
Loading