MCPcopy
hub / github.com/grafana/dskit / TestURLValueYAML

Function TestURLValueYAML

flagext/url_test.go:11–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestURLValueYAML(t *testing.T) {
12 // Test embedding of URLValue.
13 {
14 type TestStruct struct {
15 URL URLValue `yaml:"url"`
16 }
17
18 var testStruct TestStruct
19 require.NoError(t, testStruct.URL.Set("http://google.com"))
20 expected := []byte(`url: http://google.com
21`)
22
23 actual, err := yaml.Marshal(testStruct)
24 require.NoError(t, err)
25 assert.Equal(t, expected, actual)
26
27 var actualStruct TestStruct
28 err = yaml.Unmarshal(expected, &actualStruct)
29 require.NoError(t, err)
30 assert.Equal(t, testStruct, actualStruct)
31 }
32
33 // Test pointers of URLValue.
34 {
35 type TestStruct struct {
36 URL *URLValue `yaml:"url"`
37 }
38
39 var testStruct TestStruct
40 testStruct.URL = &URLValue{}
41 require.NoError(t, testStruct.URL.Set("http://google.com"))
42 expected := []byte(`url: http://google.com
43`)
44
45 actual, err := yaml.Marshal(testStruct)
46 require.NoError(t, err)
47 assert.Equal(t, expected, actual)
48
49 var actualStruct TestStruct
50 err = yaml.Unmarshal(expected, &actualStruct)
51 require.NoError(t, err)
52 assert.Equal(t, testStruct, actualStruct)
53 }
54
55 // Test no url set in URLValue.
56 {
57 type TestStruct struct {
58 URL URLValue `yaml:"url"`
59 }
60
61 var testStruct TestStruct
62 expected := []byte(`url: ""
63`)
64
65 actual, err := yaml.Marshal(testStruct)
66 require.NoError(t, err)
67 assert.Equal(t, expected, actual)
68

Callers

nothing calls this directly

Calls 4

SetMethod · 0.65
MarshalMethod · 0.45
EqualMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected