From 31b1addd9ebe0a4d84fdfb6b5fd5902be44463a0 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 7 Jan 2021 18:47:25 -0500 Subject: [PATCH] structs: add tests for String() methods To show that printing one of these IDs works properly now that the String() method receiver is no longer a pointer. --- agent/structs/structs_oss_test.go | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 agent/structs/structs_oss_test.go diff --git a/agent/structs/structs_oss_test.go b/agent/structs/structs_oss_test.go new file mode 100644 index 000000000..402122994 --- /dev/null +++ b/agent/structs/structs_oss_test.go @@ -0,0 +1,41 @@ +package structs + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestServiceID_String(t *testing.T) { + t.Run("value", func(t *testing.T) { + sid := NewServiceID("the-id", &EnterpriseMeta{}) + require.Equal(t, "the-id", fmt.Sprintf("%v", sid)) + }) + t.Run("pointer", func(t *testing.T) { + sid := NewServiceID("the-id", &EnterpriseMeta{}) + require.Equal(t, "the-id", fmt.Sprintf("%v", &sid)) + }) +} + +func TestCheckID_String(t *testing.T) { + t.Run("value", func(t *testing.T) { + cid := NewCheckID("the-id", &EnterpriseMeta{}) + require.Equal(t, "the-id", fmt.Sprintf("%v", cid)) + }) + t.Run("pointer", func(t *testing.T) { + cid := NewCheckID("the-id", &EnterpriseMeta{}) + require.Equal(t, "the-id", fmt.Sprintf("%v", &cid)) + }) +} + +func TestServiceName_String(t *testing.T) { + t.Run("value", func(t *testing.T) { + sn := NewServiceName("the-id", &EnterpriseMeta{}) + require.Equal(t, "the-id", fmt.Sprintf("%v", sn)) + }) + t.Run("pointer", func(t *testing.T) { + sn := NewServiceName("the-id", &EnterpriseMeta{}) + require.Equal(t, "the-id", fmt.Sprintf("%v", &sn)) + }) +}