Skip to content

Commit

Permalink
chore: test improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
erayarslan committed Mar 26, 2023
1 parent 16225bb commit 5f97d03
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
25 changes: 24 additions & 1 deletion dcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ import (
"github.com/testcontainers/testcontainers-go/wait"
)

var configStr = `hosts:
- localhost:8091
username: Administrator
password: password
bucketName: sample
scopeName: _default
collectionNames:
- _default
metadata:
config:
bucket: sample
checkpoint:
type: manual
logging:
level: debug
dcp:
listener:
bufferSize: 1024
group:
name: groupName
membership:
type: static`

func setupContainer(b *testing.B, config *helpers.Config) func() {
ctx := context.Background()

Expand Down Expand Up @@ -111,7 +134,7 @@ func BenchmarkDcp(benchmark *testing.B) {
mockDataSize := 320000
saveTarget := mockDataSize / 2

configPath, configFileClean, err := helpers.CreateConfigFile()
configPath, configFileClean, err := helpers.CreateConfigFile(configStr)
if err != nil {
benchmark.Error(err)
}
Expand Down
36 changes: 34 additions & 2 deletions helpers/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,31 @@ import (
"github.com/stretchr/testify/assert"
)

var configStr = `hosts:
- localhost:8091
username: Administrator
password: password
bucketName: sample
scopeName: _default
collectionNames:
- _default
metadata:
config:
bucket: sample
checkpoint:
type: manual
logging:
level: debug
dcp:
listener:
bufferSize: 1024
group:
name: groupName
membership:
type: static`

func TestLoadConfig(t *testing.T) {
configPath, configFileClean, err := CreateConfigFile()
configPath, configFileClean, err := CreateConfigFile(configStr)
if err != nil {
t.Error(err)
}
Expand All @@ -17,7 +40,16 @@ func TestLoadConfig(t *testing.T) {

assert.Equal(t, 1, len(config.Hosts))
assert.Contains(t, config.Hosts, "localhost:8091")
assert.Equal(t, "sample", config.BucketName)
assert.Equal(t, "Administrator", config.Username)
assert.Equal(t, "password", config.Password)
assert.Equal(t, "sample", config.BucketName)
assert.Equal(t, "_default", config.ScopeName)
assert.Equal(t, 1, len(config.CollectionNames))
assert.Contains(t, config.CollectionNames, "_default")
assert.Equal(t, "sample", config.Metadata.Config["bucket"])
assert.Equal(t, "manual", config.Checkpoint.Type)
assert.Equal(t, "debug", config.Logging.Level)
assert.Equal(t, 1024, config.Dcp.Listener.BufferSize)
assert.Equal(t, "groupName", config.Dcp.Group.Name)
assert.Equal(t, "static", config.Dcp.Group.Membership.Type)
}
27 changes: 2 additions & 25 deletions helpers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,13 @@ func ChunkSlice[T any](slice []T, chunks int) [][]T {
return result
}

func CreateConfigFile() (string, func(), error) {
configStr := `hosts:
- localhost:8091
username: Administrator
password: password
bucketName: sample
scopeName: _default
collectionNames:
- _default
metadata:
config:
bucket: sample
checkpoint:
type: manual
logging:
level: debug
dcp:
listener:
bufferSize: 1024
group:
name: groupName
membership:
type: static`

func CreateConfigFile(content string) (string, func(), error) {
tmpFile, err := os.CreateTemp("", "*.yml")
if err != nil {
return "", nil, err
}

if _, err = tmpFile.WriteString(configStr); err != nil {
if _, err = tmpFile.WriteString(content); err != nil {
return "", nil, err
}

Expand Down

0 comments on commit 5f97d03

Please sign in to comment.