|
| 1 | +package etcd |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/require" |
| 7 | +) |
| 8 | + |
| 9 | +func Test_configureCMD(t *testing.T) { |
| 10 | + t.Run("default", func(t *testing.T) { |
| 11 | + got := configureCMD(options{}) |
| 12 | + want := []string{"etcd", "--name=default"} |
| 13 | + require.Equal(t, want, got) |
| 14 | + }) |
| 15 | + |
| 16 | + t.Run("with-node", func(t *testing.T) { |
| 17 | + got := configureCMD(options{ |
| 18 | + nodeNames: []string{"node1"}, |
| 19 | + }) |
| 20 | + want := []string{ |
| 21 | + "etcd", |
| 22 | + "--name=node1", |
| 23 | + "--initial-advertise-peer-urls=http://node1:2380", |
| 24 | + "--advertise-client-urls=http://node1:2379", |
| 25 | + "--listen-peer-urls=http://0.0.0.0:2380", |
| 26 | + "--listen-client-urls=http://0.0.0.0:2379", |
| 27 | + "--initial-cluster-state=new", |
| 28 | + "--initial-cluster=node1=http://node1:2380", |
| 29 | + } |
| 30 | + require.Equal(t, want, got) |
| 31 | + }) |
| 32 | + |
| 33 | + t.Run("with-node-datadir", func(t *testing.T) { |
| 34 | + got := configureCMD(options{ |
| 35 | + nodeNames: []string{"node1"}, |
| 36 | + mountDataDir: true, |
| 37 | + }) |
| 38 | + want := []string{ |
| 39 | + "etcd", |
| 40 | + "--name=node1", |
| 41 | + "--initial-advertise-peer-urls=http://node1:2380", |
| 42 | + "--advertise-client-urls=http://node1:2379", |
| 43 | + "--listen-peer-urls=http://0.0.0.0:2380", |
| 44 | + "--listen-client-urls=http://0.0.0.0:2379", |
| 45 | + "--initial-cluster-state=new", |
| 46 | + "--initial-cluster=node1=http://node1:2380", |
| 47 | + "--data-dir=/data.etcd", |
| 48 | + } |
| 49 | + require.Equal(t, want, got) |
| 50 | + }) |
| 51 | + |
| 52 | + t.Run("with-node-datadir-additional-args", func(t *testing.T) { |
| 53 | + got := configureCMD(options{ |
| 54 | + nodeNames: []string{"node1"}, |
| 55 | + mountDataDir: true, |
| 56 | + additionalArgs: []string{"--auto-compaction-retention=1"}, |
| 57 | + }) |
| 58 | + want := []string{ |
| 59 | + "etcd", |
| 60 | + "--name=node1", |
| 61 | + "--initial-advertise-peer-urls=http://node1:2380", |
| 62 | + "--advertise-client-urls=http://node1:2379", |
| 63 | + "--listen-peer-urls=http://0.0.0.0:2380", |
| 64 | + "--listen-client-urls=http://0.0.0.0:2379", |
| 65 | + "--initial-cluster-state=new", |
| 66 | + "--initial-cluster=node1=http://node1:2380", |
| 67 | + "--data-dir=/data.etcd", |
| 68 | + "--auto-compaction-retention=1", |
| 69 | + } |
| 70 | + require.Equal(t, want, got) |
| 71 | + }) |
| 72 | + |
| 73 | + t.Run("with-cluster", func(t *testing.T) { |
| 74 | + got := configureCMD(options{ |
| 75 | + nodeNames: []string{"node1", "node2"}, |
| 76 | + }) |
| 77 | + want := []string{ |
| 78 | + "etcd", |
| 79 | + "--name=node1", |
| 80 | + "--initial-advertise-peer-urls=http://node1:2380", |
| 81 | + "--advertise-client-urls=http://node1:2379", |
| 82 | + "--listen-peer-urls=http://0.0.0.0:2380", |
| 83 | + "--listen-client-urls=http://0.0.0.0:2379", |
| 84 | + "--initial-cluster-state=new", |
| 85 | + "--initial-cluster=node1=http://node1:2380,node2=http://node2:2380", |
| 86 | + } |
| 87 | + require.Equal(t, want, got) |
| 88 | + }) |
| 89 | + |
| 90 | + t.Run("with-cluster-token", func(t *testing.T) { |
| 91 | + got := configureCMD(options{ |
| 92 | + nodeNames: []string{"node1", "node2"}, |
| 93 | + clusterToken: "token", |
| 94 | + }) |
| 95 | + want := []string{ |
| 96 | + "etcd", |
| 97 | + "--name=node1", |
| 98 | + "--initial-advertise-peer-urls=http://node1:2380", |
| 99 | + "--advertise-client-urls=http://node1:2379", |
| 100 | + "--listen-peer-urls=http://0.0.0.0:2380", |
| 101 | + "--listen-client-urls=http://0.0.0.0:2379", |
| 102 | + "--initial-cluster-state=new", |
| 103 | + "--initial-cluster=node1=http://node1:2380,node2=http://node2:2380", |
| 104 | + "--initial-cluster-token=token", |
| 105 | + } |
| 106 | + require.Equal(t, want, got) |
| 107 | + }) |
| 108 | +} |
0 commit comments