func TestNullAPI(test *testing.T) {
	var api client.API = new(nullAPI)

	// all the methods return errors, all the time.

	if _, err := api.Machines(); err == nil {
		test.Error("Machines() did not return an error")
	}

	if _, err := api.Unit("foo"); err == nil {
		test.Error("Unit() did not return an error")
	}

	if _, err := api.Units(); err == nil {
		test.Error("Units() did not return an error")
	}

	if _, err := api.UnitStates(); err == nil {
		test.Error("UnitStates() did not return an error")
	}

	if err := api.SetUnitTargetState("foo", "bar"); err == nil {
		test.Error("SetUnitTargetState() did not return an error")
	}

	if err := api.CreateUnit(nil); err == nil {
		test.Error("CreateUnit() did not return an error")
	}

	if err := api.DestroyUnit("foo"); err == nil {
		test.Error("DestroyUnit() did not return an error")
	}
}
示例#2
0
func getMachinePage(cAPI client.API, tok PageToken) (*schema.MachinePage, error) {
	all, err := cAPI.Machines()
	if err != nil {
		return nil, err
	}

	page := extractMachinePage(all, tok)
	return page, nil
}
示例#3
0
func getMachines(client fleetClient.API, outMachines map[string]string) error {
	machines, err := client.Machines()
	if err != nil {
		return err
	}
	for _, machine := range machines {
		outMachines[machine.ID] = machine.PublicIP
	}
	return nil
}