Skip to content

Commit

Permalink
make suggestions asked by ci
Browse files Browse the repository at this point in the history
  • Loading branch information
yannick2009 committed May 12, 2024
2 parents 350fa75 + 34eb1b8 commit 15b87ec
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions pkg/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Test_GetDBLoc(t *testing.T) {
os.Remove(actualPath)
})

assert.NoError(t, err)
require.NoError(t, err)
assert.Contains(t, actualPath, expectedWords[0])
assert.Contains(t, actualPath, expectedWords[1])
assert.Contains(t, actualPath, expectedWords[2])
Expand All @@ -45,7 +45,7 @@ func Test_GetDBLoc(t *testing.T) {
func Test_GetRecord(t *testing.T) {
t.Run("Test GetRecord", func(t *testing.T) {
actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
Expand All @@ -54,10 +54,10 @@ func Test_GetRecord(t *testing.T) {
expectedValue := "testValue"

err = db.WriteToDB(dbname, map[string]string{key: expectedValue}, bucketName)
assert.NoError(t, err)
require.NoError(t, err)

actualValue, err := db.GetRecord(dbname, key, bucketName)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, expectedValue, actualValue)
})

Expand All @@ -76,14 +76,14 @@ func Test_GetRecord(t *testing.T) {
t.Run("Test GetRecord with key not found", func(t *testing.T) {
expectedErr := db.ErrKeyNotFound
actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
})

err = db.WriteToDB(dbname, map[string]string{}, bucketName)
assert.NoError(t, err)
require.NoError(t, err)

actualValue, err := db.GetRecord(dbname, key, bucketName)

Expand All @@ -103,7 +103,7 @@ func Test_GetRecord(t *testing.T) {
func Test_WriteToDB(t *testing.T) {
t.Run("Test WriteToDB", func(t *testing.T) {
actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
Expand All @@ -117,11 +117,11 @@ func Test_WriteToDB(t *testing.T) {
bucketName := "testBucket"

err = db.WriteToDB(dbname, data, bucketName)
assert.NoError(t, err)
require.NoError(t, err)

// Verify that the data was written correctly
db, err := bolt.Open(actualPath, 0o600, nil)
assert.NoError(t, err)
require.NoError(t, err)
defer db.Close()

err = db.View(func(tx *bolt.Tx) error {
Expand All @@ -135,12 +135,12 @@ func Test_WriteToDB(t *testing.T) {

return nil
})
assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("Test WriteToDB with empty bucketname", func(t *testing.T) {
actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
Expand All @@ -160,7 +160,7 @@ func Test_WriteToDB(t *testing.T) {

t.Run("Test WriteToDB with empty map key", func(t *testing.T) {
actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
Expand Down Expand Up @@ -194,7 +194,7 @@ func Test_DeleteFromDb(t *testing.T) {
t.Run("Test DeleteFromDb", func(t *testing.T) {

actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
Expand All @@ -208,14 +208,14 @@ func Test_DeleteFromDb(t *testing.T) {
key := "key1"

err = db.WriteToDB(dbname, data, bucketName)
assert.NoError(t, err)
require.NoError(t, err)

err = db.DeleteFromDb(dbname, key, bucketName)
assert.NoError(t, err)
require.NoError(t, err)

// Verify that the key was deleted
db, err := bolt.Open(actualPath, 0o600, nil)
assert.NoError(t, err)
require.NoError(t, err)
defer db.Close()

err = db.View(func(tx *bolt.Tx) error {
Expand All @@ -227,7 +227,7 @@ func Test_DeleteFromDb(t *testing.T) {

return nil
})
assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("Test DeleteFromDb with empty dbname", func(t *testing.T) {
Expand All @@ -243,7 +243,7 @@ func Test_DeleteFromDb(t *testing.T) {
t.Run("Test DeleteFromDb with key not found", func(t *testing.T) {

actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
Expand All @@ -257,11 +257,11 @@ func Test_DeleteFromDb(t *testing.T) {
key := "key4"

err = db.WriteToDB(dbname, data, bucketName)
assert.NoError(t, err)
require.NoError(t, err)

err = db.DeleteFromDb(dbname, key, bucketName)

assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("Test DeleteFromDb with bucket not found", func(t *testing.T) {
Expand All @@ -279,7 +279,7 @@ func Test_ListAllRecords(t *testing.T) {
t.Run("Test ListAllRecords", func(t *testing.T) {

actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
Expand All @@ -292,12 +292,12 @@ func Test_ListAllRecords(t *testing.T) {
}

err = db.WriteToDB(dbname, data, bucketName)
assert.NoError(t, err)
require.NoError(t, err)

records, err := db.GetAllRecords(dbname, bucketName)

assert.NoError(t, err)
assert.Equal(t,data, records)
require.NoError(t, err)
assert.Equal(t, data, records)
})

t.Run("Test ListAllRecords with empty dbname", func(t *testing.T) {
Expand All @@ -324,7 +324,7 @@ func Test_UpdateRec(t *testing.T) {
t.Run("Test UpdateRec", func(t *testing.T) {

actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
Expand All @@ -340,14 +340,14 @@ func Test_UpdateRec(t *testing.T) {
newValue := "updatedValue"

err = db.WriteToDB(dbname, data, bucketName)
assert.NoError(t, err)
require.NoError(t, err)

err = db.UpdateRec(dbname, key, newValue, bucketName)
assert.NoError(t, err)
require.NoError(t, err)

// Verify that the value was updated
db, err := bolt.Open(actualPath, 0o600, nil)
assert.NoError(t, err)
require.NoError(t, err)
defer db.Close()

err = db.View(func(tx *bolt.Tx) error {
Expand All @@ -358,7 +358,7 @@ func Test_UpdateRec(t *testing.T) {
assert.Equal(t, []byte(newValue), value)
return nil
})
assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("Test UpdateRec with empty dbname", func(t *testing.T) {
Expand All @@ -373,7 +373,7 @@ func Test_UpdateRec(t *testing.T) {
t.Run("Test UpdateRec with key not found", func(t *testing.T) {

actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
Expand All @@ -388,7 +388,7 @@ func Test_UpdateRec(t *testing.T) {
newValue := "updatedValue"

err = db.WriteToDB(dbname, data, bucketName)
assert.NoError(t, err)
require.NoError(t, err)

err = db.UpdateRec(dbname, key, newValue, bucketName)

Expand All @@ -410,14 +410,14 @@ func Test_UpdateRec(t *testing.T) {
func Test_DeleteDb(t *testing.T) {
t.Run("Test DeleteDb", func(t *testing.T) {
actualPath, err := db.GetDBLoc(dbname)
assert.NoError(t, err)
require.NoError(t, err)

t.Cleanup(func() {
os.Remove(actualPath)
})

err = db.DeleteDb(dbname)
assert.NoError(t, err)
require.NoError(t, err)

// Verify that the database file is deleted
_, err = os.Stat(actualPath)
Expand Down

0 comments on commit 15b87ec

Please sign in to comment.