Skip to content

Commit

Permalink
Merge pull request #20 from cldcvr/fix/linting_issues
Browse files Browse the repository at this point in the history
fix: logger_test linting issue fixed
  • Loading branch information
ankitmalikg2 authored Dec 21, 2020
2 parents 84d4545 + 02968b8 commit b39d50a
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 276 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ Add the configuration in the given files:
| ------ | ------ |
| GoogleProjectID | Your Google Project ID |
| SpannerDb | Your Spanner Database Name |
| QueryLimit | Default limit for data|

For example:
```
{
"GoogleProjectID" : "first-project",
"SpannerDb" : "test-db"
"GoogleProjectID" : "first-project",
"SpannerDb" : "test-db",
"QueryLimit" : 5000
}
```

Expand Down
4 changes: 2 additions & 2 deletions api/v1/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func queryResponse(query models.Query, c *gin.Context) {
}

if query.Limit == 0 {
query.Limit = 5000
query.Limit = config.ConfigurationMap.QueryLimit
}
query.ExpressionAttributeNames = ChangeColumnToSpannerExpressionName(query.TableName, query.ExpressionAttributeNames)
query = ReplaceHashRangeExpr(query)
Expand Down Expand Up @@ -550,7 +550,7 @@ func Update(c *gin.Context) {
}
}

// BatchWriteItem put & delte items in/from table
// BatchWriteItem put & delete items in/from table
// @Description Batch Write Item for putting and deleting data in/from table
// @Summary Batch Write Items from table
// @ID batch-write-rows
Expand Down
3 changes: 2 additions & 1 deletion config-files/production/config-production.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"GoogleProjectID": "Your Google Project ID",
"SpannerDb": "Your Spanner Database Name"
"SpannerDb": "Your Spanner Database Name",
"QueryLimit": 5000
}
3 changes: 2 additions & 1 deletion config-files/staging/config-staging.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"GoogleProjectID": "Your Google Project ID",
"SpannerDb": "Your Spanner Database Name"
"SpannerDb": "Your Spanner Database Name",
"QueryLimit": 5000
}
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
type Configuration struct {
GoogleProjectID string
SpannerDb string
QueryLimit int64
}

var once sync.Once
Expand Down
6 changes: 3 additions & 3 deletions initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"github.com/cloudspannerecosystem/dynamodb-adapter/storage"
)

// InitAll - this will initiliaze all the project object
// Config, storage and all other global objects are initiliaze
// InitAll - this will initialize all the project object
// Config, storage and all other global objects are initialize
func InitAll(box *rice.Box) error {
config.InitConfig(box)
storage.InitliazeDriver()
storage.InitializeDriver()
err := spanner.ParseDDL(true)
if err != nil {
return err
Expand Down
68 changes: 35 additions & 33 deletions pkg/errors/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,38 @@

package errors

// func TestInit(t *testing.T) {
// box, err := rice.FindBox("../../errors")
// assert.NoError(t, err)
// Init(box)
// }

// func TestNew(t *testing.T) {
// e := New("E0001")
// assert.Error(t, e)
// code, err := HTTPResponse(e)
// assert.NotNil(t, err)
// assert.Equal(t, http.StatusInternalServerError, code)
// }

// func TestHTTPResponse(t *testing.T) {
// e := New("E0001")
// assert.Error(t, e)
// code, err := e.HTTPResponse()
// assert.NotNil(t, err)
// assert.Equal(t, http.StatusInternalServerError, code)
// }

// func TestNewForExceptionalError(t *testing.T) {
// e := New("E1001")
// assert.Error(t, e)
// }

// func TestNewForSystemErrors(t *testing.T) {
// code, e := HTTPResponse(errors.New("Test"))
// assert.NotNil(t, e)
// assert.Equal(t, http.StatusInternalServerError, code)

// }
import (
"errors"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

func TestNew(t *testing.T) {
e := New("E0001")
assert.Error(t, e)
code, err := HTTPResponse(e, nil)
assert.NotNil(t, err)
assert.Equal(t, http.StatusBadRequest, code)
}

func TestHTTPResponse(t *testing.T) {
e := New("E0001")
assert.Error(t, e)
code, err := e.HTTPResponse(nil)
assert.NotNil(t, err)
assert.Equal(t, http.StatusBadRequest, code)
}

func TestNewForExceptionalError(t *testing.T) {
e := New("E1001")
assert.Error(t, e)
}

func TestNewForSystemErrors(t *testing.T) {
code, e := HTTPResponse(errors.New("Test"), nil)
assert.NotNil(t, e)
assert.Equal(t, http.StatusInternalServerError, code)

}
2 changes: 1 addition & 1 deletion pkg/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestLogError(t *testing.T) {
}
LogError(err)
}

func TestLogInfo(t *testing.T) {
info := struct {
Info string
Expand All @@ -44,7 +45,6 @@ func TestLogDebug(t *testing.T) {
LogDebug(info)
}

// above shows the Benchmark for using LogError in Project
func BenchmarkLogError(b *testing.B) {
err := struct {
Error string
Expand Down
8 changes: 4 additions & 4 deletions service/services/config-control.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ func fetchConfigData() {

func parseConfig(table string, config string, count int) {
tokens := strings.Split(config, ",")
if tokens[0] == "1" {
if len(tokens) >= 1 && tokens[0] == "1" {
models.ConfigController.ReadMap[table] = struct{}{}
}
if tokens[1] == "1" {
if len(tokens) >= 2 && tokens[1] == "1" {
models.ConfigController.WriteMap[table] = struct{}{}
}
if len(tokens) > 2 {
Expand All @@ -158,8 +158,8 @@ func parseConfig(table string, config string, count int) {
}
}

// IsMyStreamEnabled checks if a table is enabaled for streaming or not
func IsMyStreamEnabled(tableName string) bool {
// IsStreamEnabled checks if a table is enabled for streaming or not
func IsStreamEnabled(tableName string) bool {
models.ConfigController.Mux.RLock()
defer models.ConfigController.Mux.RUnlock()
_, ok := models.ConfigController.StreamEnable[tableName]
Expand Down
4 changes: 2 additions & 2 deletions service/services/config-control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
}
}

func TestIsMyStreamEnabled(t *testing.T) {
func TestIsStreamEnabled(t *testing.T) {
tests := []struct {
testName string
tableName string
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestIsMyStreamEnabled(t *testing.T) {
}

for _, tc := range tests {
got := IsMyStreamEnabled(tc.tableName)
got := IsStreamEnabled(tc.tableName)
assert.Equal(t, got, tc.want)
}
}
Expand Down
Loading

0 comments on commit b39d50a

Please sign in to comment.