@@ -11,23 +11,23 @@ import (
1111
1212func TestNew (t * testing.T ) {
1313 cfg := New ()
14-
14+
1515 if cfg == nil {
1616 t .Fatal ("New() returned nil" )
1717 }
18-
18+
1919 if cfg .Rules == nil {
2020 t .Error ("Rules slice is nil" )
2121 }
22-
22+
2323 if len (cfg .Rules ) != 0 {
2424 t .Errorf ("Expected empty rules slice, got %d rules" , len (cfg .Rules ))
2525 }
26-
26+
2727 if cfg .LogFile != "var-sync.log" {
2828 t .Errorf ("Expected LogFile to be 'var-sync.log', got %s" , cfg .LogFile )
2929 }
30-
30+
3131 if cfg .Debug {
3232 t .Error ("Expected Debug to be false" )
3333 }
@@ -36,16 +36,16 @@ func TestNew(t *testing.T) {
3636func TestLoadNonExistentFile (t * testing.T ) {
3737 tempDir := t .TempDir ()
3838 configPath := filepath .Join (tempDir , "test-config.json" )
39-
39+
4040 cfg , err := Load (configPath )
4141 if err != nil {
4242 t .Fatalf ("Load() returned error: %v" , err )
4343 }
44-
44+
4545 if cfg == nil {
4646 t .Fatal ("Load() returned nil config" )
4747 }
48-
48+
4949 // Verify file was created
5050 if _ , err := os .Stat (configPath ); os .IsNotExist (err ) {
5151 t .Error ("Config file was not created" )
@@ -55,7 +55,7 @@ func TestLoadNonExistentFile(t *testing.T) {
5555func TestLoadExistingFile (t * testing.T ) {
5656 tempDir := t .TempDir ()
5757 configPath := filepath .Join (tempDir , "test-config.json" )
58-
58+
5959 // Create test config
6060 testRule := models.SyncRule {
6161 ID : "test-rule" ,
@@ -68,36 +68,36 @@ func TestLoadExistingFile(t *testing.T) {
6868 Enabled : true ,
6969 Created : time .Now (),
7070 }
71-
71+
7272 testConfig := & models.Config {
7373 Rules : []models.SyncRule {testRule },
7474 LogFile : "test.log" ,
7575 Debug : true ,
7676 }
77-
77+
7878 // Save test config
7979 if err := Save (testConfig , configPath ); err != nil {
8080 t .Fatalf ("Failed to save test config: %v" , err )
8181 }
82-
82+
8383 // Load config
8484 cfg , err := Load (configPath )
8585 if err != nil {
8686 t .Fatalf ("Load() returned error: %v" , err )
8787 }
88-
88+
8989 if len (cfg .Rules ) != 1 {
9090 t .Errorf ("Expected 1 rule, got %d" , len (cfg .Rules ))
9191 }
92-
92+
9393 if cfg .Rules [0 ].ID != "test-rule" {
9494 t .Errorf ("Expected rule ID 'test-rule', got %s" , cfg .Rules [0 ].ID )
9595 }
96-
96+
9797 if cfg .LogFile != "test.log" {
9898 t .Errorf ("Expected LogFile 'test.log', got %s" , cfg .LogFile )
9999 }
100-
100+
101101 if ! cfg .Debug {
102102 t .Error ("Expected Debug to be true" )
103103 }
@@ -106,30 +106,30 @@ func TestLoadExistingFile(t *testing.T) {
106106func TestSave (t * testing.T ) {
107107 tempDir := t .TempDir ()
108108 configPath := filepath .Join (tempDir , "subdir" , "test-config.json" )
109-
109+
110110 cfg := New ()
111111 cfg .LogFile = "custom.log"
112112 cfg .Debug = true
113-
113+
114114 if err := Save (cfg , configPath ); err != nil {
115115 t .Fatalf ("Save() returned error: %v" , err )
116116 }
117-
117+
118118 // Verify file exists
119119 if _ , err := os .Stat (configPath ); os .IsNotExist (err ) {
120120 t .Error ("Config file was not created" )
121121 }
122-
122+
123123 // Load and verify content
124124 loadedCfg , err := Load (configPath )
125125 if err != nil {
126126 t .Fatalf ("Failed to load saved config: %v" , err )
127127 }
128-
128+
129129 if loadedCfg .LogFile != "custom.log" {
130130 t .Errorf ("Expected LogFile 'custom.log', got %s" , loadedCfg .LogFile )
131131 }
132-
132+
133133 if ! loadedCfg .Debug {
134134 t .Error ("Expected Debug to be true" )
135135 }
@@ -138,22 +138,22 @@ func TestSave(t *testing.T) {
138138func TestManager (t * testing.T ) {
139139 tempDir := t .TempDir ()
140140 configPath := filepath .Join (tempDir , "manager-test.json" )
141-
141+
142142 manager , err := NewManager (configPath )
143143 if err != nil {
144144 t .Fatalf ("NewManager() returned error: %v" , err )
145145 }
146-
146+
147147 if manager == nil {
148148 t .Fatal ("NewManager() returned nil" )
149149 }
150-
150+
151151 // Test Config() method
152152 cfg := manager .Config ()
153153 if cfg == nil {
154154 t .Error ("Config() returned nil" )
155155 }
156-
156+
157157 // Test AddRule
158158 testRule := models.SyncRule {
159159 ID : "manager-test-rule" ,
@@ -166,54 +166,54 @@ func TestManager(t *testing.T) {
166166 Enabled : true ,
167167 Created : time .Now (),
168168 }
169-
169+
170170 manager .AddRule (testRule )
171-
171+
172172 if len (manager .Config ().Rules ) != 1 {
173173 t .Errorf ("Expected 1 rule after AddRule, got %d" , len (manager .Config ().Rules ))
174174 }
175-
175+
176176 // Test GetRule
177177 rule := manager .GetRule ("manager-test-rule" )
178178 if rule == nil {
179179 t .Error ("GetRule() returned nil for existing rule" )
180180 }
181-
181+
182182 if rule .ID != "manager-test-rule" {
183183 t .Errorf ("Expected rule ID 'manager-test-rule', got %s" , rule .ID )
184184 }
185-
185+
186186 // Test GetRule with non-existent ID
187187 nonExistentRule := manager .GetRule ("non-existent" )
188188 if nonExistentRule != nil {
189189 t .Error ("GetRule() should return nil for non-existent rule" )
190190 }
191-
191+
192192 // Test Save
193193 if err := manager .Save (); err != nil {
194194 t .Errorf ("Save() returned error: %v" , err )
195195 }
196-
196+
197197 // Test RemoveRule
198198 manager .RemoveRule ("manager-test-rule" )
199-
199+
200200 if len (manager .Config ().Rules ) != 0 {
201201 t .Errorf ("Expected 0 rules after RemoveRule, got %d" , len (manager .Config ().Rules ))
202202 }
203-
203+
204204 // Test removing non-existent rule (should not panic)
205205 manager .RemoveRule ("non-existent" )
206206}
207207
208208func TestLoadInvalidJSON (t * testing.T ) {
209209 tempDir := t .TempDir ()
210210 configPath := filepath .Join (tempDir , "invalid.json" )
211-
211+
212212 // Write invalid JSON
213213 if err := os .WriteFile (configPath , []byte ("invalid json" ), 0644 ); err != nil {
214214 t .Fatalf ("Failed to write invalid JSON: %v" , err )
215215 }
216-
216+
217217 _ , err := Load (configPath )
218218 if err == nil {
219219 t .Error ("Load() should return error for invalid JSON" )
@@ -223,14 +223,14 @@ func TestLoadInvalidJSON(t *testing.T) {
223223func TestSaveWithMissingDirectory (t * testing.T ) {
224224 tempDir := t .TempDir ()
225225 configPath := filepath .Join (tempDir , "missing" , "dir" , "config.json" )
226-
226+
227227 cfg := New ()
228228 if err := Save (cfg , configPath ); err != nil {
229229 t .Errorf ("Save() should create missing directories, got error: %v" , err )
230230 }
231-
231+
232232 // Verify file was created
233233 if _ , err := os .Stat (configPath ); os .IsNotExist (err ) {
234234 t .Error ("Config file was not created in missing directory" )
235235 }
236- }
236+ }
0 commit comments