-
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.
- Loading branch information
1 parent
6e1ed7c
commit 59761f5
Showing
9 changed files
with
295 additions
and
20 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
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
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,62 @@ | ||
package tiny_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"sanathk.com/tinyurl/internal/tiny" | ||
"sanathk.com/tinyurl/pkg/fakes" | ||
) | ||
|
||
func TestServiceInit(t *testing.T) { | ||
fakeDB := fakes.FakePostgresInterface{} | ||
|
||
_, err := tiny.NewService(context.Background(), &fakeDB) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestServiceCreateTinyURL(t *testing.T) { | ||
fakeDB := fakes.FakePostgresInterface{} | ||
|
||
svc, err := tiny.NewService(context.Background(), &fakeDB) | ||
require.NoError(t, err) | ||
|
||
type testcase struct { | ||
name string | ||
in tiny.TinyURLRequest | ||
expected tiny.TinyURLResponse | ||
} | ||
|
||
validExpiryTime := time.Now().Add(10 * time.Hour) | ||
validOriginalLink := "https://www.sanathk.com" | ||
|
||
testcases := []testcase{ | ||
{ | ||
name: "valid expiry and original", | ||
in: tiny.TinyURLRequest{ | ||
Expiry: validExpiryTime, | ||
Original: validOriginalLink, | ||
}, | ||
expected: tiny.TinyURLResponse{ | ||
Expiry: validExpiryTime, | ||
Original: validOriginalLink, | ||
}, | ||
// TODO: add more tests: | ||
// Negative Cases: | ||
// * invalid time | ||
// * invalid or empty url | ||
// * max url length for hashing? | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
resp, err := svc.CreateTinyURL(context.Background(), tc.in) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, tc.expected.Original, resp.Original) | ||
require.Equal(t, tc.expected.Expiry, resp.Expiry) | ||
require.NotEqual(t, tc.expected.Original, resp.Tinyurl) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
package fakes | ||
|
||
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate | ||
|
||
//counterfeiter:generate -o ./ ../postgres PostgresInterface |
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
Oops, something went wrong.