Skip to content

Commit

Permalink
fix unit tests and linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Feb 20, 2024
1 parent 1297481 commit c1559c5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/elasticClientCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func elasticBulkRequestResponseHandler(res *esapi.Response) error {
return fmt.Errorf("%s", res.String())
}

bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("%w cannot read elastic response body bytes", err)
}
Expand Down
2 changes: 2 additions & 0 deletions integrationtests/valuesIndex_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integrationtests

package integrationtests

import (
Expand Down
8 changes: 4 additions & 4 deletions process/elasticproc/accounts/serialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestSerializeAccounts(t *testing.T) {
require.Equal(t, 1, len(buffSlice.Buffers()))

expectedRes := `{ "update" : {"_index": "accounts", "_id" : "addr1" } }
{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx._source = params.account} else {if (ctx._source.containsKey('timestamp')) {if (ctx._source.timestamp <= params.account.timestamp) {ctx._source = params.account}} else {ctx._source = params.account}}","lang": "painless","params": { "account": {"address":"addr1","nonce":1,"balance":"50","balanceNum":0.1,"shardID":0} }},"upsert": {}}
{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx._source = params.account} else {if ((!ctx._source.containsKey('timestamp')) || (ctx._source.timestamp <= params.account.timestamp) ) {params.account.forEach((key, value) -> {ctx._source[key] = value;});}}","lang": "painless","params": { "account": {"address":"addr1","nonce":1,"balance":"50","balanceNum":0.1,"shardID":0} }},"upsert": {}}
`
require.Equal(t, expectedRes, buffSlice.Buffers()[0].String())
}
Expand All @@ -81,7 +81,7 @@ func TestSerializeAccountsESDTNonceZero(t *testing.T) {
require.Equal(t, 1, len(buffSlice.Buffers()))

expectedRes := `{ "update" : {"_index": "accountsesdt", "_id" : "addr1-token-abcd-00" } }
{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx._source = params.account} else {if (ctx._source.containsKey('timestamp')) {if (ctx._source.timestamp <= params.account.timestamp) {ctx._source = params.account}} else {ctx._source = params.account}}","lang": "painless","params": { "account": {"address":"addr1","nonce":1,"balance":"10000000000000","balanceNum":1,"token":"token-abcd","properties":"000","timestamp":123,"shardID":0} }},"upsert": {}}
{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx._source = params.account} else {if ((!ctx._source.containsKey('timestamp')) || (ctx._source.timestamp <= params.account.timestamp) ) {params.account.forEach((key, value) -> {ctx._source[key] = value;});}}","lang": "painless","params": { "account": {"address":"addr1","nonce":1,"balance":"10000000000000","balanceNum":1,"token":"token-abcd","properties":"000","timestamp":123,"shardID":0} }},"upsert": {}}
`
require.Equal(t, expectedRes, buffSlice.Buffers()[0].String())
}
Expand All @@ -107,7 +107,7 @@ func TestSerializeAccountsESDT(t *testing.T) {
require.Equal(t, 1, len(buffSlice.Buffers()))

expectedRes := `{ "update" : {"_index": "accountsesdt", "_id" : "addr1-token-0001-05" } }
{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx._source = params.account} else {if (ctx._source.containsKey('timestamp')) {if (ctx._source.timestamp <= params.account.timestamp) {ctx._source = params.account}} else {ctx._source = params.account}}","lang": "painless","params": { "account": {"address":"addr1","nonce":1,"balance":"10000000000000","balanceNum":1,"token":"token-0001","tokenNonce":5,"properties":"000","shardID":0} }},"upsert": {}}
{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx._source = params.account} else {if ((!ctx._source.containsKey('timestamp')) || (ctx._source.timestamp <= params.account.timestamp) ) {params.account.forEach((key, value) -> {ctx._source[key] = value;});}}","lang": "painless","params": { "account": {"address":"addr1","nonce":1,"balance":"10000000000000","balanceNum":1,"token":"token-0001","tokenNonce":5,"properties":"000","shardID":0} }},"upsert": {}}
`
require.Equal(t, expectedRes, buffSlice.Buffers()[0].String())
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestSerializeAccountsNFTWithMedaData(t *testing.T) {
require.Equal(t, 1, len(buffSlice.Buffers()))

expectedRes := `{ "update" : {"_index": "accountsesdt", "_id" : "addr1-token-0001-16" } }
{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx._source = params.account} else {if (ctx._source.containsKey('timestamp')) {if (ctx._source.timestamp <= params.account.timestamp) {ctx._source = params.account}} else {ctx._source = params.account}}","lang": "painless","params": { "account": {"address":"addr1","nonce":1,"balance":"10000000000000","balanceNum":1,"token":"token-0001","identifier":"token-0001-5","tokenNonce":22,"properties":"000","data":{"name":"nft","creator":"010101","royalties":1,"hash":"aGFzaA==","uris":["dXJp"],"tags":["test","free","fun"],"attributes":"dGFnczp0ZXN0LGZyZWUsZnVuO2Rlc2NyaXB0aW9uOlRoaXMgaXMgYSB0ZXN0IGRlc2NyaXB0aW9uIGZvciBhbiBhd2Vzb21lIG5mdA==","metadata":"metadata-test","nonEmptyURIs":true,"whiteListedStorage":false},"shardID":0} }},"upsert": {}}
{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx._source = params.account} else {if ((!ctx._source.containsKey('timestamp')) || (ctx._source.timestamp <= params.account.timestamp) ) {params.account.forEach((key, value) -> {ctx._source[key] = value;});}}","lang": "painless","params": { "account": {"address":"addr1","nonce":1,"balance":"10000000000000","balanceNum":1,"token":"token-0001","identifier":"token-0001-5","tokenNonce":22,"properties":"000","data":{"name":"nft","creator":"010101","royalties":1,"hash":"aGFzaA==","uris":["dXJp"],"tags":["test","free","fun"],"attributes":"dGFnczp0ZXN0LGZyZWUsZnVuO2Rlc2NyaXB0aW9uOlRoaXMgaXMgYSB0ZXN0IGRlc2NyaXB0aW9uIGZvciBhbiBhd2Vzb21lIG5mdA==","metadata":"metadata-test","nonEmptyURIs":true,"whiteListedStorage":false},"shardID":0} }},"upsert": {}}
`
require.Equal(t, expectedRes, buffSlice.Buffers()[0].String())
}
Expand Down
8 changes: 6 additions & 2 deletions process/elasticproc/elasticProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,17 @@ func (ei *elasticProcessor) init(useKibana bool, indexTemplates, _ map[string]*b
}

func (ei *elasticProcessor) indexVersion(version string) error {
id := fmt.Sprintf("%s", versionStr)
if version == "" {
log.Debug("ei.elasticProcessor indexer version is empty")
return nil
}

keyValueObj := &data.KeyValueObj{
Key: versionStr,
Value: version,
}

meta := []byte(fmt.Sprintf(`{ "index" : { "_index":"%s", "_id" : "%s" } }%s`, elasticIndexer.ValuesIndex, id, "\n"))
meta := []byte(fmt.Sprintf(`{ "index" : { "_index":"%s", "_id" : "%s" } }%s`, elasticIndexer.ValuesIndex, versionStr, "\n"))
keyValueObjBytes, err := json.Marshal(keyValueObj)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion process/elasticproc/templatesAndPolicies/noKibana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ func TestTemplatesAndPolicyReaderNoKibana_GetElasticTemplatesAndPolicies(t *test
templates, policies, err := reader.GetElasticTemplatesAndPolicies()
require.Nil(t, err)
require.Len(t, policies, 0)
require.Len(t, templates, 21)
require.Len(t, templates, 22)
}
3 changes: 0 additions & 3 deletions process/factory/indexerFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,4 @@ func TestIndexerFactoryCreate_ElasticIndexer(t *testing.T) {

err = elasticIndexer.Close()
require.NoError(t, err)

err = elasticIndexer.Close()
require.NoError(t, err)
}

0 comments on commit c1559c5

Please sign in to comment.