Skip to content

Commit

Permalink
linter: update ScriptId to ScriptID due to ST1003 stylecheck and add …
Browse files Browse the repository at this point in the history
…notlint:lll for test files
  • Loading branch information
GokselKUCUKSAHIN committed Feb 16, 2025
1 parent a4d274c commit e728c86
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
3 changes: 2 additions & 1 deletion benchmarks/tests/multi_filter_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func createMultiFilterQueryVanilla() map[string]any {
},
{
"exists": map[string]interface{}{
"field": "stock"},
"field": "stock",
},
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions es/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func ScriptSource(source string, scriptLanguage ScriptLanguage.ScriptLanguage) s
}
}

// ScriptId creates a new es.scriptType object with the specified script Id and language.
// ScriptID creates a new es.scriptType object with the specified script ID and language.
//
// This function initializes an es.scriptType object that references a stored script by its Id,
// This function initializes an es.scriptType object that references a stored script by its ID,
// along with the specified script language. It is used when executing pre-defined scripts in Elasticsearch.
//
// Example usage:
//
// script := es.ScriptId("calculate-discount", es.ScriptLanguage.Painless)
// script := es.ScriptID("calculate-discount", es.ScriptLanguage.Painless)
// // script now contains an es.scriptType object referencing the "calculate-discount" script written in Painless.
//
// Parameters:
Expand All @@ -47,7 +47,7 @@ func ScriptSource(source string, scriptLanguage ScriptLanguage.ScriptLanguage) s
// Returns:
//
// An es.scriptType object referencing the stored script.
func ScriptId(id string, scriptLanguage ScriptLanguage.ScriptLanguage) scriptType {
func ScriptID(id string, scriptLanguage ScriptLanguage.ScriptLanguage) scriptType {
return scriptType{
"id": id,
"lang": scriptLanguage,
Expand All @@ -61,7 +61,7 @@ func ScriptId(id string, scriptLanguage ScriptLanguage.ScriptLanguage) scriptTyp
//
// Example usage:
//
// script := es.ScriptId("calculate-discount", es.ScriptLanguage.Painless).Option("cache", "true")
// script := es.ScriptID("calculate-discount", es.ScriptLanguage.Painless).Option("cache", "true")
// // script now has an "options" field with {"cache": "true"}.
//
// Parameters:
Expand All @@ -88,7 +88,7 @@ func (s scriptType) Option(option, value string) scriptType {
//
// Example usage:
//
// script := es.ScriptId("calculate-discount", es.ScriptLanguage.Painless).
// script := es.ScriptID("calculate-discount", es.ScriptLanguage.Painless).
// Parameter("factor", 0.9)
// // script now has a "params" field with {"factor": 0.9}.
//
Expand Down
13 changes: 7 additions & 6 deletions es/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
"github.com/Trendyol/es-query-builder/test/assert"
)

//// ScriptId ////
//// ScriptID ////

func Test_ScriptId_should_script_on_es_package(t *testing.T) {
t.Parallel()
// Given When Then
assert.NotNil(t, es.ScriptId)
assert.NotNil(t, es.ScriptID)
}

func Test_ScriptId_should_create_json_with_id_and_lang_field_inside_script(t *testing.T) {
t.Parallel()
// Given
script := es.ScriptId("custom_match_script", ScriptLanguage.Painless)
script := es.ScriptID("custom_match_script", ScriptLanguage.Painless)

// When Then
assert.NotNil(t, script)
Expand Down Expand Up @@ -50,7 +50,7 @@ func Test_ScriptSource_should_create_json_with_source_and_lang_field_inside_scri
func Test_Script_should_have_Option_method(t *testing.T) {
t.Parallel()
// Given
script := es.ScriptId("key", ScriptLanguage.Mustache)
script := es.ScriptID("key", ScriptLanguage.Mustache)

// When Then
assert.NotNil(t, script.Option)
Expand All @@ -59,7 +59,7 @@ func Test_Script_should_have_Option_method(t *testing.T) {
func Test_Script_Option_should_create_json_with_options_field_inside_script(t *testing.T) {
t.Parallel()
// Given
script := es.ScriptId("key", ScriptLanguage.Mustache).
script := es.ScriptID("key", ScriptLanguage.Mustache).
Option("retry", "5")

// When Then
Expand All @@ -71,7 +71,7 @@ func Test_Script_Option_should_create_json_with_options_field_inside_script(t *t
func Test_Script_Option_should_append_options_field_inside_script_when_options_already_exists(t *testing.T) {
t.Parallel()
// Given
script := es.ScriptId("key", ScriptLanguage.Mustache).
script := es.ScriptID("key", ScriptLanguage.Mustache).
Option("retry", "5").
Option("timeout", "10s").
Option("size", "250")
Expand Down Expand Up @@ -115,5 +115,6 @@ func Test_Script_Parameter_should_append_params_field_inside_script_when_params_
// When Then
assert.NotNil(t, script)
scriptJSON := assert.MarshalWithoutError(t, script)
// nolint:golint,lll
assert.Equal(t, "{\"lang\":\"java\",\"params\":{\"p1\":100,\"p2\":\"hello\",\"p3\":5.26,\"p4\":[22,33,44]},\"source\":\"Math.min(tree[1])\"}", scriptJSON)
}
4 changes: 3 additions & 1 deletion es/terms_set_query_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package es_test

import (
ScriptLanguage "github.com/Trendyol/es-query-builder/es/enums/script-language"
"testing"

ScriptLanguage "github.com/Trendyol/es-query-builder/es/enums/script-language"

"github.com/Trendyol/es-query-builder/es"
"github.com/Trendyol/es-query-builder/test/assert"
)
Expand Down Expand Up @@ -82,6 +83,7 @@ func Test_TermsSet_MinimumShouldMatchField_should_create_json_with_minimum_shoul
// When Then
assert.NotNil(t, query)
bodyJSON := assert.MarshalWithoutError(t, query)
// nolint:golint,lll
assert.Equal(t, "{\"query\":{\"terms_set\":{\"sector.name\":{\"minimum_should_match_field\":\"match_threshold\",\"terms\":[\"a1\",\"b2\",\"c3\"]}}}}", bodyJSON)
}

Expand Down

0 comments on commit e728c86

Please sign in to comment.