2017-10-12 13:25:00 +00:00
|
|
|
package all
|
2017-12-31 04:26:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/database"
|
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
"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 14:41:40 +00:00
|
|
|
// Test for PruneNodes (by start)
|
|
|
|
assert.Nil(quit)
|
|
|
|
err := Start(runtime.DatabaseConfig{
|
|
|
|
DeleteInterval: runtime.Duration{Duration: time.Millisecond},
|
|
|
|
Connection: map[string]interface{}{
|
|
|
|
"a": []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"enable": false,
|
|
|
|
"path": "a1",
|
|
|
|
},
|
|
|
|
map[string]interface{}{
|
|
|
|
"path": "a2",
|
|
|
|
},
|
|
|
|
map[string]interface{}{
|
|
|
|
"enable": true,
|
|
|
|
"path": "a3",
|
|
|
|
},
|
2017-12-31 04:26:17 +00:00
|
|
|
},
|
2018-01-03 14:41:40 +00:00
|
|
|
"b": nil,
|
|
|
|
"c": []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"path": "c1",
|
|
|
|
},
|
2017-12-31 04:26:17 +00:00
|
|
|
},
|
2018-01-03 14:41:40 +00:00
|
|
|
// fetch continue command in Connect
|
|
|
|
"d": []map[string]interface{}{
|
|
|
|
map[string]interface{}{
|
|
|
|
"path": "d0",
|
|
|
|
},
|
2017-12-31 04:26:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(err)
|
2018-01-03 14:41:40 +00:00
|
|
|
assert.NotNil(quit)
|
2017-12-31 04:26:17 +00:00
|
|
|
|
|
|
|
_, err = Connect(map[string]interface{}{
|
|
|
|
"e": []map[string]interface{}{
|
|
|
|
map[string]interface{}{},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.Error(err)
|
|
|
|
|
2018-01-03 14:41:40 +00:00
|
|
|
// wrong format
|
|
|
|
_, err = Connect(map[string]interface{}{
|
|
|
|
"e": true,
|
2017-12-31 04:26:17 +00:00
|
|
|
})
|
2018-01-03 14:41:40 +00:00
|
|
|
assert.Error(err)
|
2017-12-31 04:26:17 +00:00
|
|
|
}
|