|
|
|
@ -5,6 +5,8 @@ import ( |
|
|
|
"strings" |
|
|
|
"testing" |
|
|
|
|
|
|
|
"github.com/sirupsen/logrus" |
|
|
|
|
|
|
|
"github.com/maxibanki/golang-url-shortener/config" |
|
|
|
) |
|
|
|
|
|
|
|
@ -41,13 +43,13 @@ func TestGenerateRandomString(t *testing.T) { |
|
|
|
|
|
|
|
func TestNewStore(t *testing.T) { |
|
|
|
t.Run("create store without file name provided", func(r *testing.T) { |
|
|
|
_, err := New(config.Store{}) |
|
|
|
_, err := New(config.Store{}, logrus.New()) |
|
|
|
if !strings.Contains(err.Error(), "could not open bolt DB database") { |
|
|
|
t.Fatalf("unexpected error: %v", err) |
|
|
|
} |
|
|
|
}) |
|
|
|
t.Run("create store with correct arguments", func(r *testing.T) { |
|
|
|
store, err := New(validConfig) |
|
|
|
store, err := New(validConfig, logrus.New()) |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("unexpected error: %v", err) |
|
|
|
} |
|
|
|
@ -59,7 +61,7 @@ func TestCreateEntry(t *testing.T) { |
|
|
|
store, err := New(config.Store{ |
|
|
|
DBPath: testingDBName, |
|
|
|
ShortedIDLength: 1, |
|
|
|
}) |
|
|
|
}, logrus.New()) |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("unexpected error: %v", err) |
|
|
|
} |
|
|
|
@ -77,7 +79,7 @@ func TestCreateEntry(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestGetEntryByID(t *testing.T) { |
|
|
|
store, err := New(validConfig) |
|
|
|
store, err := New(validConfig, logrus.New()) |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("unexpected error: %v", err) |
|
|
|
} |
|
|
|
@ -93,7 +95,7 @@ func TestGetEntryByID(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestIncreaseVisitCounter(t *testing.T) { |
|
|
|
store, err := New(validConfig) |
|
|
|
store, err := New(validConfig, logrus.New()) |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("could not create store: %v", err) |
|
|
|
} |
|
|
|
|