Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend enum support #144

Merged
merged 4 commits into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions pkg/genlib/generator_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/Pallinder/go-randomdata"
"github.com/elastic/elastic-integration-corpus-generator-tool/pkg/genlib/config"
"github.com/elastic/elastic-integration-corpus-generator-tool/pkg/genlib/fields"
"math"
"regexp"
"strconv"
"strings"
"sync"
"testing"
"time"

"github.com/Pallinder/go-randomdata"
"github.com/elastic/elastic-integration-corpus-generator-tool/pkg/genlib/config"
"github.com/elastic/elastic-integration-corpus-generator-tool/pkg/genlib/fields"
)

var timeNowToBind time.Time
Expand Down Expand Up @@ -970,6 +971,23 @@ func bindLongWithReturn(fieldCfg ConfigField, field Field, fieldMap map[string]a
return err
}

if len(fieldCfg.Enum) > 0 {
var emitF emitF
idx := customRand.Intn(len(fieldCfg.Enum))
f, err := strconv.ParseInt(fieldCfg.Enum[idx], 10, 64)
if err != nil {
return fmt.Errorf("field %s enum value is not a long: %w", fieldCfg.Name, err)
}

emitF = func(state *genState) any {
return f
}

fieldMap[field.Name] = emitF

return nil
}

if fieldCfg.Counter {
var emitF emitF

Expand Down Expand Up @@ -1072,6 +1090,23 @@ func bindDoubleWithReturn(fieldCfg ConfigField, field Field, fieldMap map[string
return err
}

if len(fieldCfg.Enum) > 0 {
var emitF emitF
idx := customRand.Intn(len(fieldCfg.Enum))
f, err := strconv.ParseFloat(fieldCfg.Enum[idx], 64)
if err != nil {
return fmt.Errorf("field %s enum value is not a double: %w", fieldCfg.Name, err)
}

emitF = func(state *genState) any {
return f
}

fieldMap[field.Name] = emitF

return nil
}

if fieldCfg.Counter {
var emitF emitF

Expand Down
Loading