@@ -5,6 +5,8 @@ package cmd
55
66import (
77 "encoding/json"
8+ "net/http"
9+ "net/http/httptest"
810 "path/filepath"
911 "strings"
1012 "testing"
@@ -20,7 +22,6 @@ func TestGenerateHTMLReport_UnchangedLeftRight(t *testing.T) {
2022 "../sample-specs/petstorev3.json" ,
2123 "../sample-specs/petstorev3.json" ,
2224 summaryOpts {noColor : true },
23- nil ,
2425 )
2526 require .NoError (t , err )
2627
@@ -37,7 +38,6 @@ func TestGenerateHTMLReport_LeftRightIncludesSanitizedPaths(t *testing.T) {
3738 "../sample-specs/petstorev3-original.json" ,
3839 "../sample-specs/petstorev3.json" ,
3940 summaryOpts {noColor : true },
40- nil ,
4141 )
4242 require .NoError (t , err )
4343
@@ -54,6 +54,54 @@ func TestGenerateHTMLReport_LeftRightIncludesSanitizedPaths(t *testing.T) {
5454 assert .Contains (t , content , "<!DOCTYPE html" )
5555}
5656
57+ func TestGenerateHTMLReport_LeftRightPreservesGitRefPaths (t * testing.T ) {
58+ repoDir := createGitSpecRepo (t )
59+ chdirForTest (t , repoDir )
60+
61+ commits , err := loadLeftRightCommits (
62+ "HEAD~1:openapi.yaml" ,
63+ "HEAD:openapi.yaml" ,
64+ summaryOpts {noColor : true },
65+ )
66+ require .NoError (t , err )
67+
68+ report , err := generateHTMLReport (commits , nil , true ,
69+ "HEAD~1:openapi.yaml" ,
70+ "HEAD:openapi.yaml" ,
71+ )
72+ require .NoError (t , err )
73+ require .NotNil (t , report )
74+
75+ content := string (report )
76+ assert .Contains (t , content , `"originalPath":"HEAD~1:openapi.yaml"` )
77+ assert .Contains (t , content , `"modifiedPath":"HEAD:openapi.yaml"` )
78+ }
79+
80+ func TestGenerateHTMLReport_LeftRightPreservesURLPaths (t * testing.T ) {
81+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
82+ if r .URL .Path == "/left.yaml" {
83+ _ , _ = w .Write ([]byte ("openapi: 3.0.3\n info:\n title: Left\n version: '1.0'\n paths: {}\n " ))
84+ return
85+ }
86+ _ , _ = w .Write ([]byte ("openapi: 3.0.3\n info:\n title: Right\n version: '1.1'\n paths:\n /pets:\n get:\n responses:\n \" 200\" :\n description: ok\n " ))
87+ }))
88+ defer server .Close ()
89+
90+ leftURL := server .URL + "/left.yaml"
91+ rightURL := server .URL + "/right.yaml"
92+
93+ commits , err := loadLeftRightCommits (leftURL , rightURL , summaryOpts {noColor : true })
94+ require .NoError (t , err )
95+
96+ report , err := generateHTMLReport (commits , nil , true , leftURL , rightURL )
97+ require .NoError (t , err )
98+ require .NotNil (t , report )
99+
100+ content := string (report )
101+ assert .Contains (t , content , `"originalPath":"` + leftURL + `"` )
102+ assert .Contains (t , content , `"modifiedPath":"` + rightURL + `"` )
103+ }
104+
57105func TestBuildHTMLReportItems_AllCommitsFail (t * testing.T ) {
58106 items , err := buildHTMLReportItems ([]* model.Commit {makeSwagger2Commit (t )}, nil )
59107 require .Error (t , err )
@@ -66,7 +114,6 @@ func TestBuildHTMLReportItems_PartialFailureReturnsPartialResults(t *testing.T)
66114 "../sample-specs/petstorev3-original.json" ,
67115 "../sample-specs/petstorev3.json" ,
68116 summaryOpts {noColor : true },
69- nil ,
70117 )
71118 require .NoError (t , err )
72119 require .NotEmpty (t , commits )
@@ -88,7 +135,6 @@ func TestGenerateHTMLReport_PartialFailureReturnsPartialReport(t *testing.T) {
88135 "../sample-specs/petstorev3-original.json" ,
89136 "../sample-specs/petstorev3.json" ,
90137 summaryOpts {noColor : true },
91- nil ,
92138 )
93139 require .NoError (t , err )
94140 require .NotEmpty (t , commits )
@@ -136,7 +182,6 @@ func TestBuildHTMLReportItems_PreservesSchemaNodesInDocumentTree(t *testing.T) {
136182 "../sample-specs/petstorev3-original.json" ,
137183 "../sample-specs/petstorev3.json" ,
138184 summaryOpts {noColor : true },
139- nil ,
140185 )
141186 require .NoError (t , err )
142187 require .NotEmpty (t , commits )
@@ -179,7 +224,6 @@ func TestBuildHTMLReportItems_SplitsStandardAndChangeExplorerGraphs(t *testing.T
179224 "../sample-specs/petstorev3-original.json" ,
180225 "../sample-specs/petstorev3.json" ,
181226 summaryOpts {noColor : true },
182- nil ,
183227 )
184228 require .NoError (t , err )
185229 require .NotEmpty (t , commits )
0 commit comments