-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change (build): remove vendor + remove vendor directory + use go mod instead + reduce code base in repository * chore (lint): fix lint warnings * change (keyvalue): refactor keyvalue package + create unittest + change some error handling in keyvalue package * change (git): update .gitignore
- Loading branch information
Showing
579 changed files
with
211 additions
and
450,398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
// nolint: gosec | ||
package crypto | ||
|
||
import ( | ||
"crypto/hmac" | ||
"crypto/sha1" | ||
"log" | ||
) | ||
|
||
func ComputeHMACSHA1(key []byte, data []byte) []byte { | ||
h := hmac.New(sha1.New, key) | ||
h.Write(data) | ||
_, err := h.Write(data) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
return h.Sum(nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package keyvalue | ||
|
||
import ( | ||
"database/sql" | ||
"testing" | ||
|
||
"github.com/DATA-DOG/go-sqlmock" | ||
_ "github.com/mattn/go-sqlite3" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type sqlStoreTestSuite struct { | ||
suite.Suite | ||
sqlDB *sql.DB | ||
mock sqlmock.Sqlmock | ||
} | ||
|
||
func (s *sqlStoreTestSuite) SetupTest() { | ||
conn, mock, err := sqlmock.New( | ||
sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual), | ||
) | ||
if err != nil { | ||
s.Fail("error creating db connection", err) | ||
} | ||
s.sqlDB = conn | ||
s.mock = mock | ||
} | ||
|
||
func (s *sqlStoreTestSuite) TearDownTest() { | ||
s.mock.ExpectClose() | ||
err := s.sqlDB.Close() | ||
if err != nil { | ||
s.Fail("error closing db connection", err) | ||
} | ||
if err := s.mock.ExpectationsWereMet(); err != nil { | ||
s.Fail("all expectation were not met", err) | ||
} | ||
} | ||
|
||
func (s *sqlStoreTestSuite) TestGetSuccessfully() { | ||
key := "foo" | ||
expected := "bar" | ||
s.mock.ExpectPrepare(_selectSQL). | ||
ExpectQuery(). | ||
WithArgs(key). | ||
WillReturnRows(sqlmock.NewRows([]string{"v"}).AddRow(expected)) | ||
|
||
// Do test | ||
store := &sqlStore{s.sqlDB} | ||
result, err := store.Get(key) | ||
s.NoError(err) | ||
s.Equal(expected, result, "expect result = %s", expected) | ||
if err := s.mock.ExpectationsWereMet(); err != nil { | ||
s.Fail("all expectation were not met", err) | ||
} | ||
|
||
} | ||
func (s *sqlStoreTestSuite) TestGetEmptyKey() { | ||
key := "foo" | ||
s.mock.ExpectPrepare(_selectSQL). | ||
ExpectQuery(). | ||
WithArgs(key). | ||
WillReturnError(sql.ErrNoRows) | ||
|
||
// Do test | ||
store := &sqlStore{s.sqlDB} | ||
result, err := store.Get(key) | ||
s.EqualError(err, ErrNoRecord.Error()) | ||
s.Empty(result) | ||
if err := s.mock.ExpectationsWereMet(); err != nil { | ||
s.Fail("all expectation were not met", err) | ||
} | ||
|
||
} | ||
|
||
func (s *sqlStoreTestSuite) TestDeleteSuccessfully() { | ||
key := "foo" | ||
s.mock.ExpectPrepare(_selectSQL). | ||
ExpectQuery(). | ||
WithArgs(key). | ||
WillReturnRows( | ||
sqlmock.NewRows([]string{"k", "v"}). | ||
AddRow(key, "bar"), | ||
) | ||
s.mock.ExpectExec(_deleteSQL). | ||
WithArgs(key). | ||
WillReturnResult(sqlmock.NewResult(1, 1)) | ||
|
||
// Do test | ||
store := &sqlStore{s.sqlDB} | ||
err := store.Delete(key) | ||
s.NoError(err) | ||
if err := s.mock.ExpectationsWereMet(); err != nil { | ||
s.Fail("all expectation were not met", err) | ||
} | ||
|
||
} | ||
func (s *sqlStoreTestSuite) TestDeleteEmptyKey() { | ||
key := "foo" | ||
s.mock.ExpectPrepare(_selectSQL). | ||
ExpectQuery(). | ||
WithArgs(key). | ||
WillReturnError(sql.ErrNoRows) | ||
|
||
// Do test | ||
store := &sqlStore{s.sqlDB} | ||
err := store.Delete(key) | ||
s.EqualError(err, ErrNoRecord.Error()) | ||
if err := s.mock.ExpectationsWereMet(); err != nil { | ||
s.Fail("all expectation were not met", err) | ||
} | ||
|
||
} | ||
|
||
func TestSqlStore(t *testing.T) { | ||
suite.Run(t, new(sqlStoreTestSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.