Use contain to make tests clearer and more resilient to changes
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
@ -17,138 +17,86 @@ package e2e
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEtcdServerProcessConfig(t *testing.T) {
|
func TestEtcdServerProcessConfig(t *testing.T) {
|
||||||
tcs := []struct {
|
tcs := []struct {
|
||||||
name string
|
name string
|
||||||
config *EtcdProcessClusterConfig
|
config *EtcdProcessClusterConfig
|
||||||
expectArgs []string
|
expectArgsNotContain []string
|
||||||
|
expectArgsContain []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Default",
|
name: "Default",
|
||||||
config: NewConfig(),
|
config: NewConfig(),
|
||||||
expectArgs: []string{
|
expectArgsContain: []string{
|
||||||
"--name=TestEtcdServerProcessConfigDefault-test-0",
|
|
||||||
"--listen-client-urls=http://localhost:0",
|
"--listen-client-urls=http://localhost:0",
|
||||||
"--advertise-client-urls=http://localhost:0",
|
"--advertise-client-urls=http://localhost:0",
|
||||||
"--listen-peer-urls=http://localhost:1",
|
"--listen-peer-urls=http://localhost:1",
|
||||||
"--initial-advertise-peer-urls=http://localhost:1",
|
"--initial-advertise-peer-urls=http://localhost:1",
|
||||||
"--initial-cluster-token=new",
|
"--initial-cluster-token=new",
|
||||||
"--data-dir=/tmp/fake/member-0",
|
|
||||||
"--snapshot-count=10000",
|
"--snapshot-count=10000",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "SnapshotCount",
|
name: "SnapshotCount",
|
||||||
config: NewConfig(WithSnapshotCount(42)),
|
config: NewConfig(WithSnapshotCount(42)),
|
||||||
expectArgs: []string{
|
expectArgsContain: []string{
|
||||||
"--name=TestEtcdServerProcessConfigSnapshotCount-test-0",
|
|
||||||
"--listen-client-urls=http://localhost:0",
|
|
||||||
"--advertise-client-urls=http://localhost:0",
|
|
||||||
"--listen-peer-urls=http://localhost:1",
|
|
||||||
"--initial-advertise-peer-urls=http://localhost:1",
|
|
||||||
"--initial-cluster-token=new",
|
|
||||||
"--data-dir=/tmp/fake/member-0",
|
|
||||||
"--snapshot-count=42",
|
"--snapshot-count=42",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "SnapshotCatchUpEntries",
|
name: "SnapshotCatchUpEntries",
|
||||||
config: NewConfig(WithSnapshotCatchUpEntries(12)),
|
config: NewConfig(WithSnapshotCatchUpEntries(12)),
|
||||||
expectArgs: []string{
|
expectArgsContain: []string{
|
||||||
"--name=TestEtcdServerProcessConfigSnapshotCatchUpEntries-test-0",
|
|
||||||
"--listen-client-urls=http://localhost:0",
|
|
||||||
"--advertise-client-urls=http://localhost:0",
|
|
||||||
"--listen-peer-urls=http://localhost:1",
|
|
||||||
"--initial-advertise-peer-urls=http://localhost:1",
|
|
||||||
"--initial-cluster-token=new",
|
|
||||||
"--data-dir=/tmp/fake/member-0",
|
|
||||||
"--snapshot-count=10000",
|
|
||||||
"--experimental-snapshot-catchup-entries=12",
|
"--experimental-snapshot-catchup-entries=12",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "QuotaBackendBytes",
|
name: "QuotaBackendBytes",
|
||||||
config: NewConfig(WithQuotaBackendBytes(123)),
|
config: NewConfig(WithQuotaBackendBytes(123)),
|
||||||
expectArgs: []string{
|
expectArgsContain: []string{
|
||||||
"--name=TestEtcdServerProcessConfigQuotaBackendBytes-test-0",
|
|
||||||
"--listen-client-urls=http://localhost:0",
|
|
||||||
"--advertise-client-urls=http://localhost:0",
|
|
||||||
"--listen-peer-urls=http://localhost:1",
|
|
||||||
"--initial-advertise-peer-urls=http://localhost:1",
|
|
||||||
"--initial-cluster-token=new",
|
|
||||||
"--data-dir=/tmp/fake/member-0",
|
|
||||||
"--snapshot-count=10000",
|
|
||||||
"--quota-backend-bytes=123",
|
"--quota-backend-bytes=123",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "CorruptCheck",
|
name: "CorruptCheck",
|
||||||
config: NewConfig(WithInitialCorruptCheck(true)),
|
config: NewConfig(WithInitialCorruptCheck(true)),
|
||||||
expectArgs: []string{
|
expectArgsContain: []string{
|
||||||
"--name=TestEtcdServerProcessConfigCorruptCheck-test-0",
|
|
||||||
"--listen-client-urls=http://localhost:0",
|
|
||||||
"--advertise-client-urls=http://localhost:0",
|
|
||||||
"--listen-peer-urls=http://localhost:1",
|
|
||||||
"--initial-advertise-peer-urls=http://localhost:1",
|
|
||||||
"--initial-cluster-token=new",
|
|
||||||
"--data-dir=/tmp/fake/member-0",
|
|
||||||
"--snapshot-count=10000",
|
|
||||||
"--experimental-initial-corrupt-check",
|
"--experimental-initial-corrupt-check",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "StrictReconfigCheck",
|
name: "StrictReconfigCheck",
|
||||||
config: NewConfig(WithStrictReconfigCheck(false)),
|
config: NewConfig(WithStrictReconfigCheck(false)),
|
||||||
expectArgs: []string{
|
expectArgsContain: []string{
|
||||||
"--name=TestEtcdServerProcessConfigStrictReconfigCheck-test-0",
|
|
||||||
"--listen-client-urls=http://localhost:0",
|
|
||||||
"--advertise-client-urls=http://localhost:0",
|
|
||||||
"--listen-peer-urls=http://localhost:1",
|
|
||||||
"--initial-advertise-peer-urls=http://localhost:1",
|
|
||||||
"--initial-cluster-token=new",
|
|
||||||
"--data-dir=/tmp/fake/member-0",
|
|
||||||
"--snapshot-count=10000",
|
|
||||||
"--strict-reconfig-check=false",
|
"--strict-reconfig-check=false",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "CatchUpEntries",
|
name: "CatchUpEntries",
|
||||||
config: NewConfig(WithSnapshotCatchUpEntries(100)),
|
config: NewConfig(WithSnapshotCatchUpEntries(100)),
|
||||||
expectArgs: []string{
|
expectArgsContain: []string{
|
||||||
"--name=TestEtcdServerProcessConfigCatchUpEntries-test-0",
|
|
||||||
"--listen-client-urls=http://localhost:0",
|
|
||||||
"--advertise-client-urls=http://localhost:0",
|
|
||||||
"--listen-peer-urls=http://localhost:1",
|
|
||||||
"--initial-advertise-peer-urls=http://localhost:1",
|
|
||||||
"--initial-cluster-token=new",
|
|
||||||
"--data-dir=/tmp/fake/member-0",
|
|
||||||
"--snapshot-count=10000",
|
|
||||||
"--experimental-snapshot-catchup-entries=100",
|
"--experimental-snapshot-catchup-entries=100",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "CatchUpEntriesLastVersion",
|
name: "CatchUpEntriesLastVersion",
|
||||||
config: NewConfig(WithSnapshotCatchUpEntries(100), WithVersion(LastVersion)),
|
config: NewConfig(WithSnapshotCatchUpEntries(100), WithVersion(LastVersion)),
|
||||||
expectArgs: []string{
|
expectArgsNotContain: []string{
|
||||||
"--name=TestEtcdServerProcessConfigCatchUpEntriesLastVersion-test-0",
|
"--experimental-snapshot-catchup-entries=100",
|
||||||
"--listen-client-urls=http://localhost:0",
|
|
||||||
"--advertise-client-urls=http://localhost:0",
|
|
||||||
"--listen-peer-urls=http://localhost:1",
|
|
||||||
"--initial-advertise-peer-urls=http://localhost:1",
|
|
||||||
"--initial-cluster-token=new",
|
|
||||||
"--data-dir=/tmp/fake/member-0",
|
|
||||||
"--snapshot-count=10000",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range tcs {
|
for _, tc := range tcs {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
tc.config.BaseDataDirPath = "/tmp/fake"
|
args := tc.config.EtcdServerProcessConfig(t, 0).Args
|
||||||
if diff := cmp.Diff(tc.config.EtcdServerProcessConfig(t, 0).Args, tc.expectArgs); diff != "" {
|
if len(tc.expectArgsContain) != 0 {
|
||||||
t.Errorf("diff: %s", diff)
|
assert.Subset(t, args, tc.expectArgsContain)
|
||||||
|
}
|
||||||
|
if len(tc.expectArgsNotContain) != 0 {
|
||||||
|
assert.NotSubset(t, args, tc.expectArgsNotContain)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user