MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / TestURLPlaceholders

Function TestURLPlaceholders

pkg/codegen/server_urls_test.go:15–38  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestURLPlaceholders(t *testing.T) {
16 t.Run("returns nil for a URL with no placeholders", func(t *testing.T) {
17 assert.Nil(t, urlPlaceholders("https://api.example.com/v1"))
18 })
19
20 t.Run("extracts a single placeholder", func(t *testing.T) {
21 got := urlPlaceholders("https://{host}.example.com/v1")
22 assert.Len(t, got, 1)
23 assert.Contains(t, got, "host")
24 })
25
26 t.Run("extracts multiple placeholders and dedupes repeats", func(t *testing.T) {
27 got := urlPlaceholders("https://{host}.example.com:{port}/{base}/{host}")
28 assert.Len(t, got, 3)
29 assert.Contains(t, got, "host")
30 assert.Contains(t, got, "port")
31 assert.Contains(t, got, "base")
32 })
33
34 t.Run("does not span across `/`", func(t *testing.T) {
35 // "{a/b}" must not be treated as a single placeholder named "a/b".
36 assert.Nil(t, urlPlaceholders("https://{a/b}.example.com"))
37 })
38}
39
40func TestUsedAndUndeclaredVariables(t *testing.T) {
41 srv := ServerObjectDefinition{

Callers

nothing calls this directly

Calls 3

urlPlaceholdersFunction · 0.85
RunMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected