Skip to content

Commit 4741a1f

Browse files
feat: ✅ validate config test added
As part of #46, adding tests incrementally
1 parent 20b04da commit 4741a1f

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

pkg/config/validate_test.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package config
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestValidateConfig(t *testing.T) {
8+
tests := []struct {
9+
name string
10+
cfg Config
11+
wantErr bool
12+
}{
13+
{
14+
name: "Empty Username",
15+
cfg: Config{
16+
Username: "",
17+
},
18+
wantErr: true,
19+
},
20+
{
21+
name: "Empty Token",
22+
cfg: Config{
23+
Username: "test",
24+
Token: "",
25+
},
26+
wantErr: true,
27+
},
28+
{
29+
name: "Empty BackupDir",
30+
cfg: Config{
31+
Username: "test",
32+
Token: "test",
33+
BackupDir: "",
34+
},
35+
wantErr: true,
36+
},
37+
{
38+
name: "Empty Server Domain",
39+
cfg: Config{
40+
Username: "test",
41+
Token: "test",
42+
BackupDir: "test",
43+
Server: Server{
44+
Domain: "",
45+
},
46+
},
47+
wantErr: true,
48+
},
49+
{
50+
name: "Invalid Server Protocol",
51+
cfg: Config{
52+
Username: "test",
53+
Token: "test",
54+
BackupDir: "test",
55+
Server: Server{
56+
Domain: "test",
57+
Protocol: "ftp",
58+
},
59+
},
60+
wantErr: true,
61+
},
62+
{
63+
name: "Empty Workspace for Bitbucket",
64+
cfg: Config{
65+
Username: "test",
66+
Token: "test",
67+
BackupDir: "test",
68+
Server: Server{
69+
Domain: "test",
70+
Protocol: "https",
71+
},
72+
Platform: "bitbucket",
73+
Workspace: "",
74+
},
75+
wantErr: true,
76+
},
77+
{
78+
name: "Invalid Cron Expression",
79+
cfg: Config{
80+
Username: "test",
81+
Token: "test",
82+
BackupDir: "test",
83+
Server: Server{
84+
Domain: "test",
85+
Protocol: "https",
86+
},
87+
Cron: "invalid",
88+
},
89+
wantErr: true,
90+
},
91+
{
92+
name: "Invalid Clone Type",
93+
cfg: Config{
94+
Username: "test",
95+
Token: "test",
96+
BackupDir: "test",
97+
Server: Server{
98+
Domain: "test",
99+
Protocol: "https",
100+
},
101+
CloneType: "invalid",
102+
},
103+
wantErr: true,
104+
},
105+
{
106+
name: "Valid Config",
107+
cfg: Config{
108+
Username: "test",
109+
Token: "test",
110+
BackupDir: "test",
111+
Server: Server{
112+
Domain: "test",
113+
Protocol: "https",
114+
},
115+
CloneType: "bare",
116+
},
117+
wantErr: false,
118+
},
119+
}
120+
121+
for _, tt := range tests {
122+
t.Run(tt.name, func(t *testing.T) {
123+
if err := ValidateConfig(tt.cfg); (err != nil) != tt.wantErr {
124+
t.Errorf("ValidateConfig() error = %v, wantErr %v", err, tt.wantErr)
125+
}
126+
})
127+
}
128+
}

0 commit comments

Comments
 (0)