Skip to content

Commit

Permalink
UTILS: Add utility pkg for helper functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cian911 committed Dec 11, 2021
1 parent ce85df1 commit d4af193
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package utils

import "path/filepath"

func ExtractFileExt(path string) string {
return filepath.Ext(path)
}
30 changes: 30 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package utils

import "testing"

const (
filePath = "/home/test/file.mp4"
dirPath = "/home/test"
diffDirPath = "/home/test.movies/"
)

func TestUtils(t *testing.T) {
tests := []struct {
input string
expectedOutput string
}{
{"/home/test/movie.mp4", ".mp4"},
{"/home/test/movie.maaaap4.aaa.mp4", ".mp4"},
{"/home/test/", ""},
{"/home/test", ""},
{"/home/test/movie.mp4/", ""},
}

for _, tt := range tests {
got := ExtractFileExt(tt.input)

if got != tt.expectedOutput {
t.Errorf("Failed extracting file extention: got=%s, want=%s", got, tt.expectedOutput)
}
}
}

0 comments on commit d4af193

Please sign in to comment.