|
| 1 | +package zmq |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +func TestDefaultConfig(t *testing.T) { |
| 10 | + cfg := DefaultConfig() |
| 11 | + |
| 12 | + assert.NotNil(t, cfg, "DefaultConfig should not return nil") |
| 13 | + assert.Equal(t, "", cfg.ZmqPubBlockInfo, "ZmqPubBlockInfo should be empty") |
| 14 | + assert.Equal(t, "", cfg.ZmqPubTxInfo, "ZmqPubTxInfo should be empty") |
| 15 | + assert.Equal(t, "", cfg.ZmqPubRawBlock, "ZmqPubRawBlock should be empty") |
| 16 | + assert.Equal(t, "", cfg.ZmqPubRawTx, "ZmqPubRawTx should be empty") |
| 17 | + assert.Equal(t, 1000, cfg.ZmqPubHWM, "ZmqPubHWM should default to 1000") |
| 18 | +} |
| 19 | + |
| 20 | +func TestBasicCheck(t *testing.T) { |
| 21 | + testCases := []struct { |
| 22 | + name string |
| 23 | + config *Config |
| 24 | + expectErr bool |
| 25 | + }{ |
| 26 | + { |
| 27 | + name: "Valid configuration", |
| 28 | + config: &Config{ |
| 29 | + ZmqPubBlockInfo: "tcp://127.0.0.1:28332", |
| 30 | + ZmqPubTxInfo: "tcp://127.0.0.1:28333", |
| 31 | + ZmqPubRawBlock: "tcp://127.0.0.1:28334", |
| 32 | + ZmqPubRawTx: "tcp://127.0.0.1:28335", |
| 33 | + ZmqPubHWM: 1000, |
| 34 | + }, |
| 35 | + expectErr: false, |
| 36 | + }, |
| 37 | + { |
| 38 | + name: "Invalid scheme", |
| 39 | + config: &Config{ |
| 40 | + ZmqPubBlockInfo: "udp://127.0.0.1:28332", |
| 41 | + }, |
| 42 | + expectErr: true, |
| 43 | + }, |
| 44 | + { |
| 45 | + name: "Missing port", |
| 46 | + config: &Config{ |
| 47 | + ZmqPubBlockInfo: "tcp://127.0.0.1", |
| 48 | + }, |
| 49 | + expectErr: true, |
| 50 | + }, |
| 51 | + { |
| 52 | + name: "Empty host", |
| 53 | + config: &Config{ |
| 54 | + ZmqPubBlockInfo: "tcp://:28332", |
| 55 | + }, |
| 56 | + expectErr: true, |
| 57 | + }, |
| 58 | + { |
| 59 | + name: "Negative ZmqPubHWM", |
| 60 | + config: &Config{ |
| 61 | + ZmqPubHWM: -1, |
| 62 | + }, |
| 63 | + expectErr: true, |
| 64 | + }, |
| 65 | + { |
| 66 | + name: "Empty configuration", |
| 67 | + config: DefaultConfig(), |
| 68 | + expectErr: false, |
| 69 | + }, |
| 70 | + } |
| 71 | + |
| 72 | + for _, tc := range testCases { |
| 73 | + t.Run(tc.name, func(t *testing.T) { |
| 74 | + err := tc.config.BasicCheck() |
| 75 | + if tc.expectErr { |
| 76 | + assert.Error(t, err, "BasicCheck should return an error") |
| 77 | + } else { |
| 78 | + assert.NoError(t, err, "BasicCheck should not return an error") |
| 79 | + } |
| 80 | + }) |
| 81 | + } |
| 82 | +} |
0 commit comments