Atlas › Test
single_link
Exact test identity: go.temporal.io/server/common/nexus/nexusrpc/TestAddLinksToHeader/single_link
- Package
go.temporal.io/server/common/nexus/nexusrpc
- Suite / test hierarchy
TestAddLinksToHeader/single_link
- Test
single_link
- Introduced at
- api.go ×1 Frontier kind: Joint frontier
- Covered ranges
- 13
- Covered lines
- 20
- 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 20 covered LOC · 13 ranges
Open complete file
77
}
78
79
>
func addLinksToHTTPHeader(links []nexus.Link, httpHeader http.Header) error {
api.go
80
>
for _, link := range links {
81
>
encodedLink, err := encodeLink(link)
api.go
82
>
if err != nil {
83
return err
84
}
85
>
httpHeader.Add(headerLink, encodedLink)
api.go
86
}
88
}
89
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
}
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
}
252
}
253