2015-06-08 11:24:43 -04:00
|
|
|
package host
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-09-07 13:33:28 -04:00
|
|
|
_ "github.com/docker/libnetwork/testutils"
|
2015-06-08 11:24:43 -04:00
|
|
|
"github.com/docker/libnetwork/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDriver(t *testing.T) {
|
|
|
|
d := &driver{}
|
|
|
|
|
|
|
|
if d.Type() != networkType {
|
2016-11-21 20:29:53 -05:00
|
|
|
t.Fatal("Unexpected network type returned by driver")
|
2015-06-08 11:24:43 -04:00
|
|
|
}
|
|
|
|
|
2016-04-18 22:55:39 -04:00
|
|
|
err := d.CreateNetwork("first", nil, nil, nil, nil)
|
2015-06-08 11:24:43 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if d.network != "first" {
|
2016-11-21 20:29:53 -05:00
|
|
|
t.Fatal("Unexpected network id stored")
|
2015-06-08 11:24:43 -04:00
|
|
|
}
|
|
|
|
|
2016-04-18 22:55:39 -04:00
|
|
|
err = d.CreateNetwork("second", nil, nil, nil, nil)
|
2015-06-08 11:24:43 -04:00
|
|
|
if err == nil {
|
2016-11-21 20:29:53 -05:00
|
|
|
t.Fatal("Second network creation should fail on this driver")
|
2015-06-08 11:24:43 -04:00
|
|
|
}
|
|
|
|
if _, ok := err.(types.ForbiddenError); !ok {
|
2016-11-21 20:29:53 -05:00
|
|
|
t.Fatal("Second network creation failed with unexpected error type")
|
2015-06-08 11:24:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = d.DeleteNetwork("first")
|
|
|
|
if err == nil {
|
2016-11-21 20:29:53 -05:00
|
|
|
t.Fatal("network deletion should fail on this driver")
|
2015-06-08 11:24:43 -04:00
|
|
|
}
|
|
|
|
if _, ok := err.(types.ForbiddenError); !ok {
|
2016-11-21 20:29:53 -05:00
|
|
|
t.Fatal("network deletion failed with unexpected error type")
|
2015-06-08 11:24:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// we don't really check if it is there or not, delete is not allowed for this driver, period.
|
|
|
|
err = d.DeleteNetwork("unknown")
|
|
|
|
if err == nil {
|
2016-11-21 20:29:53 -05:00
|
|
|
t.Fatal("any network deletion should fail on this driver")
|
2015-06-08 11:24:43 -04:00
|
|
|
}
|
|
|
|
if _, ok := err.(types.ForbiddenError); !ok {
|
2016-11-21 20:29:53 -05:00
|
|
|
t.Fatal("any network deletion failed with unexpected error type")
|
2015-06-08 11:24:43 -04:00
|
|
|
}
|
|
|
|
}
|