1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package infrastructure
- import (
- "code.osinet.fr/fgm/kurz/domain"
- "testing"
- )
- const example_valid_http_url = "https://example.com"
- func TestEmptyRepo(test *testing.T) {
- domain.RegisterRepositories(
- MemoryShortURLRepository{},
- MemoryTargetURLRepository{},
- )
- _, err := domain.GetTargetURL("whatever")
- if err == nil {
- test.Error("Empty repository should not find a target for any URL")
- }
- s1, isNew, err := domain.GetShortURL(example_valid_http_url)
- 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(example_valid_http_url)
- 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)
- if err != nil {
- test.Error("Repository should find a target for an existing short URL")
- }
- if t != example_valid_http_url {
- test.Error("Target URL for a short URL should match the target it was created for")
- }
- }
|