@@ -11,15 +11,20 @@ import "github.com/greenbone/opensight-golang-libraries/pkg/httpassert"
1111## Index
1212
1313- [ Constants] ( < #constants > )
14+ - [ func AssertJSONCanonicalEq\( t \* testing.T, expected, actual string\) bool] ( < #AssertJSONCanonicalEq > )
15+ - [ func NormalizeJSON\( t \* testing.T, s string\) string] ( < #NormalizeJSON > )
1416- [ type Extractor] ( < #Extractor > )
1517 - [ func ExtractRegexTo\( value string, ptr any\) Extractor] ( < #ExtractRegexTo > )
1618 - [ func ExtractTo\( ptr any\) Extractor] ( < #ExtractTo > )
1719- [ type Matcher] ( < #Matcher > )
1820 - [ func Contains\( v string\) Matcher] ( < #Contains > )
1921 - [ func HasSize\( e int\) Matcher] ( < #HasSize > )
22+ - [ func IsUUID\(\) Matcher] ( < #IsUUID > )
23+ - [ func NotEmpty\(\) Matcher] ( < #NotEmpty > )
2024 - [ func Regex\( expr string\) Matcher] ( < #Regex > )
2125- [ type Request] ( < #Request > )
22- - [ func New\( t \* testing.T, router http.Handler\) Request] ( < #New > )
26+ - [ type RequestStart] ( < #RequestStart > )
27+ - [ func New\( t \* testing.T, router http.Handler\) RequestStart] ( < #New > )
2328- [ type Response] ( < #Response > )
2429
2530
@@ -31,6 +36,24 @@ import "github.com/greenbone/opensight-golang-libraries/pkg/httpassert"
3136const IgnoreJsonValue = " <IGNORE>"
3237```
3338
39+ <a name =" AssertJSONCanonicalEq " ></a >
40+ ## func [ AssertJSONCanonicalEq] ( < https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/assert.go#L32 > )
41+
42+ ``` go
43+ func AssertJSONCanonicalEq (t *testing .T , expected , actual string ) bool
44+ ```
45+
46+ AssertJSONCanonicalEq compares two JSON strings by normalizing both first. On mismatch, it prints a readable diff of the normalized forms.
47+
48+ <a name="NormalizeJSON"></a>
49+ ## func [NormalizeJSON](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/assert.go#L15>)
50+
51+ ```go
52+ func NormalizeJSON(t *testing.T, s string) string
53+ ```
54+
55+ NormalizeJSON parses JSON and re\-marshals it with stable key ordering and indentation. \- Uses Decoder.UseNumber\(\) to preserve numeric fidelity \(avoid float64 surprises\).
56+
3457<a name="Extractor"></a>
3558## type [Extractor](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/extracter.go#L16>)
3659
@@ -64,7 +87,7 @@ request.Expect().JsonPath("$.data.id", httpassert.ExtractTo(&id))
6487```
6588
6689<a name="Matcher"></a>
67- ## type [Matcher](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L15 >)
90+ ## type [Matcher](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L16 >)
6891
6992
7093
@@ -73,39 +96,84 @@ type Matcher func(t *testing.T, actual any) bool
7396```
7497
7598<a name="Contains"></a>
76- ### func [Contains](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L43 >)
99+ ### func [Contains](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L44 >)
77100
78101```go
79102func Contains(v string) Matcher
80103```
81104
82- Contains checks if a string contains the value Example: ExpectJsonPath \("$.data.name", httpassert.Contains\("foo"\)\)
105+ Contains checks if a string contains the value Example: JsonPath \("$.data.name", httpassert.Contains\("foo"\)\)
83106
84107<a name="HasSize"></a>
85- ### func [HasSize](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L19 >)
108+ ### func [HasSize](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L20 >)
86109
87110```go
88111func HasSize(e int) Matcher
89112```
90113
91- HasSize checks the length of arrays, maps, or strings. Example: ExpectJsonPath\("$.data", httpassert.HasSize\(11\)\)
114+ HasSize checks the length of arrays, maps, or strings. Example: JsonPath\("$.data", httpassert.HasSize\(11\)\)
115+
116+ <a name="IsUUID"></a>
117+ ### func [IsUUID](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L76>)
118+
119+ ```go
120+ func IsUUID() Matcher
121+ ```
122+
123+ IsUUID checks if a string is a UUID Example: JsonPath\("$.id", httpassert.IsUUID\(\)\)
124+
125+ <a name="NotEmpty"></a>
126+ ### func [NotEmpty](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L63>)
127+
128+ ```go
129+ func NotEmpty() Matcher
130+ ```
131+
132+ NotEmpty checks if a string is not empty Example: JsonPath\("$.data.name", httpassert.NotEmpty\(\)\)
92133
93134<a name="Regex"></a>
94- ### func [Regex](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L52 >)
135+ ### func [Regex](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L53 >)
95136
96137```go
97138func Regex(expr string) Matcher
98139```
99140
100- Regex checks if a string matches the given regular expression Example: ExpectJsonPath \("$.data.name", httpassert.Regex\("^foo.\*bar$"\)\)
141+ Regex checks if a string matches the given regular expression Example: JsonPath \("$.data.name", httpassert.Regex\("^foo.\*bar$"\)\)
101142
102143<a name="Request"></a>
103- ## type [Request](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/request.go#L23-L55 >)
144+ ## type [Request](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/request.go#L47-L65 >)
104145
105- nolint:interfacebloat Request interface provides fluent HTTP request building.
146+ nolint:interfacebloat Request provides fluent request configuration
106147
107148```go
108149type Request interface {
150+ AuthHeader (header string ) Request
151+ Headers (headers map [string ]string ) Request
152+ Header (key, value string ) Request
153+ AuthJwt (jwt string ) Request
154+
155+ ContentType (string ) Request
156+
157+ Content (string ) Request
158+ ContentFile (string ) Request
159+
160+ JsonContent (string ) Request
161+ JsonContentTemplate (body string , values map [string ]any) Request
162+ JsonContentObject (any) Request
163+ JsonContentFile (path string ) Request
164+
165+ Expect () Response
166+ ExpectEventually (check func (r Response), timeout time.Duration , interval time.Duration ) Response
167+ }
168+ ```
169+
170+ <a name =" RequestStart " ></a >
171+ ## type [ RequestStart] ( < https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/request.go#L27-L43 > )
172+
173+ nolint: interfacebloat RequestStart provides fluent HTTP \* method \+ path\* selection. Each call returns a fresh Request
174+
175+ ``` go
176+ type RequestStart interface {
109177 Get (path string ) Request
110178 Getf (format string , a ...interface {}) Request
111179 Post (path string ) Request
@@ -121,33 +189,17 @@ type Request interface {
121189
122190 Perform (verb string , path string ) Request
123191 Performf (verb string , path string , a ...interface {}) Request
124-
125- AuthHeader (header string ) Request
126- Headers (headers map [string ]string ) Request
127- Header (key, value string ) Request
128- AuthJwt (jwt string ) Request
129-
130- ContentType (string ) Request
131-
132- Content (string ) Request
133- JsonContent (string ) Request
134- JsonContentObject (any) Request
135- ContentFile (string ) Request
136- JsonContentFile (path string ) Request
137-
138- Expect () Response
139- ExpectEventually (check func (r Response), timeout time.Duration , interval time.Duration ) Response
140192}
141193```
142194
143195<a name =" New " ></a >
144- ### func [ New] ( < https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/request.go#L119 > )
196+ ### func [ New] ( < https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/request.go#L95 > )
145197
146198``` go
147- func New (t *testing .T , router http .Handler ) Request
199+ func New (t *testing .T , router http .Handler ) RequestStart
148200```
149201
150- New returns a new Request instance for the given router.
202+ New returns a new RequestStart instance for the given router. All method calls \(Get/Post/...\) return a \*fresh\* Request .
151203
152204<a name="Response"></a>
153205## type [Response](<https:// github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/response.go#L24-L46>)
0 commit comments