MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestConfigDiffHandler

Function TestConfigDiffHandler

pkg/api/handlers_test.go:90–172  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

88}
89
90func TestConfigDiffHandler(t *testing.T) {
91 for _, tc := range []struct {
92 name string
93 expectedStatusCode int
94 expectedBody string
95 actualConfig func() any
96 }{
97 {
98 name: "no config parameters overridden",
99 expectedStatusCode: 200,
100 expectedBody: "{}\n",
101 },
102 {
103 name: "slice changed",
104 actualConfig: func() any {
105 c := newDefaultDiffConfigMock()
106 c.MySlice = append(c.MySlice, "value3")
107 return c
108 },
109 expectedStatusCode: 200,
110 expectedBody: "my_slice:\n" +
111 "- value1\n" +
112 "- value2\n" +
113 "- value3\n",
114 },
115 {
116 name: "string in nested struct changed",
117 actualConfig: func() any {
118 c := newDefaultDiffConfigMock()
119 c.MyNestedStruct.MyString = "string2"
120 return c
121 },
122 expectedStatusCode: 200,
123 expectedBody: "my_nested_struct:\n" +
124 " my_string: string2\n",
125 },
126 {
127 name: "bool in nested struct changed",
128 actualConfig: func() any {
129 c := newDefaultDiffConfigMock()
130 c.MyNestedStruct.MyBool = true
131 return c
132 },
133 expectedStatusCode: 200,
134 expectedBody: "my_nested_struct:\n" +
135 " my_bool: true\n",
136 },
137 {
138 name: "test invalid input",
139 actualConfig: func() any {
140 c := "x"
141 return &c
142 },
143 expectedStatusCode: 500,
144 expectedBody: "yaml: unmarshal errors:\n" +
145 " line 1: cannot unmarshal !!str `x` into map[interface {}]interface {}\n",
146 },
147 } {

Callers

nothing calls this directly

Calls 4

newDefaultDiffConfigMockFunction · 0.85
DefaultConfigHandlerFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected