From 16b3da9b4095b24c25ceabfc0872b1b430566fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20D=C3=B6ll?= Date: Tue, 30 Jul 2024 21:06:29 +0000 Subject: [PATCH] test: adding test for cast --- cast/ptr_test.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 cast/ptr_test.go diff --git a/cast/ptr_test.go b/cast/ptr_test.go new file mode 100644 index 0000000..f43b6ff --- /dev/null +++ b/cast/ptr_test.go @@ -0,0 +1,61 @@ +package cast_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/zeiss/pkg/cast" +) + +func TestPtr(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + v any + }{ + {"success", 1}, + {"success", "hello"}, + {"success", struct{}{}}, + {"success", []int{1, 2, 3}}, + {"success", map[string]int{"a": 1, "b": 2}}, + } + + for _, tt := range tests { + tt := tt + + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + p := &tt.v + got := cast.Ptr(tt.v) + assert.Equal(t, p, got) + }) + } +} + +func TestValue(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + v any + }{ + {"success", 1}, + {"success", "hello"}, + {"success", struct{}{}}, + {"success", []int{1, 2, 3}}, + {"success", map[string]int{"a": 1, "b": 2}}, + } + + for _, tt := range tests { + tt := tt + + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got := cast.Value(&tt.v) + assert.Equal(t, tt.v, got) + }) + } +}