diff --git a/dump/dump_test.go b/dump/dump_test.go index ce2fb2cee..44885e43e 100644 --- a/dump/dump_test.go +++ b/dump/dump_test.go @@ -235,7 +235,7 @@ func TestStruct_CannotExportField(t *testing.T) { assert.Contains(t, str, "opt4: string(\"abc\"),") } -func TestStruct_InterfaceField(t *testing.T) { +func ExampleStruct_interfaceField() { myS1 := struct { // cannotExport any // ok cannotExport st1 // ok @@ -251,7 +251,7 @@ func TestStruct_InterfaceField(t *testing.T) { fmt.Println(myS1) } -func TestStruct_MapInterfacedValue(t *testing.T) { +func ExampleStruct_mapInterfacedValue() { myS2 := &struct { cannotExport map[string]any }{ diff --git a/netutil/httpctype/content_type.go b/netutil/httpctype/content_type.go index efe22af89..8fb0b5471 100644 --- a/netutil/httpctype/content_type.go +++ b/netutil/httpctype/content_type.go @@ -1,6 +1,7 @@ // Package httpctype list some common http content-type package httpctype +// Key is the header key of Content-Type const Key = "Content-Type" // there are some HTTP Content-Type with charset of the most common data formats. diff --git a/netutil/httpheader/header.go b/netutil/httpheader/header.go index 2f02d7a63..28c4f6857 100644 --- a/netutil/httpheader/header.go +++ b/netutil/httpheader/header.go @@ -1,3 +1,4 @@ +// Package httpheader provides some common http header names. package httpheader // some common http header names diff --git a/sysutil/user_nonwin.go b/sysutil/user_nonwin.go index db5a00ee1..e8d613c7b 100644 --- a/sysutil/user_nonwin.go +++ b/sysutil/user_nonwin.go @@ -9,14 +9,21 @@ import ( ) // ChangeUserByName change work user by new username. -func ChangeUserByName(newUname string) (err error) { +func ChangeUserByName(newUname string) error { u := MustFindUser(newUname) // syscall.Setlogin(newUname) - return ChangeUserUidGid(strutil.IntOrPanic(u.Uid), strutil.IntOrPanic(u.Gid)) + return ChangeUserUIDGid(strutil.IntOrPanic(u.Uid), strutil.IntOrPanic(u.Gid)) } // ChangeUserUidGid change work user by new username uid,gid -func ChangeUserUidGid(newUID int, newGid int) (err error) { +// +// Deprecated: use ChangeUserUIDGid instead +func ChangeUserUidGid(newUID int, newGid int) error { + return ChangeUserUIDGid(newUID, newGid) +} + +// ChangeUserUIDGid change work user by new username uid,gid +func ChangeUserUIDGid(newUID int, newGid int) (err error) { if newUID > 0 { err = syscall.Setuid(newUID) diff --git a/sysutil/user_windows.go b/sysutil/user_windows.go index 0ad7322bf..4d3ea34a9 100644 --- a/sysutil/user_windows.go +++ b/sysutil/user_windows.go @@ -5,10 +5,17 @@ package sysutil // ChangeUserByName change work user by new username. func ChangeUserByName(newUname string) (err error) { - return ChangeUserUidGid(0, 0) + return ChangeUserUIDGid(0, 0) } // ChangeUserUidGid change work user by new username uid,gid +// +// Deprecated: use ChangeUserUIDGid instead func ChangeUserUidGid(newUid int, newGid int) (err error) { + return ChangeUserUIDGid(newUid, newGid) +} + +// ChangeUserUIDGid change work user by new username uid,gid +func ChangeUserUIDGid(newUid int, newGid int) (err error) { return nil } diff --git a/testutil/assert/assertions_methods.go b/testutil/assert/assertions_methods.go index a21ff5a97..06d223ba4 100644 --- a/testutil/assert/assertions_methods.go +++ b/testutil/assert/assertions_methods.go @@ -1,5 +1,6 @@ package assert +// Nil asserts that the given is a nil value func (as *Assertions) Nil(give any, fmtAndArgs ...any) *Assertions { as.t.Helper() as.ok = Nil(as.t, give, fmtAndArgs...) diff --git a/testutil/fakeobj/fs.go b/testutil/fakeobj/fs.go index fd9daaeeb..3b7ba492a 100644 --- a/testutil/fakeobj/fs.go +++ b/testutil/fakeobj/fs.go @@ -95,10 +95,12 @@ func (f *FileInfo) Reset() *FileInfo { // fs.File methods. +// Stat returns the FileInfo structure describing file. func (f *FileInfo) Stat() (fs.FileInfo, error) { return f, nil } +// Read reads up to len(p) bytes into p. func (f *FileInfo) Read(p []byte) (int, error) { if f.offset >= len(f.Contents) { return 0, io.EOF @@ -109,32 +111,39 @@ func (f *FileInfo) Read(p []byte) (int, error) { return n, nil } +// Close closes the file func (f *FileInfo) Close() error { return f.CloseErr } // fs.FileInfo methods. +// Name returns the base name of the file. func (f *FileInfo) Name() string { return f.Nam } +// Size returns the length in bytes for regular files; system-dependent for others. func (f *FileInfo) Size() int64 { return int64(len(f.Contents)) } +// Mode returns file mode bits. func (f *FileInfo) Mode() fs.FileMode { return f.Mod } +// ModTime returns the modification time. func (f *FileInfo) ModTime() time.Time { return f.Mt } +// IsDir returns true if the file is a directory. func (f *FileInfo) IsDir() bool { return f.Dir } +// Sys returns underlying data source (can return nil). func (f *FileInfo) Sys() any { return nil } diff --git a/testutil/fakeobj/fs_test.go b/testutil/fakeobj/fs_test.go index 65ec72792..a757ad210 100644 --- a/testutil/fakeobj/fs_test.go +++ b/testutil/fakeobj/fs_test.go @@ -46,4 +46,5 @@ func TestNewFileInfo(t *testing.T) { assert.True(t, fi.IsDir()) assert.Gt(t, int(fi.Mode()), 0) assert.Equal(t, "dir", fi.Name()) + assert.Nil(t, fi.Sys()) } diff --git a/testutil/httpmock.go b/testutil/httpmock.go index 85def6c56..27a6f5471 100644 --- a/testutil/httpmock.go +++ b/testutil/httpmock.go @@ -25,7 +25,14 @@ type ( } ) -// NewHttpRequest for http testing +// NewHttpRequest for http testing, alias of NewHTTPRequest() +// +// Deprecated: use NewHTTPRequest() instead. +func NewHttpRequest(method, path string, data *MD) *http.Request { + return NewHTTPRequest(method, path, data) +} + +// NewHTTPRequest for http testing // Usage: // // req := NewHttpRequest("GET", "/path", nil) @@ -42,7 +49,7 @@ type ( // BodyString: "data string", // Headers: M{"x-head": "val"} // }) -func NewHttpRequest(method, path string, data *MD) *http.Request { +func NewHTTPRequest(method, path string, data *MD) *http.Request { var body io.Reader if data != nil { if data.Body != nil { @@ -97,7 +104,7 @@ func NewHttpRequest(method, path string, data *MD) *http.Request { func MockRequest(h http.Handler, method, path string, data *MD) *httptest.ResponseRecorder { // w.Result() will return http.Response w := httptest.NewRecorder() - r := NewHttpRequest(method, path, data) + r := NewHTTPRequest(method, path, data) // s := httptest.NewServer() h.ServeHTTP(w, r)