Files
zeekay 6e545b9eef fork: beego v2.3.8 — prometheus/client_golang stripped (luxfi/metric backend)
Patches against upstream beego/[email protected]:
  server/web/admin_controller.go     — promhttp.Handler → luxfi/metric HTTP handler
  server/web/filter/prometheus/      — luxfi/metric backend, drops MustRegister
  client/httplib/filter/prometheus/  — luxfi/metric backend
  client/orm/filter/prometheus/      — luxfi/metric backend
  core/config/etcd/config.go         — drop grpc-ecosystem/go-grpc-prometheus
                                       interceptors (etcd dialing has no
                                       observability through this path)

Default closure: 0 grpc, 0 protobuf, 0 prometheus/client_golang.
Consumers in hanzoai/iam see the fork through workspace mode.
2026-05-22 20:59:15 -07:00

99 lines
2.1 KiB
Go

// Copyright 2024 beego
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package context
import (
"net/url"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFormFirstValue(t *testing.T) {
typ := reflect.TypeOf(TestStruct{})
defField, _ := typ.FieldByName("DefaultField")
noDefField, _ := typ.FieldByName("NoDefaultField")
testCases := []struct {
name string
tag string
form url.Values
field reflect.StructField
wantRes string
wantOk bool
}{
{
name: "use value",
tag: "defaultField",
field: defField,
form: map[string][]string{
"defaultField": {"abc", "bcd"},
},
wantRes: "abc",
wantOk: true,
},
{
name: "empty value",
tag: "defaultField",
field: defField,
form: map[string][]string{
"defaultField": {"", "bcd"},
},
wantRes: "",
wantOk: false,
},
{
name: "empty default value",
tag: "defaultField",
field: defField,
form: map[string][]string{
"defaultField": {"", "bcd"},
},
wantRes: "",
wantOk: false,
},
{
name: "use default value",
tag: "defaultField",
field: defField,
form: map[string][]string{},
wantRes: "Tom",
wantOk: true,
},
{
name: "no value",
tag: "no",
field: noDefField,
form: map[string][]string{},
wantOk: false,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
val, ok := formFirstValue(tc.tag, tc.form, tc.field)
assert.Equal(t, tc.wantRes, val)
assert.Equal(t, tc.wantOk, ok)
})
}
}
type TestStruct struct {
DefaultField string `form:"defaultField" default:"Tom"`
NoDefaultField string `form:"noDefaultField"`
}