MCPcopy
hub / github.com/caddyserver/caddy / TestUnsyncedConfigAccessCanonicalArrayIndices

Function TestUnsyncedConfigAccessCanonicalArrayIndices

admin_test.go:1105–1147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1103}
1104
1105func TestUnsyncedConfigAccessCanonicalArrayIndices(t *testing.T) {
1106 rawCfg = map[string]any{
1107 rawConfigKey: map[string]any{
1108 "list": []any{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"},
1109 },
1110 }
1111
1112 tests := []struct {
1113 name string
1114 path string
1115 wantOutput string
1116 wantErr bool
1117 }{
1118 {name: "allow zero", path: "/" + rawConfigKey + "/list/0", wantOutput: "\"zero\"\n"},
1119 {name: "allow one", path: "/" + rawConfigKey + "/list/1", wantOutput: "\"one\"\n"},
1120 {name: "allow ten", path: "/" + rawConfigKey + "/list/10", wantOutput: "\"ten\"\n"},
1121 {name: "reject leading zero", path: "/" + rawConfigKey + "/list/01", wantErr: true},
1122 {name: "reject multiple leading zeros", path: "/" + rawConfigKey + "/list/002", wantErr: true},
1123 {name: "reject plus sign", path: "/" + rawConfigKey + "/list/+1", wantErr: true},
1124 {name: "reject negative zero", path: "/" + rawConfigKey + "/list/-0", wantErr: true},
1125 }
1126
1127 for i, tc := range tests {
1128 t.Run(tc.name, func(t *testing.T) {
1129 var gotOutput bytes.Buffer
1130 err := unsyncedConfigAccess(http.MethodGet, tc.path, nil, &gotOutput)
1131
1132 if tc.wantErr {
1133 if err == nil {
1134 t.Errorf("test %d (%s): input path %q: expected error, got nil with output %q", i, tc.name, tc.path, gotOutput.String())
1135 }
1136 return
1137 }
1138
1139 if err != nil {
1140 t.Errorf("test %d (%s): input path %q: expected no error with output %q, got error %v with output %q", i, tc.name, tc.path, tc.wantOutput, err, gotOutput.String())
1141 }
1142 if gotOutput.String() != tc.wantOutput {
1143 t.Errorf("test %d (%s): input path %q: expected output %q, got %q", i, tc.name, tc.path, tc.wantOutput, gotOutput.String())
1144 }
1145 })
1146 }
1147}

Callers

nothing calls this directly

Calls 2

unsyncedConfigAccessFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected