Page MenuHomeDevCentral

D4227.id11088.diff
No OneTemporary

D4227.id11088.diff

diff --git a/pkg/dockerutils/dockerutils_test.go b/pkg/dockerutils/dockerutils_test.go
new file mode 100644
--- /dev/null
+++ b/pkg/dockerutils/dockerutils_test.go
@@ -0,0 +1,56 @@
+package dockerutils
+
+import (
+ "github.com/docker/docker/api/types/container"
+ "testing"
+)
+
+func TestGetContainerName(t *testing.T) {
+ tests := []struct {
+ name string
+ container container.Summary
+ expected string
+ }{
+ {
+ name: "single name with leading slash",
+ container: container.Summary{
+ ID: "1234567890abcdef",
+ Names: []string{"/my-container"},
+ },
+ expected: "my-container",
+ },
+ {
+ name: "no names returns truncated ID",
+ container: container.Summary{
+ ID: "1234567890abcdef",
+ Names: []string{},
+ },
+ expected: "1234567890",
+ },
+ {
+ name: "linked container with link name first",
+ container: container.Summary{
+ ID: "1234567890abcdef",
+ Names: []string{"/parent/child-link", "/child-container"},
+ },
+ expected: "child-container",
+ },
+ {
+ name: "only linked name available",
+ container: container.Summary{
+ ID: "1234567890abcdef",
+ Names: []string{"/parent/child-link"},
+ },
+ expected: "parent/child-link",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := GetContainerName(tt.container)
+ if got != tt.expected {
+ t.Errorf("GetContainerName() = %v, want %v", got, tt.expected)
+ }
+ })
+ }
+}
diff --git a/pkg/process/process_test.go b/pkg/process/process_test.go
new file mode 100644
--- /dev/null
+++ b/pkg/process/process_test.go
@@ -0,0 +1,43 @@
+package process
+
+import (
+ "reflect"
+ "testing"
+)
+
+func TestParse(t *testing.T) {
+ labels := []string{"USER", "PID", "%CPU", "VSZ", "RSS", "COMMAND"}
+ info := []string{"root", "1234", "1.5", "10240", "2048", "/usr/bin/app"}
+
+ expected := Process{
+ User: "root",
+ Pid: 1234,
+ CPU: 1.5,
+ VSZ: 10240,
+ RSS: 2048,
+ Command: "/usr/bin/app",
+ }
+
+ got := Parse(labels, info)
+ if !reflect.DeepEqual(got, expected) {
+ t.Errorf("Parse() = %+v, want %+v", got, expected)
+ }
+}
+
+func TestParseIntOrZero(t *testing.T) {
+ if got := ParseIntOrZero("123"); got != 123 {
+ t.Errorf("ParseIntOrZero(\"123\") = %v, want 123", got)
+ }
+ if got := ParseIntOrZero("invalid"); got != 0 {
+ t.Errorf("ParseIntOrZero(\"invalid\") = %v, want 0", got)
+ }
+}
+
+func TestParseFloatOrZero(t *testing.T) {
+ if got := ParseFloatOrZero("12.34"); got != 12.34 {
+ t.Errorf("ParseFloatOrZero(\"12.34\") = %v, want 12.34", got)
+ }
+ if got := ParseFloatOrZero("invalid"); got != 0.0 {
+ t.Errorf("ParseFloatOrZero(\"invalid\") = %v, want 0.0", got)
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 24, 08:34 (13 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4213789
Default Alt Text
D4227.id11088.diff (2 KB)

Event Timeline