Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
keuin committed Sep 16, 2022
1 parent e90c617 commit 495c915
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
24 changes: 24 additions & 0 deletions common/bytesize_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package common

import (
"testing"
)

func TestPrettyBytes(t *testing.T) {
tests := []struct {
Expected string
Actual string
}{
{"128 Byte", PrettyBytes(128)},
{"128.00 KiB", PrettyBytes(128 * 1024)},
{"128.00 MiB", PrettyBytes(128 * 1024 * 1024)},
{"128.00 GiB", PrettyBytes(128 * 1024 * 1024 * 1024)},
{"128.00 TiB", PrettyBytes(128 * 1024 * 1024 * 1024 * 1024)},
{"131072.00 TiB", PrettyBytes(128 * 1024 * 1024 * 1024 * 1024 * 1024)},
}
for i, tc := range tests {
if tc.Expected != tc.Actual {
t.Fatalf("Test %v failed: %v", i, tc)
}
}
}
32 changes: 32 additions & 0 deletions common/urlparse_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package common

import "testing"

func TestGetFileExtensionFromUrl(t *testing.T) {
tests := []struct {
Expected string
Actual string
}{
{Expected: "html"},
{Expected: "htm"},
{Expected: "flv"},
}
var err error
tests[0].Actual, err = GetFileExtensionFromUrl("http://www.example.com/index.html")
if err != nil {
t.Fatalf("GetFileExtensionFromUrl: %v", err)
}
tests[1].Actual, err = GetFileExtensionFromUrl("https://www.example.com/index.htm")
if err != nil {
t.Fatalf("GetFileExtensionFromUrl: %v", err)
}
tests[2].Actual, err = GetFileExtensionFromUrl("https://www.example.com/video.flv?a=1&b=2flv")
if err != nil {
t.Fatalf("GetFileExtensionFromUrl: %v", err)
}
for i, tc := range tests {
if tc.Expected != tc.Actual {
t.Fatalf("Test %v failed: %v", i, tc)
}
}
}

0 comments on commit 495c915

Please sign in to comment.