1- package comparing_structs_for_changes
1+ package change
22
33import (
4+ "github.com/rschoonheim/go-struct-sync/compare"
45 "reflect"
56 "testing"
67)
@@ -24,10 +25,10 @@ func TestApplyChangesModifiesValues(t *testing.T) {
2425 Address : "123 Main St" ,
2526 }
2627
27- changes := []Change {
28- {Field : "Name" , ChangeType : Modified , NewValue : "Jane" },
29- {Field : "Age" , ChangeType : Modified , NewValue : 31 },
30- {Field : "Active" , ChangeType : Modified , NewValue : false },
28+ changes := []compare. Change {
29+ {Field : "Name" , ChangeType : compare . Modified , NewValue : "Jane" },
30+ {Field : "Age" , ChangeType : compare . Modified , NewValue : 31 },
31+ {Field : "Active" , ChangeType : compare . Modified , NewValue : false },
3132 }
3233
3334 result , err := ApplyChanges (original , changes )
@@ -50,8 +51,8 @@ func TestApplyChangesToPointer(t *testing.T) {
5051 Age : 30 ,
5152 }
5253
53- changes := []Change {
54- {Field : "Name" , ChangeType : Modified , NewValue : "Jane" },
54+ changes := []compare. Change {
55+ {Field : "Name" , ChangeType : compare . Modified , NewValue : "Jane" },
5556 }
5657
5758 result , err := ApplyChanges (original , changes )
@@ -61,7 +62,7 @@ func TestApplyChangesToPointer(t *testing.T) {
6162
6263 modified := result .(* Person )
6364 if modified .Name != "Jane" || modified .Age != 30 {
64- t .Errorf ("Expected only Name to be modified , got: %+v" , modified )
65+ t .Errorf ("Expected only Name to be compare.Modified , got: %+v" , modified )
6566 }
6667}
6768
@@ -73,10 +74,10 @@ func TestApplyChangesDeletesFields(t *testing.T) {
7374 Manager : & Person {Name : "Boss" },
7475 }
7576
76- changes := []Change {
77- {Field : "Name" , ChangeType : Deleted , OldValue : "John" },
78- {Field : "Children" , ChangeType : Deleted , OldValue : []string {"Alice" , "Bob" }},
79- {Field : "Manager" , ChangeType : Deleted , OldValue : & Person {Name : "Boss" }},
77+ changes := []compare. Change {
78+ {Field : "Name" , ChangeType : compare . Deleted , OldValue : "John" },
79+ {Field : "Children" , ChangeType : compare . Deleted , OldValue : []string {"Alice" , "Bob" }},
80+ {Field : "Manager" , ChangeType : compare . Deleted , OldValue : & Person {Name : "Boss" }},
8081 }
8182
8283 result , err := ApplyChanges (original , changes )
@@ -101,10 +102,10 @@ func TestApplyChangesAddsValues(t *testing.T) {
101102 Name : "John" ,
102103 }
103104
104- changes := []Change {
105- {Field : "Age" , ChangeType : Added , NewValue : 25 },
106- {Field : "Active" , ChangeType : Added , NewValue : true },
107- {Field : "Children" , ChangeType : Added , NewValue : []string {"Child" }},
105+ changes := []compare. Change {
106+ {Field : "Age" , ChangeType : compare . Added , NewValue : 25 },
107+ {Field : "Active" , ChangeType : compare . Added , NewValue : true },
108+ {Field : "Children" , ChangeType : compare . Added , NewValue : []string {"Child" }},
108109 }
109110
110111 result , err := ApplyChanges (original , changes )
@@ -123,7 +124,7 @@ func TestApplyChangesAddsValues(t *testing.T) {
123124
124125func TestApplyChangesWithEmptyChangesList (t * testing.T ) {
125126 original := Person {Name : "John" , Age : 30 }
126- changes := []Change {}
127+ changes := []compare. Change {}
127128
128129 result , err := ApplyChanges (original , changes )
129130 if err != nil {
@@ -138,8 +139,8 @@ func TestApplyChangesWithEmptyChangesList(t *testing.T) {
138139
139140func TestApplyChangesFailsOnNonStruct (t * testing.T ) {
140141 original := "not a struct"
141- changes := []Change {
142- {Field : "something" , ChangeType : Modified , NewValue : "new" },
142+ changes := []compare. Change {
143+ {Field : "something" , ChangeType : compare . Modified , NewValue : "new" },
143144 }
144145
145146 _ , err := ApplyChanges (original , changes )
@@ -150,8 +151,8 @@ func TestApplyChangesFailsOnNonStruct(t *testing.T) {
150151
151152func TestApplyChangesFailsOnNonExistentField (t * testing.T ) {
152153 original := Person {Name : "John" }
153- changes := []Change {
154- {Field : "NonExistentField" , ChangeType : Modified , NewValue : "value" },
154+ changes := []compare. Change {
155+ {Field : "NonExistentField" , ChangeType : compare . Modified , NewValue : "value" },
155156 }
156157
157158 _ , err := ApplyChanges (original , changes )
@@ -162,8 +163,8 @@ func TestApplyChangesFailsOnNonExistentField(t *testing.T) {
162163
163164func TestApplyChangesFailsOnUnexportedField (t * testing.T ) {
164165 original := Person {Name : "John" }
165- changes := []Change {
166- {Field : "private" , ChangeType : Modified , NewValue : "value" },
166+ changes := []compare. Change {
167+ {Field : "private" , ChangeType : compare . Modified , NewValue : "value" },
167168 }
168169
169170 _ , err := ApplyChanges (original , changes )
@@ -174,8 +175,8 @@ func TestApplyChangesFailsOnUnexportedField(t *testing.T) {
174175
175176func TestApplyChangesFailsOnTypeConversionError (t * testing.T ) {
176177 original := Person {Name : "John" }
177- changes := []Change {
178- {Field : "Name" , ChangeType : Modified , NewValue : struct {}{}},
178+ changes := []compare. Change {
179+ {Field : "Name" , ChangeType : compare . Modified , NewValue : struct {}{}},
179180 }
180181
181182 _ , err := ApplyChanges (original , changes )
0 commit comments