Atlas › Test

valid_custom_URL

Exact test identity: go.temporal.io/server/common/nexus/nexusrpc/TestEncodeLink/valid_custom_URL

Package
go.temporal.io/server/common/nexus/nexusrpc
Suite / test hierarchy
TestEncodeLink/valid_custom_URL
Test
valid_custom_URL
Introduced at
api.go ×1 Frontier kind: Joint frontier
Covered ranges
9
Covered lines
14
Covered files
1

Co-introduced tests

1 other test enter at the same concept.

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/nexus/nexusrpc/api.go 14 covered LOC · 9 ranges

Open complete file

140 // decodeLink encodes the link to Nexus-Link header value.
141 // It follows the same format of HTTP Link header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
142 > func encodeLink(link nexus.Link) (string, error) { api.go
143 > if err := validateLinkURL(link.URL); err != nil {
144 return "", fmt.Errorf("failed to encode link: %w", err)
145 }
146 > if err := validateLinkType(link.Type); err != nil { api.go
147 return "", fmt.Errorf("failed to encode link: %w", err)
148 }
149 > return fmt.Sprintf(`<%s>; %s="%s"`, link.URL.String(), linkTypeKey, link.Type), nil api.go
150 }
151
229 }
230
231 > func validateLinkURL(value *url.URL) error { api.go
232 > if value == nil || value.String() == "" {
233 return errors.New("url is empty")
234 }
235 > _, err := url.ParseQuery(value.RawQuery) api.go
236 > if err != nil {
237 return fmt.Errorf("url query not percent-encoded: %s", value)
238 }
239 > return nil api.go
240 }
241
242 > func validateLinkType(value string) error { api.go
243 > if len(value) == 0 {
244 return errors.New("link type is empty")
245 }
246 > for _, c := range value { api.go
247 > if (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c < '0' || c > '9') && c != '_' && c != '.' && c != '/' {
248 return errors.New("link type contains invalid char (valid chars: alphanumeric, '_', '.', '/')")
249 }
250 }
251 > return nil api.go
252 }
253