Task 5544441: Network plugin test initial commit
This commit is contained in:
Родитель
9aec1d5ff2
Коммит
f369a8bd5e
|
@ -43,7 +43,8 @@ func (listener *Listener) Start(errChan chan error) error {
|
|||
|
||||
listener.l, err = net.Listen("unix", listener.socketName)
|
||||
if err != nil {
|
||||
log.Printf("Listener: Failed to listen on %s %v", listener.socketName, err)
|
||||
log.Printf("Listener: Failed to listen %+v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Listener: Started listening on %s.", listener.socketName)
|
||||
|
@ -67,6 +68,11 @@ func (listener *Listener) Stop() {
|
|||
log.Printf("Listener: Stopped listening on %s", listener.socketName)
|
||||
}
|
||||
|
||||
// Returns the HTTP mux for the listener.
|
||||
func (listener *Listener) GetMux() *http.ServeMux {
|
||||
return listener.mux
|
||||
}
|
||||
|
||||
// Registers a protocol handler.
|
||||
func (listener *Listener) AddHandler(endpoint string, method string, handler func(http.ResponseWriter, *http.Request)) {
|
||||
url := fmt.Sprintf("/%s.%s", endpoint, method)
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
// Copyright Microsoft Corp.
|
||||
// All rights reserved.
|
||||
|
||||
package network
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/sharmasushant/penguin/core"
|
||||
//"github.com/docker/libnetwork/drivers/remote/api"
|
||||
)
|
||||
|
||||
var plugin NetPlugin
|
||||
var mux *http.ServeMux
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
// Create the listener.
|
||||
listener, err := core.NewListener("test")
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create listener %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
mux = listener.GetMux()
|
||||
|
||||
// Create the plugin.
|
||||
plugin, err = NewPlugin("test", "")
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create network plugin %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = plugin.Start(listener)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to start network plugin %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Run tests.
|
||||
exitCode := m.Run()
|
||||
|
||||
// Cleanup.
|
||||
plugin.Stop()
|
||||
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
func TestActivate(t *testing.T) {
|
||||
fmt.Println("Test: Activate")
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, "/Plugin.Activate", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Error("Activate request failed")
|
||||
}
|
||||
|
||||
//fmt.Printf("%d - %s", w.Code, w.Body.String())
|
||||
}
|
||||
|
||||
func TestGetCapabilities(t *testing.T) {
|
||||
fmt.Println("Test: GetCapabilities")
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, "/NetworkDriver.GetCapabilities", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Error("GetCapabilities request failed")
|
||||
}
|
||||
|
||||
//resp api.GetCapabilityResponse
|
||||
}
|
Загрузка…
Ссылка в новой задаче