2017-10-12 15:25:00 +02:00
|
|
|
package all
|
2017-12-31 05:26:17 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/database"
|
2018-01-07 21:00:56 +01:00
|
|
|
"github.com/FreifunkBremen/yanic/lib/duration"
|
2017-12-31 05:26:17 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStart(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
database.RegisterAdapter("d", func(config map[string]interface{}) (database.Connection, error) {
|
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
database.RegisterAdapter("e", func(config map[string]interface{}) (database.Connection, error) {
|
|
|
|
return nil, errors.New("blub")
|
|
|
|
})
|
2018-01-03 15:41:40 +01:00
|
|
|
// Test for PruneNodes (by start)
|
|
|
|
assert.Nil(quit)
|
2018-01-07 21:00:56 +01:00
|
|
|
err := Start(database.Config{
|
|
|
|
DeleteInterval: duration.Duration{Duration: time.Millisecond},
|
2018-01-03 15:41:40 +01:00
|
|
|
Connection: map[string]interface{}{
|
|
|
|
"a": []map[string]interface{}{
|
2018-01-13 16:40:23 +01:00
|
|
|
{
|
2018-01-03 15:41:40 +01:00
|
|
|
"enable": false,
|
|
|
|
"path": "a1",
|
|
|
|
},
|
2018-01-13 16:40:23 +01:00
|
|
|
{
|
2018-01-03 15:41:40 +01:00
|
|
|
"path": "a2",
|
|
|
|
},
|
2018-01-13 16:40:23 +01:00
|
|
|
{
|
2018-01-03 15:41:40 +01:00
|
|
|
"enable": true,
|
|
|
|
"path": "a3",
|
|
|
|
},
|
2017-12-31 05:26:17 +01:00
|
|
|
},
|
2018-01-03 15:41:40 +01:00
|
|
|
"b": nil,
|
2018-01-15 01:01:32 +01:00
|
|
|
"c": []interface{}{
|
|
|
|
map[string]interface{}{
|
2018-01-03 15:41:40 +01:00
|
|
|
"path": "c1",
|
|
|
|
},
|
2017-12-31 05:26:17 +01:00
|
|
|
},
|
2018-01-03 15:41:40 +01:00
|
|
|
// fetch continue command in Connect
|
2018-01-15 01:01:32 +01:00
|
|
|
"d": []interface{}{
|
|
|
|
map[string]interface{}{
|
2018-01-03 15:41:40 +01:00
|
|
|
"path": "d0",
|
|
|
|
},
|
2017-12-31 05:26:17 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(err)
|
2018-01-03 15:41:40 +01:00
|
|
|
assert.NotNil(quit)
|
2017-12-31 05:26:17 +01:00
|
|
|
|
2018-01-07 21:00:56 +01:00
|
|
|
// connection type not found
|
2017-12-31 05:26:17 +01:00
|
|
|
_, err = Connect(map[string]interface{}{
|
|
|
|
"e": []map[string]interface{}{
|
2018-01-13 16:40:23 +01:00
|
|
|
{},
|
2017-12-31 05:26:17 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Error(err)
|
|
|
|
|
2018-01-07 21:00:56 +01:00
|
|
|
// test close
|
|
|
|
Close()
|
|
|
|
|
2018-01-03 15:41:40 +01:00
|
|
|
// wrong format
|
2018-01-07 21:00:56 +01:00
|
|
|
err = Start(database.Config{
|
|
|
|
Connection: map[string]interface{}{
|
|
|
|
"e": true,
|
|
|
|
},
|
2017-12-31 05:26:17 +01:00
|
|
|
})
|
2018-01-03 15:41:40 +01:00
|
|
|
assert.Error(err)
|
2017-12-31 05:26:17 +01:00
|
|
|
}
|