|
| 1 | +<!-- gomarkdoc:embed:start --> |
| 2 | + |
| 3 | +<!-- Code generated by gomarkdoc. DO NOT EDIT --> |
| 4 | + |
| 5 | +# httpassert |
| 6 | + |
| 7 | +```go |
| 8 | +import "github.com/greenbone/opensight-golang-libraries/pkg/httpassert" |
| 9 | +``` |
| 10 | + |
| 11 | +## Index |
| 12 | + |
| 13 | +- [Constants](<#constants>) |
| 14 | +- [type Extractor](<#Extractor>) |
| 15 | + - [func ExtractTo\(ptr any\) Extractor](<#ExtractTo>) |
| 16 | +- [type Matcher](<#Matcher>) |
| 17 | + - [func Contains\(v string\) Matcher](<#Contains>) |
| 18 | + - [func HasSize\(e int\) Matcher](<#HasSize>) |
| 19 | +- [type Request](<#Request>) |
| 20 | + - [func New\(t \*testing.T, router http.Handler\) Request](<#New>) |
| 21 | +- [type Response](<#Response>) |
| 22 | + |
| 23 | + |
| 24 | +## Constants |
| 25 | + |
| 26 | +<a name="IgnoreJsonValue"></a> |
| 27 | + |
| 28 | +```go |
| 29 | +const IgnoreJsonValue = "<IGNORE>" |
| 30 | +``` |
| 31 | + |
| 32 | +<a name="Extractor"></a> |
| 33 | +## type [Extractor](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/extracter.go#L15>) |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +```go |
| 38 | +type Extractor func(t *testing.T, actual any) any |
| 39 | +``` |
| 40 | + |
| 41 | +<a name="ExtractTo"></a> |
| 42 | +### func [ExtractTo](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/extracter.go#L22>) |
| 43 | + |
| 44 | +```go |
| 45 | +func ExtractTo(ptr any) Extractor |
| 46 | +``` |
| 47 | + |
| 48 | +ExtractTo sets the value read from JSONPath into the given pointer variable. Example: |
| 49 | + |
| 50 | +``` |
| 51 | +var id string |
| 52 | +request.Expect().JsonPath("$.data.id", httpassert.ExtractTo(&id)) |
| 53 | +``` |
| 54 | + |
| 55 | +<a name="Matcher"></a> |
| 56 | +## type [Matcher](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L14>) |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +```go |
| 61 | +type Matcher func(t *testing.T, actual any) bool |
| 62 | +``` |
| 63 | + |
| 64 | +<a name="Contains"></a> |
| 65 | +### func [Contains](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L42>) |
| 66 | + |
| 67 | +```go |
| 68 | +func Contains(v string) Matcher |
| 69 | +``` |
| 70 | + |
| 71 | +Contains checks if a string contains the value Example: ExpectJsonPath\("$.data.name", httpassert.Contains\("foo"\)\) |
| 72 | + |
| 73 | +<a name="HasSize"></a> |
| 74 | +### func [HasSize](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/matcher.go#L18>) |
| 75 | + |
| 76 | +```go |
| 77 | +func HasSize(e int) Matcher |
| 78 | +``` |
| 79 | + |
| 80 | +HasSize checks the length of arrays, maps, or strings. Example: ExpectJsonPath\("$.data", httpassert.HasSize\(11\)\) |
| 81 | + |
| 82 | +<a name="Request"></a> |
| 83 | +## type [Request](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/request.go#L23-L55>) |
| 84 | + |
| 85 | +nolint:interfacebloat Request interface provides fluent HTTP request building. |
| 86 | + |
| 87 | +```go |
| 88 | +type Request interface { |
| 89 | + Get(path string) Request |
| 90 | + Getf(format string, a ...interface{}) Request |
| 91 | + Post(path string) Request |
| 92 | + Postf(format string, a ...interface{}) Request |
| 93 | + Put(path string) Request |
| 94 | + Putf(format string, a ...interface{}) Request |
| 95 | + Delete(path string) Request |
| 96 | + Deletef(format string, a ...interface{}) Request |
| 97 | + Options(path string) Request |
| 98 | + Optionsf(format string, a ...interface{}) Request |
| 99 | + Patch(path string) Request |
| 100 | + Patchf(format string, a ...interface{}) Request |
| 101 | + |
| 102 | + Perform(verb string, path string) Request |
| 103 | + Performf(verb string, path string, a ...interface{}) Request |
| 104 | + |
| 105 | + AuthHeader(header string) Request |
| 106 | + Headers(headers map[string]string) Request |
| 107 | + Header(key, value string) Request |
| 108 | + AuthJwt(jwt string) Request |
| 109 | + |
| 110 | + ContentType(string) Request |
| 111 | + |
| 112 | + Content(string) Request |
| 113 | + JsonContent(string) Request |
| 114 | + JsonContentObject(any) Request |
| 115 | + ContentFile(string) Request |
| 116 | + JsonContentFile(path string) Request |
| 117 | + |
| 118 | + Expect() Response |
| 119 | + ExpectEventually(check func(r Response), timeout time.Duration, interval time.Duration) Response |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +<a name="New"></a> |
| 124 | +### func [New](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/request.go#L119>) |
| 125 | + |
| 126 | +```go |
| 127 | +func New(t *testing.T, router http.Handler) Request |
| 128 | +``` |
| 129 | + |
| 130 | +New returns a new Request instance for the given router. |
| 131 | + |
| 132 | +<a name="Response"></a> |
| 133 | +## type [Response](<https://github.com/greenbone/opensight-golang-libraries/blob/main/pkg/httpassert/response.go#L24-L44>) |
| 134 | + |
| 135 | +nolint:interfacebloat Response interface provides fluent response assertions. |
| 136 | + |
| 137 | +```go |
| 138 | +type Response interface { |
| 139 | + StatusCode(int) Response |
| 140 | + |
| 141 | + JsonPath(string, any) Response |
| 142 | + JsonPathJson(path string, expectedJson string) Response |
| 143 | + |
| 144 | + ContentType(contentType string) Response |
| 145 | + |
| 146 | + NoContent() Response |
| 147 | + |
| 148 | + Json(json string) Response |
| 149 | + JsonTemplate(json string, values map[string]any) Response |
| 150 | + JsonTemplateFile(path string, values map[string]any) Response |
| 151 | + JsonFile(path string) Response |
| 152 | + |
| 153 | + Body(body string) Response |
| 154 | + GetJsonBodyObject(target any) Response |
| 155 | + GetBody() string |
| 156 | + |
| 157 | + Log() Response |
| 158 | +} |
| 159 | +``` |
| 160 | + |
| 161 | +Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>) |
| 162 | + |
| 163 | + |
| 164 | +<!-- gomarkdoc:embed:end --> |
0 commit comments