diff --git a/pkg/extension/action_test.go b/pkg/extension/action_test.go index edba7e4712f2f334b50a0e2aa13e8ebb79c923d6..cfbcaf4fbc793b968526028b80cc122f5e60afff 100644 --- a/pkg/extension/action_test.go +++ b/pkg/extension/action_test.go @@ -8,46 +8,50 @@ import ( "github.com/stretchr/testify/require" ) -func TestAction(t *testing.T) { +func TestActionCoversion(t *testing.T) { t.Run("Protobuf", func(t *testing.T) { - var pbAction *pb.Action - err := gofakeit.Struct(&pbAction) - require.NoError(t, err) - - action := ActionFromPB(pbAction) - result := ActionToPB(action) - require.Equal(t, pbAction, result) - }) - - t.Run("Nil Protobuf", func(t *testing.T) { - var pbAction *pb.Action - action := ActionFromPB(pbAction) - result := ActionToPB(action) - require.Equal(t, pbAction, result) + t.Run("Should not lose information", func(t *testing.T) { + var pbAction *pb.Action + err := gofakeit.Struct(&pbAction) + require.NoError(t, err) + + action := ActionFromPB(pbAction) + result := ActionToPB(action) + require.Equal(t, pbAction, result) + }) + + t.Run("Should return nil if action is nil", func(t *testing.T) { + var pbAction *pb.Action + action := ActionFromPB(pbAction) + result := ActionToPB(action) + require.Equal(t, pbAction, result) + }) }) t.Run("Map", func(t *testing.T) { - var action *Action - err := gofakeit.Struct(&action) - require.NoError(t, err) - - dict := ActionToMap(action) - result, err := ActionFromMap(dict) - require.NoError(t, err) - require.Equal(t, action, result) - }) - - t.Run("Nil Map", func(t *testing.T) { - var action *Action - dict := ActionToMap(action) - result, err := ActionFromMap(dict) - require.NoError(t, err) - require.Equal(t, &Action{}, result) + t.Run("Should not lose information", func(t *testing.T) { + var action *Action + err := gofakeit.Struct(&action) + require.NoError(t, err) + + dict := ActionToMap(action) + result, err := ActionFromMap(dict) + require.NoError(t, err) + require.Equal(t, action, result) + }) + + t.Run("Should return zero-value struct if argument is nil", func(t *testing.T) { + var action *Action + dict := ActionToMap(action) + result, err := ActionFromMap(dict) + require.NoError(t, err) + require.Equal(t, &Action{}, result) + }) }) } -func TestActionRequest(t *testing.T) { - t.Run("Protobuf", func(t *testing.T) { +func TestActionRequestPBConversion(t *testing.T) { + t.Run("Should not lose information", func(t *testing.T) { var pbAction *pb.ActionRequest err := gofakeit.Struct(&pbAction) require.NoError(t, err) @@ -57,7 +61,7 @@ func TestActionRequest(t *testing.T) { require.Equal(t, pbAction, result) }) - t.Run("Nil", func(t *testing.T) { + t.Run("Should return nil if action is nil", func(t *testing.T) { var pbAction *pb.ActionRequest action := ActionRequestFromPB(pbAction) result := ActionRequestToPB(action) @@ -65,8 +69,8 @@ func TestActionRequest(t *testing.T) { }) } -func TestActionResponse(t *testing.T) { - t.Run("Protobuf", func(t *testing.T) { +func TestActionResponsePBConversion(t *testing.T) { + t.Run("Should not lose information", func(t *testing.T) { var pbAction *pb.ActionResponse err := gofakeit.Struct(&pbAction) require.NoError(t, err) @@ -76,7 +80,7 @@ func TestActionResponse(t *testing.T) { require.Equal(t, pbAction, result) }) - t.Run("Nil", func(t *testing.T) { + t.Run("Should return nil if action is nil", func(t *testing.T) { var pbAction *pb.ActionResponse action := ActionResponseFromPB(pbAction) result := ActionResponseToPB(action)