refactor: improve performance by optimizing string conversions

- Add the `strconv` import.
- Replace `fmt.Sprintf` with `strconv.Itoa` for converting UID and GID to string.

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
appleboy 2025-04-12 22:04:25 +08:00
parent dc7ab75e3b
commit 9376ede4c6
No known key found for this signature in database

View File

@ -7,6 +7,7 @@ import (
"io" "io"
"os" "os"
"reflect" "reflect"
"strconv"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -977,8 +978,8 @@ func TestSSHWithTestcontainers(t *testing.T) {
Image: "lscr.io/linuxserver/openssh-server:latest", Image: "lscr.io/linuxserver/openssh-server:latest",
ExposedPorts: []string{"2222/tcp"}, // Default port for this image is 2222 ExposedPorts: []string{"2222/tcp"}, // Default port for this image is 2222
Env: map[string]string{ Env: map[string]string{
"PUID": fmt.Sprintf("%d", os.Getuid()), // Use current user's UID "PUID": strconv.Itoa(os.Getuid()), // Use current user's UID
"PGID": fmt.Sprintf("%d", os.Getgid()), // Use current user's GID "PGID": strconv.Itoa(os.Getgid()), // Use current user's GID
"USER_NAME": "testuser", "USER_NAME": "testuser",
"USER_PASSWORD": "testpass", "USER_PASSWORD": "testpass",
"PASSWORD_ACCESS": "true", // Enable password authentication "PASSWORD_ACCESS": "true", // Enable password authentication