-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] extract enable to all databases + increase testing in database
(#78)
- Loading branch information
Showing
16 changed files
with
431 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package data | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNodeinfoBatAddresses(t *testing.T) { | ||
assert := assert.New(t) | ||
batIface := &BatInterface{ | ||
Interfaces: struct { | ||
Wireless []string `json:"wireless,omitempty"` | ||
Other []string `json:"other,omitempty"` | ||
Tunnel []string `json:"tunnel,omitempty"` | ||
}{ | ||
Wireless: nil, | ||
Other: []string{"aa:aa:aa:aa:aa", "aa:aa:aa:aa:ab"}, | ||
Tunnel: []string{}, | ||
}, | ||
} | ||
|
||
addr := batIface.Addresses() | ||
assert.NotNil(addr) | ||
assert.Equal([]string{"aa:aa:aa:aa:aa", "aa:aa:aa:aa:ab"}, addr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,156 @@ | ||
package all | ||
|
||
import ( | ||
"errors" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/FreifunkBremen/yanic/database" | ||
"github.com/FreifunkBremen/yanic/runtime" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type testConn struct { | ||
database.Connection | ||
countNode int | ||
countLink int | ||
countGlobals int | ||
countPrune int | ||
countClose int | ||
sync.Mutex | ||
} | ||
|
||
func (c *testConn) InsertNode(node *runtime.Node) { | ||
c.Lock() | ||
c.countNode++ | ||
c.Unlock() | ||
} | ||
func (c *testConn) GetNode() int { | ||
c.Lock() | ||
defer c.Unlock() | ||
return c.countNode | ||
} | ||
func (c *testConn) InsertLink(link *runtime.Link, time time.Time) { | ||
c.Lock() | ||
c.countLink++ | ||
c.Unlock() | ||
} | ||
func (c *testConn) GetLink() int { | ||
c.Lock() | ||
defer c.Unlock() | ||
return c.countLink | ||
} | ||
func (c *testConn) InsertGlobals(stats *runtime.GlobalStats, time time.Time, site string) { | ||
c.Lock() | ||
c.countGlobals++ | ||
c.Unlock() | ||
} | ||
func (c *testConn) GetGlobal() int { | ||
c.Lock() | ||
defer c.Unlock() | ||
return c.countGlobals | ||
} | ||
func (c *testConn) PruneNodes(time.Duration) { | ||
c.Lock() | ||
c.countPrune++ | ||
c.Unlock() | ||
} | ||
func (c *testConn) GetPrune() int { | ||
c.Lock() | ||
defer c.Unlock() | ||
return c.countPrune | ||
} | ||
func (c *testConn) Close() { | ||
c.Lock() | ||
c.countClose++ | ||
c.Unlock() | ||
} | ||
func (c *testConn) GetClose() int { | ||
c.Lock() | ||
defer c.Unlock() | ||
return c.countClose | ||
} | ||
|
||
func TestStart(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
globalConn := &testConn{} | ||
database.RegisterAdapter("a", func(config map[string]interface{}) (database.Connection, error) { | ||
return globalConn, nil | ||
}) | ||
database.RegisterAdapter("b", func(config map[string]interface{}) (database.Connection, error) { | ||
return globalConn, nil | ||
}) | ||
database.RegisterAdapter("c", func(config map[string]interface{}) (database.Connection, error) { | ||
return globalConn, nil | ||
}) | ||
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") | ||
}) | ||
allConn, err := Connect(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", | ||
}, | ||
}, | ||
"b": nil, | ||
"c": []map[string]interface{}{ | ||
map[string]interface{}{ | ||
"path": "c1", | ||
}, | ||
}, | ||
// fetch continue command in Connect | ||
"d": []map[string]interface{}{ | ||
map[string]interface{}{ | ||
"path": "d0", | ||
}, | ||
}, | ||
}) | ||
assert.NoError(err) | ||
|
||
assert.Equal(0, globalConn.GetNode()) | ||
allConn.InsertNode(nil) | ||
assert.Equal(3, globalConn.GetNode()) | ||
|
||
assert.Equal(0, globalConn.GetLink()) | ||
allConn.InsertLink(nil, time.Now()) | ||
assert.Equal(3, globalConn.GetLink()) | ||
|
||
assert.Equal(0, globalConn.GetGlobal()) | ||
allConn.InsertGlobals(nil, time.Now(), runtime.GLOBAL_SITE) | ||
assert.Equal(3, globalConn.GetGlobal()) | ||
|
||
assert.Equal(0, globalConn.GetPrune()) | ||
allConn.PruneNodes(time.Second) | ||
assert.Equal(3, globalConn.GetPrune()) | ||
|
||
assert.Equal(0, globalConn.GetClose()) | ||
allConn.Close() | ||
assert.Equal(3, globalConn.GetClose()) | ||
|
||
_, err = Connect(map[string]interface{}{ | ||
"e": []map[string]interface{}{ | ||
map[string]interface{}{}, | ||
}, | ||
}) | ||
assert.Error(err) | ||
|
||
// wrong format -> the only panic in Register | ||
assert.Panics(func() { | ||
Connect(map[string]interface{}{ | ||
"e": true, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.