1package main
2
3import (
4	"github.com/aws/aws-sdk-go-v2/internal/repotools/changelog"
5	"github.com/aws/aws-sdk-go-v2/internal/repotools/release"
6	"github.com/google/go-cmp/cmp"
7	"testing"
8)
9
10func Test_sortAnnotations(t *testing.T) {
11	annotations := []changelog.Annotation{
12		{Type: changelog.DependencyChangeType, Description: "b"},
13		{Type: changelog.DependencyChangeType, Description: "a"},
14		{Type: changelog.DocumentationChangeType, Description: "c"},
15		{Type: changelog.BugFixChangeType, Description: "d"},
16		{Type: changelog.FeatureChangeType, Description: "e"},
17		{Type: changelog.ReleaseChangeType, Description: "f"},
18		{Type: changelog.AnnouncementChangeType, Description: "g"},
19	}
20
21	want := []changelog.Annotation{
22		{Type: changelog.AnnouncementChangeType, Description: "g"},
23		{Type: changelog.ReleaseChangeType, Description: "f"},
24		{Type: changelog.FeatureChangeType, Description: "e"},
25		{Type: changelog.BugFixChangeType, Description: "d"},
26		{Type: changelog.DocumentationChangeType, Description: "c"},
27		{Type: changelog.DependencyChangeType, Description: "a"},
28		{Type: changelog.DependencyChangeType, Description: "b"},
29	}
30
31	sortAnnotations(annotations)
32
33	if diff := cmp.Diff(annotations, want); len(diff) > 0 {
34		t.Error(diff)
35	}
36}
37
38func Test_filterUnreferencedAnnotations(t *testing.T) {
39	manifest := release.Manifest{
40		Modules: map[string]release.ModuleManifest{
41			"foo": {
42				Annotations: []string{"a", "c"},
43			},
44			"bar": {
45				Annotations: []string{"c"},
46			},
47		},
48	}
49
50	annotations := []changelog.Annotation{{ID: "a"}, {ID: "b"}, {ID: "c"}}
51	wantFiltered := []changelog.Annotation{{ID: "a"}, {ID: "c"}}
52
53	gotFiltered := filterUnreferencedAnnotations(manifest, annotations)
54
55	if diff := cmp.Diff(wantFiltered, gotFiltered); len(diff) > 0 {
56		t.Error(diff)
57	}
58}
59