Bläddra i källkod

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 1 år sedan
förälder
incheckning
2d4e2fbbeb
3 ändrade filer med 11 tillägg och 42 borttagningar
  1. +1
    -6
      Makefile
  2. +4
    -12
      pkg/db/db.go
  3. +6
    -24
      pkg/db/db_test.go

+ 1
- 6
Makefile Visa fil

@@ -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 Visa fil

@@ -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 Visa fil

@@ -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)
}

Laddar…
Avbryt
Spara