* Add Virtual Kubelet provider for VIC Initial virtual kubelet provider for VMware VIC. This provider currently handles creating and starting of a pod VM via the VIC portlayer and persona server. Image store handling via the VIC persona server. This provider currently requires the feature/wolfpack branch of VIC. * Added pod stop and delete. Also added node capacity. Added the ability to stop and delete pod VMs via VIC. Also retrieve node capacity information from the VCH. * Cleanup and readme file Some file clean up and added a Readme.md markdown file for the VIC provider. * Cleaned up errors, added function comments, moved operation code 1. Cleaned up error handling. Set standard for creating errors. 2. Added method prototype comments for all interface functions. 3. Moved PodCreator, PodStarter, PodStopper, and PodDeleter to a new folder. * Add mocking code and unit tests for podcache, podcreator, and podstarter Used the unit test framework used in VIC to handle assertions in the provider's unit test. Mocking code generated using OSS project mockery, which is compatible with the testify assertion framework. * Vendored packages for the VIC provider Requires feature/wolfpack branch of VIC and a few specific commit sha of projects used within VIC. * Implementation of POD Stopper and Deleter unit tests (#4) * Updated files for initial PR
109 lines
2.8 KiB
Go
109 lines
2.8 KiB
Go
package options
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
_ "github.com/docker/libnetwork/testutils"
|
|
)
|
|
|
|
func TestGenerate(t *testing.T) {
|
|
gen := NewGeneric()
|
|
gen["Int"] = 1
|
|
gen["Rune"] = 'b'
|
|
gen["Float64"] = 2.0
|
|
|
|
type Model struct {
|
|
Int int
|
|
Rune rune
|
|
Float64 float64
|
|
}
|
|
|
|
result, err := GenerateFromModel(gen, Model{})
|
|
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cast, ok := result.(Model)
|
|
if !ok {
|
|
t.Fatalf("result has unexpected type %s", reflect.TypeOf(result))
|
|
}
|
|
if expected := 1; cast.Int != expected {
|
|
t.Fatalf("wrong value for field Int: expected %v, got %v", expected, cast.Int)
|
|
}
|
|
if expected := 'b'; cast.Rune != expected {
|
|
t.Fatalf("wrong value for field Rune: expected %v, got %v", expected, cast.Rune)
|
|
}
|
|
if expected := 2.0; cast.Float64 != expected {
|
|
t.Fatalf("wrong value for field Int: expected %v, got %v", expected, cast.Float64)
|
|
}
|
|
}
|
|
|
|
func TestGeneratePtr(t *testing.T) {
|
|
gen := NewGeneric()
|
|
gen["Int"] = 1
|
|
gen["Rune"] = 'b'
|
|
gen["Float64"] = 2.0
|
|
|
|
type Model struct {
|
|
Int int
|
|
Rune rune
|
|
Float64 float64
|
|
}
|
|
|
|
result, err := GenerateFromModel(gen, &Model{})
|
|
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cast, ok := result.(*Model)
|
|
if !ok {
|
|
t.Fatalf("result has unexpected type %s", reflect.TypeOf(result))
|
|
}
|
|
if expected := 1; cast.Int != expected {
|
|
t.Fatalf("wrong value for field Int: expected %v, got %v", expected, cast.Int)
|
|
}
|
|
if expected := 'b'; cast.Rune != expected {
|
|
t.Fatalf("wrong value for field Rune: expected %v, got %v", expected, cast.Rune)
|
|
}
|
|
if expected := 2.0; cast.Float64 != expected {
|
|
t.Fatalf("wrong value for field Int: expected %v, got %v", expected, cast.Float64)
|
|
}
|
|
}
|
|
|
|
func TestGenerateMissingField(t *testing.T) {
|
|
type Model struct{}
|
|
_, err := GenerateFromModel(Generic{"foo": "bar"}, Model{})
|
|
|
|
if _, ok := err.(NoSuchFieldError); !ok {
|
|
t.Fatalf("expected NoSuchFieldError, got %#v", err)
|
|
} else if expected := "no field"; !strings.Contains(err.Error(), expected) {
|
|
t.Fatalf("expected %q in error message, got %s", expected, err.Error())
|
|
}
|
|
}
|
|
|
|
func TestFieldCannotBeSet(t *testing.T) {
|
|
type Model struct{ foo int }
|
|
_, err := GenerateFromModel(Generic{"foo": "bar"}, Model{})
|
|
|
|
if _, ok := err.(CannotSetFieldError); !ok {
|
|
t.Fatalf("expected CannotSetFieldError, got %#v", err)
|
|
} else if expected := "cannot set field"; !strings.Contains(err.Error(), expected) {
|
|
t.Fatalf("expected %q in error message, got %s", expected, err.Error())
|
|
}
|
|
}
|
|
|
|
func TestTypeMismatchError(t *testing.T) {
|
|
type Model struct{ Foo int }
|
|
_, err := GenerateFromModel(Generic{"Foo": "bar"}, Model{})
|
|
|
|
if _, ok := err.(TypeMismatchError); !ok {
|
|
t.Fatalf("expected TypeMismatchError, got %#v", err)
|
|
} else if expected := "type mismatch"; !strings.Contains(err.Error(), expected) {
|
|
t.Fatalf("expected %q in error message, got %s", expected, err.Error())
|
|
}
|
|
}
|