Skip to content

Commit 2c7a6ae

Browse files
committed
fit tests
1 parent 3fcb50a commit 2c7a6ae

File tree

20 files changed

+530
-1308
lines changed

20 files changed

+530
-1308
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
go-version: ${{ env.GO_VERSION }}
2525

2626
- name: Cache Go modules
27-
uses: actions/cache@v3
27+
uses: actions/cache@v4
2828
with:
2929
path: |
3030
~/.cache/go-build
@@ -40,7 +40,7 @@ jobs:
4040
uses: golangci/golangci-lint-action@v3
4141
with:
4242
version: latest
43-
args: --timeout=5m
43+
args: --timeout=5m --out-format=colored-line-number
4444

4545
- name: Check formatting
4646
run: |
@@ -171,7 +171,7 @@ jobs:
171171
fail_ci_if_error: false
172172

173173
- name: Upload coverage reports as artifact
174-
uses: actions/upload-artifact@v3
174+
uses: actions/upload-artifact@v4
175175
with:
176176
name: coverage-reports
177177
path: |
@@ -237,7 +237,7 @@ jobs:
237237
run: make test-performance
238238

239239
- name: Upload performance profiles as artifacts
240-
uses: actions/upload-artifact@v3
240+
uses: actions/upload-artifact@v4
241241
with:
242242
name: performance-profiles
243243
path: |

.github/workflows/release.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
id: current_version
3030
run: |
3131
CURRENT_VERSION=$(grep -o 'version.*=.*"[^"]*"' main.go | cut -d'"' -f2)
32-
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
32+
echo "current=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
3333
3434
- name: Bump version
3535
id: version
@@ -40,9 +40,17 @@ jobs:
4040
MINOR=${PARTS[1]}
4141
PATCH=${PARTS[2]}
4242
NEW_PATCH=$((PATCH + 1))
43+
44+
# Keep incrementing until we find an available tag
45+
while git ls-remote --tags origin | grep -q "refs/tags/v$MAJOR.$MINOR.$NEW_PATCH"; do
46+
echo "Tag v$MAJOR.$MINOR.$NEW_PATCH already exists, incrementing..."
47+
NEW_PATCH=$((NEW_PATCH + 1))
48+
done
49+
4350
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
44-
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
45-
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
51+
echo "Using version: $NEW_VERSION"
52+
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
53+
echo "tag=v$NEW_VERSION" >> "$GITHUB_OUTPUT"
4654
4755
- name: Update version in code
4856
run: |

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ func (m *Manager) GetRule(id string) *models.SyncRule {
101101
}
102102
}
103103
return nil
104-
}
104+
}

internal/config/config_test.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ import (
1111

1212
func 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) {
3636
func 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) {
5555
func 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) {
106106
func 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) {
138138
func 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

208208
func 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) {
223223
func 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+
}

internal/logger/logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (l *Logger) log(level LogLevel, format string, args ...any) {
6464
timestamp := time.Now().Format("2006-01-02 15:04:05")
6565
levelStr := []string{"DEBUG", "INFO", "WARN", "ERROR"}[level]
6666
message := fmt.Sprintf(format, args...)
67-
67+
6868
logLine := fmt.Sprintf("[%s] %s: %s", timestamp, levelStr, message)
6969

7070
if l.logger != nil {
@@ -90,4 +90,4 @@ func (l *Logger) Warn(format string, args ...any) {
9090

9191
func (l *Logger) Error(format string, args ...any) {
9292
l.log(ERROR, format, args...)
93-
}
93+
}

0 commit comments

Comments
 (0)