* 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
96 lines
2.2 KiB
Go
96 lines
2.2 KiB
Go
package objx
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var fixtures = []struct {
|
|
// name is the name of the fixture (used for reporting
|
|
// failures)
|
|
name string
|
|
// data is the JSON data to be worked on
|
|
data string
|
|
// get is the argument(s) to pass to Get
|
|
get interface{}
|
|
// output is the expected output
|
|
output interface{}
|
|
}{
|
|
{
|
|
name: "Simple get",
|
|
data: `{"name": "Mat"}`,
|
|
get: "name",
|
|
output: "Mat",
|
|
},
|
|
{
|
|
name: "Get with dot notation",
|
|
data: `{"address": {"city": "Boulder"}}`,
|
|
get: "address.city",
|
|
output: "Boulder",
|
|
},
|
|
{
|
|
name: "Deep get with dot notation",
|
|
data: `{"one": {"two": {"three": {"four": "hello"}}}}`,
|
|
get: "one.two.three.four",
|
|
output: "hello",
|
|
},
|
|
{
|
|
name: "Get missing with dot notation",
|
|
data: `{"one": {"two": {"three": {"four": "hello"}}}}`,
|
|
get: "one.ten",
|
|
output: nil,
|
|
},
|
|
{
|
|
name: "Get with array notation",
|
|
data: `{"tags": ["one", "two", "three"]}`,
|
|
get: "tags[1]",
|
|
output: "two",
|
|
},
|
|
{
|
|
name: "Get with array and dot notation",
|
|
data: `{"types": { "tags": ["one", "two", "three"]}}`,
|
|
get: "types.tags[1]",
|
|
output: "two",
|
|
},
|
|
{
|
|
name: "Get with array and dot notation - field after array",
|
|
data: `{"tags": [{"name":"one"}, {"name":"two"}, {"name":"three"}]}`,
|
|
get: "tags[1].name",
|
|
output: "two",
|
|
},
|
|
{
|
|
name: "Complex get with array and dot notation",
|
|
data: `{"tags": [{"list": [{"one":"pizza"}]}]}`,
|
|
get: "tags[0].list[0].one",
|
|
output: "pizza",
|
|
},
|
|
{
|
|
name: "Get field from within string should be nil",
|
|
data: `{"name":"Tyler"}`,
|
|
get: "name.something",
|
|
output: nil,
|
|
},
|
|
{
|
|
name: "Get field from within string (using array accessor) should be nil",
|
|
data: `{"numbers":["one", "two", "three"]}`,
|
|
get: "numbers[0].nope",
|
|
output: nil,
|
|
},
|
|
}
|
|
|
|
func TestFixtures(t *testing.T) {
|
|
for _, fixture := range fixtures {
|
|
m := MustFromJSON(fixture.data)
|
|
|
|
// get the value
|
|
t.Logf("Running get fixture: \"%s\" (%v)", fixture.name, fixture)
|
|
value := m.Get(fixture.get.(string))
|
|
|
|
// make sure it matches
|
|
assert.Equal(t, fixture.output, value.data,
|
|
"Get fixture \"%s\" failed: %v", fixture.name, fixture,
|
|
)
|
|
}
|
|
}
|