Skip to content

Commit

Permalink
improve test on nil and empty value for slice and map in HashSerializ…
Browse files Browse the repository at this point in the history
…e functions
  • Loading branch information
NicolasMahe committed Mar 5, 2020
1 parent 5774bfe commit aef551a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions hash/hashserializer/hashserializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ type StringSlice []string

// HashSerialize returns the hash-serialized string of this type.
func (s StringSlice) HashSerialize() string {
if s == nil || len(s) == 0 {
return ""
}
ser := New()
for i, value := range s {
ser.AddString(strconv.Itoa(i), value)
Expand Down
13 changes: 8 additions & 5 deletions process/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ type mapProcessNodeMapOutput map[string]*Process_Node_Map_Output

// HashSerialize returns the hashserialized string of this type
func (data mapProcessNodeMapOutput) HashSerialize() string {
ser := hashserializer.New()
if data == nil || len(data) == 0 {
return ""
}
keys := make([]string, 0, len(data))
for k := range data {
keys = append(keys, k)
}
sort.Strings(keys)
ser := hashserializer.New()
for _, key := range keys {
ser.Add(key, data[key])
}
Expand Down Expand Up @@ -133,7 +136,7 @@ type processNodeMapOutputs []*Process_Node_Map_Output

// HashSerialize returns the hashserialized string of this type
func (data processNodeMapOutputs) HashSerialize() string {
if data == nil {
if data == nil || len(data) == 0 {
return ""
}
ser := hashserializer.New()
Expand Down Expand Up @@ -180,7 +183,7 @@ type processNodeFilterConditions []Process_Node_Filter_Condition

// HashSerialize returns the hashserialized string of this type
func (data processNodeFilterConditions) HashSerialize() string {
if data == nil {
if data == nil || len(data) == 0 {
return ""
}
ser := hashserializer.New()
Expand Down Expand Up @@ -214,7 +217,7 @@ type processNodes []*Process_Node

// HashSerialize returns the hashserialized string of this type
func (data processNodes) HashSerialize() string {
if data == nil {
if data == nil || len(data) == 0 {
return ""
}
ser := hashserializer.New()
Expand All @@ -228,7 +231,7 @@ type processEdges []*Process_Edge

// HashSerialize returns the hashserialized string of this type
func (data processEdges) HashSerialize() string {
if data == nil {
if data == nil || len(data) == 0 {
return ""
}
ser := hashserializer.New()
Expand Down
7 changes: 5 additions & 2 deletions protobuf/types/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ type mapValue map[string]*Value

// HashSerialize returns the hashserialized string of this type
func (data mapValue) HashSerialize() string {
ser := hashserializer.New()
if data == nil || len(data) == 0 {
return ""
}
keys := make([]string, 0, len(data))
for k := range data {
keys = append(keys, k)
}
sort.Strings(keys)
ser := hashserializer.New()
for _, key := range keys {
ser.Add(key, data[key])
}
Expand Down Expand Up @@ -62,7 +65,7 @@ type values []*Value

// HashSerialize returns the hashserialized string of this type
func (data values) HashSerialize() string {
if data == nil {
if data == nil || len(data) == 0 {
return ""
}
ser := hashserializer.New()
Expand Down
8 changes: 4 additions & 4 deletions service/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type serviceTasks []*Service_Task

// HashSerialize returns the hashserialized string of this type
func (data serviceTasks) HashSerialize() string {
if data == nil {
if data == nil || len(data) == 0 {
return ""
}
ser := hashserializer.New()
Expand All @@ -114,7 +114,7 @@ type serviceParameters []*Service_Parameter

// HashSerialize returns the hashserialized string of this type
func (data serviceParameters) HashSerialize() string {
if data == nil {
if data == nil || len(data) == 0 {
return ""
}
ser := hashserializer.New()
Expand All @@ -128,7 +128,7 @@ type serviceEvents []*Service_Event

// HashSerialize returns the hashserialized string of this type
func (data serviceEvents) HashSerialize() string {
if data == nil {
if data == nil || len(data) == 0 {
return ""
}
ser := hashserializer.New()
Expand All @@ -142,7 +142,7 @@ type serviceDependencies []*Service_Dependency

// HashSerialize returns the hashserialized string of this type
func (data serviceDependencies) HashSerialize() string {
if data == nil {
if data == nil || len(data) == 0 {
return ""
}
ser := hashserializer.New()
Expand Down

0 comments on commit aef551a

Please sign in to comment.