|
4 | 4 | package git |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "fmt" |
| 8 | + "os" |
7 | 9 | "testing" |
| 10 | + "time" |
8 | 11 |
|
9 | 12 | "github.com/pb33f/openapi-changes/model" |
10 | 13 | "github.com/stretchr/testify/assert" |
@@ -72,3 +75,40 @@ func TestReadFile(t *testing.T) { |
72 | 75 | assert.NoError(t, err) |
73 | 76 | assert.NotEmpty(t, contentRaw) |
74 | 77 | } |
| 78 | + |
| 79 | +func TestBuildCommitChangelog_IdenticalLeftRightPreservesSentinelCommit(t *testing.T) { |
| 80 | + specBytes := mustReadTestFile(t, "../sample-specs/petstorev3.json") |
| 81 | + progressChan := make(chan *model.ProgressUpdate, 32) |
| 82 | + errorChan := make(chan model.ProgressError, 32) |
| 83 | + |
| 84 | + commits := []*model.Commit{ |
| 85 | + { |
| 86 | + Hash: "right1", |
| 87 | + Message: "right", |
| 88 | + CommitDate: time.Now(), |
| 89 | + Data: specBytes, |
| 90 | + FilePath: "../sample-specs/petstorev3.json", |
| 91 | + }, |
| 92 | + { |
| 93 | + Hash: "left01", |
| 94 | + Message: "left", |
| 95 | + CommitDate: time.Now(), |
| 96 | + Data: specBytes, |
| 97 | + FilePath: "../sample-specs/petstorev3.json", |
| 98 | + }, |
| 99 | + } |
| 100 | + |
| 101 | + cleaned, errs := BuildCommitChangelog(commits, progressChan, errorChan, "", true, false, nil) |
| 102 | + require.Empty(t, errs) |
| 103 | + require.Len(t, cleaned, 1) |
| 104 | + assert.Nil(t, cleaned[0].Changes) |
| 105 | + assert.NotNil(t, cleaned[0].Document) |
| 106 | +} |
| 107 | + |
| 108 | +func mustReadTestFile(t *testing.T, path string) []byte { |
| 109 | + t.Helper() |
| 110 | + |
| 111 | + bits, err := os.ReadFile(path) |
| 112 | + require.NoError(t, err, fmt.Sprintf("read test file %s", path)) |
| 113 | + return bits |
| 114 | +} |
0 commit comments