Skip to content

Commit 14ba743

Browse files
refactor: logic and add test
1 parent 2f5023a commit 14ba743

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

utils/validators.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ func NullChecker(ftpurl string) bool {
66
}
77

88
func SchemeValidator(source, dest, key string) bool {
9-
if source == dest {
10-
if source == key {
11-
return true
12-
}
13-
}
14-
return false
9+
return (source == dest && dest == key)
1510
}
1611

1712
func FtpParamsValidator(params map[string]string) bool {

utils/validators_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ func TestNullChecker(t *testing.T) {
2323
}
2424
}
2525

26+
func TestSchemeValidator(t *testing.T) {
27+
test := []struct {
28+
source string
29+
dest string
30+
key string
31+
expected bool
32+
}{
33+
{"ftp", "ftp", "ftp", true},
34+
{"sftp", "ftp", "ftp", false},
35+
{"sftp", "sftp", "ftp", false},
36+
}
37+
for _, tt := range test {
38+
t.Run(tt.source, func(t *testing.T) {
39+
result := SchemeValidator(tt.source, tt.dest, tt.key)
40+
if result != tt.expected {
41+
t.Errorf("Expected %v, got %v", tt.expected, result)
42+
}
43+
})
44+
}
45+
}
46+
2647
func TestFtpParamsValidator(t *testing.T) {
2748
test := []struct {
2849
input map[string]string

0 commit comments

Comments
 (0)