Quellcode durchsuchen

Updated Makefile and improved the DB package

Now the Makefine isn't the responsible of the installation
of gometalinter. The DB package improvements are corrections
that were found using gometalinter
tags/v1.0.0^2
Néfix Estrada vor 1 Jahr
Ursprung
Commit
2d4e2fbbeb
3 geänderte Dateien mit 11 neuen und 42 gelöschten Zeilen
  1. +1
    -6
      Makefile
  2. +4
    -12
      pkg/db/db.go
  3. +6
    -24
      pkg/db/db_test.go

+ 1
- 6
Makefile Datei anzeigen

@@ -12,10 +12,5 @@ test: lint
go test ./...

.PHONY: lint
lint: gometalinter
lint:
gometalinter ./...

.PHONY: gometalinter
gometalinter:
go get github.com/alecthomas/gometalinter
gometalinter --install &> /dev/null

+ 4
- 12
pkg/db/db.go Datei anzeigen

@@ -44,7 +44,7 @@ func (d *DB) AddURL(shortURL string, longURL string) error {
return errors.New("the long URL needs to be a valid URL")
}

if err := d.DB.Update(func(tx *bolt.Tx) error {
return d.DB.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("urls"))
if b == nil {
return errors.New("the bucket urls doesn't exist")
@@ -59,22 +59,14 @@ func (d *DB) AddURL(shortURL string, longURL string) error {
}

return nil
}); err != nil {
return err
}

return nil
})
}

// Initialize creates the required bucket
func (d *DB) Initialize() error {
if err := d.DB.Update(func(tx *bolt.Tx) error {
return d.DB.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucketIfNotExists([]byte("urls"))

return err
}); err != nil {
return err
}

return nil
})
}

+ 6
- 24
pkg/db/db_test.go Datei anzeigen

@@ -72,11 +72,8 @@ func TestReadURLNotFound(t *testing.T) {

if err = boltDB.Update(func(tx *bolt.Tx) error {
_, err = tx.CreateBucket([]byte("urls"))
if err != nil {
return err
}

return nil
return err
}); err != nil {
t.Fatalf("error inserting test data to the DB: %v", err)
}
@@ -112,11 +109,8 @@ func TestAddURL(t *testing.T) {

if err = boltDB.Update(func(tx *bolt.Tx) error {
_, err = tx.CreateBucket([]byte("urls"))
if err != nil {
return err
}

return nil
return err
}); err != nil {
t.Fatalf("error inserting test data to the DB: %v", err)
}
@@ -146,11 +140,8 @@ func TestAddURLShortNoEmpty(t *testing.T) {

if err = boltDB.Update(func(tx *bolt.Tx) error {
_, err = tx.CreateBucket([]byte("urls"))
if err != nil {
return err
}

return nil
return err
}); err != nil {
t.Fatalf("error inserting test data to the DB: %v", err)
}
@@ -182,11 +173,8 @@ func TestAddURLLongNoEmpty(t *testing.T) {

if err = boltDB.Update(func(tx *bolt.Tx) error {
_, err = tx.CreateBucket([]byte("urls"))
if err != nil {
return err
}

return nil
return err
}); err != nil {
t.Fatalf("error inserting test data to the DB: %v", err)
}
@@ -218,11 +206,8 @@ func TestAddURLLongIsURL(t *testing.T) {

if err = boltDB.Update(func(tx *bolt.Tx) error {
_, err = tx.CreateBucket([]byte("urls"))
if err != nil {
return err
}

return nil
return err
}); err != nil {
t.Fatalf("error inserting test data to the DB: %v", err)
}
@@ -320,11 +305,8 @@ func TestAddURLErrInserting(t *testing.T) {

if err = boltDB.Update(func(tx *bolt.Tx) error {
_, err = tx.CreateBucket([]byte("urls"))
if err != nil {
return err
}

return nil
return err
}); err != nil {
t.Fatalf("error inserting test data to the DB: %v", err)
}

Laden…
Abbrechen
Speichern