Skip to content

Commit

Permalink
added return values to getVersion mock function
Browse files Browse the repository at this point in the history
Signed-off-by: bugslayer-332 <ayashwanth9503@gmail.com>
  • Loading branch information
severussnape321 committed Nov 22, 2023
1 parent 658fa9f commit 1a91d03
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
31 changes: 15 additions & 16 deletions plugin/storage/es/mappings/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package mappings
import (
"embed"
"errors"
"fmt"
"io"
"os"
"testing"
Expand Down Expand Up @@ -51,27 +52,25 @@ func TestMappingBuilder_GetMapping(t *testing.T) {
for _, tt := range tests {
t.Run(tt.mapping, func(t *testing.T) {
mb := &MappingBuilder{
TemplateBuilder: es.TextTemplateBuilder{},
Shards: 3,
Replicas: 3,
EsVersion: tt.esVersion,
IndexPrefix: "test-",
UseILM: true,
ILMPolicyName: "jaeger-test-policy",
TemplateBuilder: es.TextTemplateBuilder{},
Shards: 3,
Replicas: 3,
PrioritySpanTemplate: 500,
PriorityServiceTemplate: 501,
PriorityDependenciesTemplate: 502,
EsVersion: tt.esVersion,
IndexPrefix: "test-",
UseILM: true,
ILMPolicyName: "jaeger-test-policy",
}
got, err := mb.GetMapping(tt.mapping)
require.NoError(t, err)
var wantbytes []byte
if tt.esVersion == 8 {
wantbytes, err = FIXTURES.ReadFile("fixtures/" + tt.mapping + "-8.json")
require.NoError(t, err)
} else if tt.esVersion == 7 {
wantbytes, err = FIXTURES.ReadFile("fixtures/" + tt.mapping + "-7.json")
require.NoError(t, err)
} else {
wantbytes, err = FIXTURES.ReadFile("fixtures/" + tt.mapping + ".json")
require.NoError(t, err)
fileSuffix := ""
if tt.esVersion >= 7 {
fileSuffix = fmt.Sprintf("-%d", tt.esVersion)
}
wantbytes, err = FIXTURES.ReadFile("fixtures/" + tt.mapping + fileSuffix + ".json")

Check failure on line 73 in plugin/storage/es/mappings/mapping_test.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
want := string(wantbytes)
assert.Equal(t, got, want)
})
Expand Down
6 changes: 6 additions & 0 deletions plugin/storage/es/spanstore/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func TestCreateTemplates(t *testing.T) {
err string
spanTemplateService func() *mocks.TemplateCreateService
serviceTemplateService func() *mocks.TemplateCreateService
version uint
indexPrefix string
}{
{
Expand All @@ -237,6 +238,7 @@ func TestCreateTemplates(t *testing.T) {
tService.On("Do", context.Background()).Return(nil, nil)
return tService
},
version: uint(7),
},
{
spanTemplateService: func() *mocks.TemplateCreateService {
Expand All @@ -251,6 +253,7 @@ func TestCreateTemplates(t *testing.T) {
tService.On("Do", context.Background()).Return(nil, nil)
return tService
},
version: uint(7),
indexPrefix: "test",
},
{
Expand All @@ -267,6 +270,7 @@ func TestCreateTemplates(t *testing.T) {
tService.On("Do", context.Background()).Return(nil, nil)
return tService
},
version: uint(7),
},
{
err: "service-template-error",
Expand All @@ -282,6 +286,7 @@ func TestCreateTemplates(t *testing.T) {
tService.On("Do", context.Background()).Return(nil, errors.New("service-template-error"))
return tService
},
version: uint(7),
},
}

Expand All @@ -293,6 +298,7 @@ func TestCreateTemplates(t *testing.T) {
}
w.client.On("CreateTemplate", prefix+"jaeger-span").Return(test.spanTemplateService())
w.client.On("CreateTemplate", prefix+"jaeger-service").Return(test.serviceTemplateService())
w.client.On("GetVersion").Return(test.version)
err := w.writer.CreateTemplates(mock.Anything, mock.Anything, test.indexPrefix)
if test.err != "" {
assert.Error(t, err, test.err)
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/integration/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func cleanESIndexTemplates(t *testing.T, client *elastic.Client, v8Client *elast
if version > 7 {
prefixWithSeparator := prefix
if prefix != "" {
prefixWithSeparator = prefixWithSeparator + "-"
prefixWithSeparator += "-"
}
_, err := v8Client.Indices.DeleteIndexTemplate(prefixWithSeparator + spanTemplateName)
require.NoError(t, err)
Expand Down
7 changes: 7 additions & 0 deletions plugin/storage/integration/es_index_cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,10 @@ func createESClient() (*elastic.Client, error) {
elastic.SetURL(queryURL),
elastic.SetSniff(false))
}

func createESV8Client() (*elasticsearch8.Client, error) {
return elasticsearch8.NewClient(elasticsearch8.Config{
Addresses: []string{queryURL},
DiscoverNodesOnStart: false,
})
}
8 changes: 8 additions & 0 deletions plugin/storage/integration/es_index_rollover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strconv"
"testing"

elasticsearch8 "github.com/elastic/go-elasticsearch/v8"
"github.com/olivere/elastic"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -149,6 +150,13 @@ func createESClient() (*elastic.Client, error) {
elastic.SetSniff(false))
}

func createESV8Client() (*elasticsearch8.Client, error) {
return elasticsearch8.NewClient(elasticsearch8.Config{
Addresses: []string{queryURL},
DiscoverNodesOnStart: false,
})
}

func runEsRollover(action string, envs []string) error {
var dockerEnv string
for _, e := range envs {
Expand Down

0 comments on commit 1a91d03

Please sign in to comment.