-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add service to check whether a filename exist in array of filenames * feat: only upload files that do not exist yet in the cloud
- Loading branch information
Showing
3 changed files
with
76 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package service | ||
|
||
// Contains tells whether b exist in a. | ||
func Contains(a []string, b string) bool { | ||
for _, n := range a { | ||
if b == n { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package service | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestContains(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
sample []string | ||
check string | ||
expect bool | ||
}{ | ||
{ | ||
name: "Should true if `sample` contains string `check`", | ||
sample: []string{"one.zip", "two.txt", "three.mp4"}, | ||
check: "two.txt", | ||
expect: true, | ||
}, | ||
{ | ||
name: "Should false if `sample` does not contains string `check`", | ||
sample: []string{"one.zip", "two.txt", "three.mp4"}, | ||
check: "one.txt", | ||
expect: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
out := Contains(tc.sample, tc.check) | ||
assert.Equal(t, tc.expect, out) | ||
}) | ||
} | ||
} |