Fill in Default Values for CPU/Memory (#130)

Update k8s client and the dependencies
ACI client change for Mocking
Add ACI Provider Mock Tests
Add the Windows development environment
Add UT for Default Resource Requests
Enable the make test in Docker file
Update the vendors
This commit is contained in:
Robbie Zhang
2018-04-16 10:31:16 -07:00
committed by GitHub
parent 88bafc701b
commit 2b85b0d1df
862 changed files with 61483 additions and 16781 deletions

View File

@@ -0,0 +1,83 @@
package azure
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"github.com/gorilla/mux"
"github.com/virtual-kubelet/virtual-kubelet/providers/azure/client/aci"
)
// ACIMock implements a Azure Container Instance mock server.
type ACIMock struct {
server *httptest.Server
OnCreate func(string, string, string, *aci.ContainerGroup) (int, interface{})
}
const (
containerGroupsRoute = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.ContainerInstance/containerGroups"
containerGroupRoute = containerGroupsRoute + "/{containerGroup}"
containerGroupLogRoute = containerGroupRoute + "/containers/{containerName}/logs"
)
// NewACIMock creates a new Azure Container Instance mock server.
func NewACIMock() *ACIMock {
mock := new(ACIMock)
mock.start()
return mock
}
// Start the Azure Container Instance mock service.
func (mock *ACIMock) start() {
if mock.server != nil {
return
}
router := mux.NewRouter()
router.HandleFunc(
containerGroupRoute,
func(w http.ResponseWriter, r *http.Request) {
subscription, _ := mux.Vars(r)["subscriptionId"]
resourceGroup, _ := mux.Vars(r)["resourceGroup"]
containerGroup, _ := mux.Vars(r)["containerGroup"]
var cg aci.ContainerGroup
if err := json.NewDecoder(r.Body).Decode(&cg); err != nil {
panic(err)
}
if mock.OnCreate != nil {
statusCode, response := mock.OnCreate(subscription, resourceGroup, containerGroup, &cg)
w.WriteHeader(statusCode)
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(response)
w.Write(b.Bytes())
return
}
w.WriteHeader(http.StatusNotImplemented)
}).Methods("PUT")
mock.server = httptest.NewServer(router)
}
// GetServerURL returns the mock server URL.
func (mock *ACIMock) GetServerURL() string {
if mock.server != nil {
return mock.server.URL
}
panic("Mock server is not initialized.")
}
// Close terminates the Azure Container Instance mock server.
func (mock *ACIMock) Close() {
if mock.server != nil {
mock.server.Close()
mock.server = nil
}
}