Skip to content

Commit 0199f67

Browse files
add: tests
1 parent 1940ac4 commit 0199f67

File tree

5 files changed

+82
-26
lines changed

5 files changed

+82
-26
lines changed

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Go Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "**" # Run on any pull request, regardless of the source branch
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: "1.23" # Specify your Go version here
20+
21+
- name: Install dependencies
22+
run: go mod download
23+
24+
- name: Run tests
25+
run: go test ./... -v

main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ func main() {
1818

1919
flag.Parse()
2020

21-
utils.NullChecker("source", *source_ftp)
22-
utils.NullChecker("destination", *destination_ftp)
21+
if utils.NullChecker(*source_ftp) {
22+
log.Fatal("source_ftp Empty")
23+
}
24+
if utils.NullChecker(*destination_ftp) {
25+
log.Fatal("destination_ftp Empty")
26+
}
2327

2428
bsvalue := *bytesize
2529

utils/parsers.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,3 @@ func ParseInput(key string, furl string) (map[string]string, error) {
3939

4040
return params, nil
4141
}
42-
43-
func NullChecker(key string, ftpurl string) {
44-
// Check if string is null
45-
if ftpurl == "" {
46-
log.Panicf("Error: Empty URL for %s", key)
47-
}
48-
}
49-
50-
func SchemeValidator(source, dest, key string) bool {
51-
if source == dest {
52-
if source == key {
53-
return true
54-
}
55-
}
56-
return false
57-
}
58-
59-
func FtpParamsValidator(params map[string]string) {
60-
for k, v := range params {
61-
if v == "" {
62-
log.Panicf("Null Values passed for %v", k)
63-
}
64-
}
65-
}

utils/validators.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package utils
2+
3+
import (
4+
"log"
5+
)
6+
7+
func NullChecker(ftpurl string) bool {
8+
// Check if string is null
9+
return ftpurl == ""
10+
}
11+
12+
func SchemeValidator(source, dest, key string) bool {
13+
if source == dest {
14+
if source == key {
15+
return true
16+
}
17+
}
18+
return false
19+
}
20+
21+
func FtpParamsValidator(params map[string]string) {
22+
for k, v := range params {
23+
if v == "" {
24+
log.Panicf("Null Values passed for %v", k)
25+
}
26+
}
27+
}

utils/validators_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package utils
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestNullChecker(t *testing.T) {
8+
test := []struct {
9+
input string
10+
expected bool
11+
}{
12+
{"", true},
13+
{"ftp://user:password@host/path", false},
14+
}
15+
16+
for _, tt := range test {
17+
t.Run(tt.input, func(t *testing.T) {
18+
result := NullChecker(tt.input)
19+
if result != tt.expected {
20+
t.Errorf("Expected %v, got %v", tt.expected, result)
21+
}
22+
})
23+
}
24+
}

0 commit comments

Comments
 (0)