12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package infrastructure
- import (
- "code.osinet.fr/fgm/kurz/domain"
- "testing"
- )
- func TestMemoryEmptyRepo(test *testing.T) {
- domain.RegisterRepositories(
- shortRepo,
- targetRepo,
- )
- _, err := domain.GetTargetURL("whatever", nil)
- if err == nil {
- test.Error("Empty repository should not find a target for any URL")
- }
- s1, isNew, err := domain.GetShortURL(exampleValidHTTPURL, nil)
- if err != nil {
- test.Error("Creating a short URL for a valid URL should not fail")
- }
- if !isNew {
- test.Error("The first short URL in an empty repository should be new")
- }
- s2, isNew, err := domain.GetShortURL(exampleValidHTTPURL, nil)
- if err != nil {
- test.Error("Creating a short URL for a valid URL should not fail")
- }
- if isNew {
- test.Error("The second short URL for an already shortened URL should not be new")
- }
- if s1 != s2 {
- test.Error("The second short URL for an already shortened URL should be the same as the first one")
- }
- t, err := domain.GetTargetURL(s1, nil)
- if err != nil {
- test.Error("Repository should find a target for an existing short URL")
- }
- if t != exampleValidHTTPURL {
- test.Error("Target URL for a short URL should match the target it was created for")
- }
- }
- func TestMemorySad(test *testing.T) {
- domain.RegisterRepositories(
- MemoryShortURLRepository{},
- MemoryTargetURLRepository{},
- )
- _, _, err := domain.GetShortURL("", nil)
- if err == nil {
- test.Error("Empty target URL has no valid short URL")
- }
- }
|