VOL-1952 return error if message has missing field
Change-Id: Iaa07f736aa517b793c633d6762933e12488ec7f5
diff --git a/internal/pkg/afrouter/source-router_test.go b/internal/pkg/afrouter/source-router_test.go
index 3be2a6e..9810ace 100644
--- a/internal/pkg/afrouter/source-router_test.go
+++ b/internal/pkg/afrouter/source-router_test.go
@@ -84,7 +84,7 @@
_, err := newRouter(routerConfig)
assert.Nil(t, err)
- // Get the created AffinityRouter so we can inspect its state
+ // Get the created SourceRouter so we can inspect its state
sourceRouter := allRouters["vcorelogger"].(SourceRouter)
loggingMessage := &common_pb.Logging{Level: 1,
@@ -103,6 +103,25 @@
assert.Equal(t, s, "ro_vcore0.ro_vcore01")
}
+func TestSourceRouterDecodeProtoFieldMissingField(t *testing.T) {
+ _, routerConfig := MakeSourceRouterTestConfig()
+ _, err := newRouter(routerConfig)
+ assert.Nil(t, err)
+
+ // Get the created SourceRouter so we can inspect its state
+ sourceRouter := allRouters["vcorelogger"].(SourceRouter)
+
+ loggingMessage := &common_pb.Logging{Level: 1,
+ PackageName: "default",
+ ComponentName: "ro_vcore0.ro_vcore01"}
+
+ loggingData, err := proto.Marshal(loggingMessage)
+ assert.Nil(t, err)
+
+ _, err = sourceRouter.decodeProtoField(loggingData, 123) // field 123 does not exist
+ assert.EqualError(t, err, "At end of message, attribute 123 not found")
+}
+
func TestSourceRouterRoute(t *testing.T) {
_, routerConfig := MakeSourceRouterTestConfig()
_, err := newRouter(routerConfig)