Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

// This context holds all the configuration items in the same
// way that Eden context works: the commands line options override
// YAML settings. In addition to that, context is polymorphic in
// a sense that it abstracts away a particular controller (currently
// Adam and Zedcloud are supported)
tc *TestContext // TestContext is at least {
// controller *Controller
// project *Project
// nodes []EdgeNode
// ...
// }

// TestMain is used to provide setup and teardown for the rest of the
// tests. As part of setup we make sure that context has a slice of
// EVE instances that we can operate on. For any action, if the instance
// is not specified explicitly it is assumed to be the first one in the slice
func TestMain(m *testing.M) {
// this is expected to connect us to a desired controller
tc = NewTestContex(...)

// The following probably needs to be part of NewTestContext,
// I'm breaking it out to explain a few key things:

// Registering our own project namespace with controller for easy cleanup
tc.project = tc.controller.NewProject(GENERATED NAME BASED ON TestReboot + user + timestamp + uuid)

// Create representation of EVE instances (based on the names
// or UUIDs that were passed in) in the context. This is the first place
// where we're using zcli-like API:
for nodeName in range ... {
edgeNode := tc.controller.GetEdgeNode(nodeName)

if edgeNode == nil {
// Couldn't find existing edgeNode record in the controller.
// Need to create it from scratch now:
// this is modeled after: zcli edge-node create <name>
// --project=<project> --model=<model> [--title=<title>]
// ([--edge-node-certificate=<certificate>] |
// [--onboarding-certificate=<certificate>] |
// [(--onboarding-key=<key> --serial=<serial-number>)])
// [--network=<network>...]
//
// XXX: not sure if struct (giving us optional fields) would be better
edgeNode := tc.controller.NewEdgeNode(nodeName, tc.contr, ...)
} else {
// make sure to move EdgeNode to the project we created, again
// this is modeled after zcli edge-node update <name> [--title=<title>]
// [--lisp-mode=experimental|default] [--project=<project>]
// [--clear-onboarding-certs] [--config=<key:value>...] [--network=<network>...]
edgeNode.update(... project=XXX...)
}

// finally we need to make sure that the edgeNode is in a state that we need
// it to be, before the test can run -- this could be multiple checks on its
// status, but for example:
if edgeNode.GetStatus().state != registered {
// we may need to trasistion the node into registered state, or may be
// we just note that fact
}

// this is a good node -- lets add it to the test context
tc.addNode(edgeNode)
}

// we now have a situation where TestContext has enough EVE nodes known
// for the rest of the tests to run. So run them:
res := m.Run()

// Finally, we need to cleanup whatever objects may be in in the project we created
// and then we can exit

os.Exit(res)
}


func TestReboot(t *testing.T) {
// note that GetEdgeNode() without any argument is
// equivalent to the default (first one). Otherwise
// one can specify a name GetEdgeNode("foo")
edgeNode := tc.GetEdgeNode()

// this is modeled after: zcli edge-node reboot [-f] <name>
edgeNode.Reboot()

// this is how we make sure that the right event actually happens:
tc.AssertInfo("expected reboot to happen", func() {})

// now we're blocking until the time elapses or asserts fire
tc.WaitForAsserts(60) // this is guarantee to exit under 60 seconds
}