Repository: zeromicro/go-zero
Pull request #3260 (2023-05-18 16:36:10)

chore: add more tests

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/3260?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#3260](https://app.codecov.io/gh/zeromicro/go-zero/pull/3260?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (92b1407) into [master](https://app.codecov.io/gh/zeromicro/go-zero/commit/701bb31ed2390d12437ba4d2d31eed2c7365e0b4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (701bb31) will **increase** coverage by `0.15%`.
> The diff coverage is `n/a`.


| [Impacted Files](https://app.codecov.io/gh/zeromicro/go-zero/pull/3260?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [core/stat/internal/cgroup\_linux.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3260?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29yZS9zdGF0L2ludGVybmFsL2Nncm91cF9saW51eC5nbw==) | `37.93% <ø> (ø)` | |

... and [2 files with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/3260/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/core/stat/internal/cgroup_linux.go b/core/stat/internal/cgroup_linux.go
index 23bdda48..5f53d9ed 100644
--- a/core/stat/internal/cgroup_linux.go
+++ b/core/stat/internal/cgroup_linux.go
@@ -284,6 +284,7 @@ func runningInUserNS() bool {
 		if a == 0 && b == 0 && c == math.MaxUint32 {
 			return
 		}
+
 		inUserNS = true
 	})
 


Test patch:
diff --git a/core/stores/builder/builder_test.go b/core/stores/builder/builder_test.go
index 8741b7d6..d8cfd33e 100644
--- a/core/stores/builder/builder_test.go
+++ b/core/stores/builder/builder_test.go
@@ -69,3 +69,62 @@ func TestFieldNamesWithDashTagAndOptions(t *testing.T) {
 		assert.Equal(t, expected, out)
 	})
 }
+
+func TestPostgreSqlJoin(t *testing.T) {
+	// Test with empty input array
+	var input []string
+	var expectedOutput string
+	assert.Equal(t, expectedOutput, PostgreSqlJoin(input))
+
+	// Test with single element input array
+	input = []string{"foo"}
+	expectedOutput = "foo = $2"
+	assert.Equal(t, expectedOutput, PostgreSqlJoin(input))
+
+	// Test with multiple elements input array
+	input = []string{"foo", "bar", "baz"}
+	expectedOutput = "foo = $2, bar = $3, baz = $4"
+	assert.Equal(t, expectedOutput, PostgreSqlJoin(input))
+}
+
+type testStruct struct {
+	Foo string `db:"foo"`
+	Bar int    `db:"bar"`
+	Baz bool   `db:"-"`
+}
+
+func TestRawFieldNames(t *testing.T) {
+	// Test with a struct without tags
+	in := struct {
+		Foo string
+		Bar int
+	}{}
+	expectedOutput := []string{"`Foo`", "`Bar`"}
+	assert.ElementsMatch(t, expectedOutput, RawFieldNames(in))
+
+	// Test pg without db tag
+	expectedOutput = []string{"Foo", "Bar"}
+	assert.ElementsMatch(t, expectedOutput, RawFieldNames(in, true))
+
+	// Test with a struct with tags
+	input := testStruct{}
+	expectedOutput = []string{"`foo`", "`bar`"}
+	assert.ElementsMatch(t, expectedOutput, RawFieldNames(input))
+
+	// Test with nil input (pointer)
+	var nilInput *testStruct
+	assert.Panics(t, func() {
+		RawFieldNames(nilInput)
+	}, "RawFieldNames should panic with nil input")
+
+	// Test with non-struct input
+	inputInt := 42
+	assert.Panics(t, func() {
+		RawFieldNames(inputInt)
+	}, "RawFieldNames should panic with non-struct input")
+
+	// Test with PostgreSQL flag
+	input = testStruct{}
+	expectedOutput = []string{"foo", "bar"}
+	assert.ElementsMatch(t, expectedOutput, RawFieldNames(input, true))
+}