Browse Source

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 7 months ago
parent
commit
2d4e2fbbeb
3 changed files with 11 additions and 42 deletions
  1. 1
    6
      Makefile
  2. 4
    12
      pkg/db/db.go
  3. 6
    24
      pkg/db/db_test.go

+ 1
- 6
Makefile View File

@@ -12,10 +12,5 @@ test: lint
12 12
 	go test ./...
13 13
 
14 14
 .PHONY: lint
15
-lint: gometalinter
15
+lint:
16 16
 	gometalinter ./...
17
-
18
-.PHONY: gometalinter
19
-gometalinter:
20
-	go get github.com/alecthomas/gometalinter
21
-	gometalinter --install &> /dev/null

+ 4
- 12
pkg/db/db.go View File

@@ -44,7 +44,7 @@ func (d *DB) AddURL(shortURL string, longURL string) error {
44 44
 		return errors.New("the long URL needs to be a valid URL")
45 45
 	}
46 46
 
47
-	if err := d.DB.Update(func(tx *bolt.Tx) error {
47
+	return d.DB.Update(func(tx *bolt.Tx) error {
48 48
 		b := tx.Bucket([]byte("urls"))
49 49
 		if b == nil {
50 50
 			return errors.New("the bucket urls doesn't exist")
@@ -59,22 +59,14 @@ func (d *DB) AddURL(shortURL string, longURL string) error {
59 59
 		}
60 60
 
61 61
 		return nil
62
-	}); err != nil {
63
-		return err
64
-	}
65
-
66
-	return nil
62
+	})
67 63
 }
68 64
 
69 65
 // Initialize creates the required bucket
70 66
 func (d *DB) Initialize() error {
71
-	if err := d.DB.Update(func(tx *bolt.Tx) error {
67
+	return d.DB.Update(func(tx *bolt.Tx) error {
72 68
 		_, err := tx.CreateBucketIfNotExists([]byte("urls"))
73 69
 
74 70
 		return err
75
-	}); err != nil {
76
-		return err
77
-	}
78
-
79
-	return nil
71
+	})
80 72
 }

+ 6
- 24
pkg/db/db_test.go View File

@@ -72,11 +72,8 @@ func TestReadURLNotFound(t *testing.T) {
72 72
 
73 73
 		if err = boltDB.Update(func(tx *bolt.Tx) error {
74 74
 			_, err = tx.CreateBucket([]byte("urls"))
75
-			if err != nil {
76
-				return err
77
-			}
78 75
 
79
-			return nil
76
+			return err
80 77
 		}); err != nil {
81 78
 			t.Fatalf("error inserting test data to the DB: %v", err)
82 79
 		}
@@ -112,11 +109,8 @@ func TestAddURL(t *testing.T) {
112 109
 
113 110
 		if err = boltDB.Update(func(tx *bolt.Tx) error {
114 111
 			_, err = tx.CreateBucket([]byte("urls"))
115
-			if err != nil {
116
-				return err
117
-			}
118 112
 
119
-			return nil
113
+			return err
120 114
 		}); err != nil {
121 115
 			t.Fatalf("error inserting test data to the DB: %v", err)
122 116
 		}
@@ -146,11 +140,8 @@ func TestAddURLShortNoEmpty(t *testing.T) {
146 140
 
147 141
 		if err = boltDB.Update(func(tx *bolt.Tx) error {
148 142
 			_, err = tx.CreateBucket([]byte("urls"))
149
-			if err != nil {
150
-				return err
151
-			}
152 143
 
153
-			return nil
144
+			return err
154 145
 		}); err != nil {
155 146
 			t.Fatalf("error inserting test data to the DB: %v", err)
156 147
 		}
@@ -182,11 +173,8 @@ func TestAddURLLongNoEmpty(t *testing.T) {
182 173
 
183 174
 		if err = boltDB.Update(func(tx *bolt.Tx) error {
184 175
 			_, err = tx.CreateBucket([]byte("urls"))
185
-			if err != nil {
186
-				return err
187
-			}
188 176
 
189
-			return nil
177
+			return err
190 178
 		}); err != nil {
191 179
 			t.Fatalf("error inserting test data to the DB: %v", err)
192 180
 		}
@@ -218,11 +206,8 @@ func TestAddURLLongIsURL(t *testing.T) {
218 206
 
219 207
 		if err = boltDB.Update(func(tx *bolt.Tx) error {
220 208
 			_, err = tx.CreateBucket([]byte("urls"))
221
-			if err != nil {
222
-				return err
223
-			}
224 209
 
225
-			return nil
210
+			return err
226 211
 		}); err != nil {
227 212
 			t.Fatalf("error inserting test data to the DB: %v", err)
228 213
 		}
@@ -320,11 +305,8 @@ func TestAddURLErrInserting(t *testing.T) {
320 305
 
321 306
 		if err = boltDB.Update(func(tx *bolt.Tx) error {
322 307
 			_, err = tx.CreateBucket([]byte("urls"))
323
-			if err != nil {
324
-				return err
325
-			}
326 308
 
327
-			return nil
309
+			return err
328 310
 		}); err != nil {
329 311
 			t.Fatalf("error inserting test data to the DB: %v", err)
330 312
 		}

Loading…
Cancel
Save