This is an automated email from the ASF dual-hosted git repository.
zfeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-seata-go.git
The following commit(s) were added to refs/heads/master by this push:
new e2e18563 test: add unit test for pkg/util/flagext/register (#1005)
e2e18563 is described below
commit e2e185630224849bd38396798cbba4c8245e20be
Author: simple-xair <[email protected]>
AuthorDate: Sat Dec 20 19:33:38 2025 +0800
test: add unit test for pkg/util/flagext/register (#1005)
Co-authored-by: Tew <[email protected]>
Co-authored-by: flypiggy <[email protected]>
---
pkg/util/flagext/register_test.go | 77 +++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/pkg/util/flagext/register_test.go
b/pkg/util/flagext/register_test.go
new file mode 100644
index 00000000..cb093f6f
--- /dev/null
+++ b/pkg/util/flagext/register_test.go
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 flagext_test
+
+import (
+ "flag"
+ "testing"
+
+ "seata.apache.org/seata-go/pkg/util/flagext"
+)
+
+type testRegistererAll struct {
+ str *string
+ integer *int
+ int64Val *int64
+ boolean *bool
+ float64Val *float64
+}
+
+func (f *testRegistererAll) RegisterFlags(fs *flag.FlagSet) {
+ f.str = fs.String("str", "default-string", "string flag")
+ f.integer = fs.Int("int", 123, "int flag")
+ f.int64Val = fs.Int64("int64", 1234567890, "int64 flag")
+ f.boolean = fs.Bool("bool", true, "bool flag")
+ f.float64Val = fs.Float64("float", 3.14, "float64 flag")
+}
+
+func TestRegisterFlagsAll(t *testing.T) {
+ flag.CommandLine = flag.NewFlagSet("test", flag.ContinueOnError)
+
+ r := &testRegistererAll{}
+ flagext.RegisterFlags(r)
+
+ flags := []string{"str", "int", "int64", "bool", "float"}
+ for _, name := range flags {
+ if flag.CommandLine.Lookup(name) == nil {
+ t.Fatalf("expected %s to be registered in
flag.CommandLine", name)
+ }
+ }
+}
+
+func TestDefaultValuesAll(t *testing.T) {
+ r := &testRegistererAll{}
+
+ flagext.DefaultValues(r)
+
+ if *r.str != "default-string" {
+ t.Fatalf("expected default value 'default-string', got %q",
*r.str)
+ }
+ if *r.integer != 123 {
+ t.Fatalf("expected default value 123, got %d", *r.integer)
+ }
+ if *r.int64Val != 1234567890 {
+ t.Fatalf("expected default value 1234567890, got %d",
*r.int64Val)
+ }
+ if *r.boolean != true {
+ t.Fatalf("expected default value true, got %v", *r.boolean)
+ }
+ if *r.float64Val != 3.14 {
+ t.Fatalf("expected default value 3.14, got %v", *r.float64Val)
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]