fixed review comments
Signed-off-by: akhilac1 <chetlapalle.akhila@gmail.com>
This commit is contained in:
parent
1243970b63
commit
5a06d2d980
|
@ -303,7 +303,7 @@ func parseMetadata(cmetadata configuration.Metadata) (metadata, error) {
|
|||
m.maxIdleTimeout = t
|
||||
}
|
||||
}
|
||||
if m.maxIdleTimeout == 0 {
|
||||
if m.maxIdleTimeout <= 0 {
|
||||
m.maxIdleTimeout = defaultMaxConnIdleTime
|
||||
}
|
||||
return m, nil
|
||||
|
@ -375,18 +375,13 @@ func (p *ConfigurationStore) isSubscriptionActive(req *configuration.SubscribeRe
|
|||
}
|
||||
|
||||
func (p *ConfigurationStore) isSubscribed(subscriptionID string, channel string, key string) bool {
|
||||
if val, yes := p.ActiveSubscriptions[channel]; yes {
|
||||
if val.uuid == subscriptionID && slices.Contains(val.keys, key) {
|
||||
return true
|
||||
}
|
||||
if val, yes := p.ActiveSubscriptions[channel]; yes && val.uuid == subscriptionID && slices.Contains(val.keys, key) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func validateInput(keys []string) error {
|
||||
if len(keys) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, key := range keys {
|
||||
if !allowedChars.MatchString(key) {
|
||||
return fmt.Errorf("invalid key : '%v'", key)
|
||||
|
@ -398,7 +393,7 @@ func validateInput(keys []string) error {
|
|||
func (p *ConfigurationStore) subscribeToChannel(ctx context.Context, pgNotifyChanList []string, req *configuration.SubscribeRequest, handler configuration.UpdateHandler) (string, error) {
|
||||
p.configLock.Lock()
|
||||
defer p.configLock.Unlock()
|
||||
var subscribeID string // TO_DO - duplicate trigger
|
||||
var subscribeID string
|
||||
for _, channel := range pgNotifyChanList {
|
||||
pgNotifyCmd := fmt.Sprintf(listenTemplate, channel)
|
||||
if sub, isActive := p.isSubscriptionActive(req); isActive {
|
||||
|
|
|
@ -43,6 +43,7 @@ func TestSelectAllQuery(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("Error building query: %v ", err)
|
||||
}
|
||||
assert.Nil(t, err, "Error building query: %v ", err)
|
||||
assert.Equal(t, expected, query, "did not get expected result. Got: '%v' , Expected: '%v'", query, expected)
|
||||
}
|
||||
|
||||
|
@ -56,9 +57,7 @@ func TestPostgresbuildQuery(t *testing.T) {
|
|||
|
||||
query, params, err := buildQuery(g, "cfgtbl")
|
||||
_ = params
|
||||
if err != nil {
|
||||
t.Errorf("Error building query: %v ", err)
|
||||
}
|
||||
assert.Nil(t, err, "Error building query: %v ", err)
|
||||
expected := "SELECT * FROM cfgtbl WHERE KEY IN ($1) AND $2 = $3"
|
||||
assert.Equal(t, expected, query, "did not get expected result. Got: '%v' , Expected: '%v'", query, expected)
|
||||
i := 0
|
||||
|
@ -102,3 +101,14 @@ func TestConnectAndQuery(t *testing.T) {
|
|||
err = mock.ExpectationsWereMet()
|
||||
assert.Nil(t, err, "pgxmock error in expectations were met")
|
||||
}
|
||||
|
||||
func TestValidateInput(t *testing.T) {
|
||||
keys := []string{"testKey1", "testKey2"}
|
||||
assert.Nil(t, validateInput(keys), "incorrect input provided: %v", keys)
|
||||
|
||||
var keys2 []string
|
||||
assert.Nil(t, validateInput(keys), "incorrect input provided: %v", keys2)
|
||||
|
||||
keys3 := []string{"Name 1=1"}
|
||||
assert.Error(t, validateInput(keys3), "invalid key : 'Name 1=1'")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue