func TestAzureHandler(t *testing.T) {
	machine := new(client.Machine)
	machineDir := "."

	machine.AzureConfig = new(client.AzureConfig)
	machine.AzureConfig.SubscriptionCert = "QXp1cmVDb25maWc=" //base64 encoding of 'AzureConfig'

	azureHandler := &AzureHandler{}

	err := azureHandler.HandleCreate(machine, machineDir)

	if err != nil {
		t.Errorf("could not save subscriptionCert to path, err=%v", err)
		return
	}

	var f *os.File
	filename := filepath.Join(machineDir, "subscription-cert.pem")
	f, err = os.Open(filename)
	defer os.Remove(filename)

	if err != nil {
		t.Errorf("could not open saved file, err=%v", err)
		return
	}

	b := make([]byte, 11)
	f.Read(b)
	if string(b) != "AzureConfig" {
		t.Errorf("Saved data [AzureConfig] is not the same as actual data [%s]", string(b))
	}

}
func TestBuildContainerConfig(t *testing.T) {
	machine := new(client.Machine)

	machine.ExternalId = "externalId"
	labels := make(map[string]interface{})

	labels["abc"] = "def"
	labels["foo"] = "bar"

	machine.Labels = labels
	config := buildContainerConfig([]string{}, machine, "rancher/agent", "0.7.8")

	for _, elem := range config.Env {
		if elem == "CATTLE_HOST_LABELS=abc=def&foo=bar" || elem == "CATTLE_HOST_LABELS=foo=bar&abc=def" {
			return
		}
	}
	t.Error("label is not being set!")
}
func buildMockPublishReply(machine *client.Machine) mockPublishReplyFunc {
	return func(reply *client.Publish, apiClient *client.RancherClient) error {
		if reply.Data == nil {
			return nil
		}

		if machine.Data == nil {
			machine.Data = map[string]interface{}{}
		}

		if data, ok := reply.Data["+data"]; ok {
			d := data.(map[string]interface{})
			if machineDir, mdOk := d[machineDirField]; mdOk {
				machine.Data[machineDirField] = machineDir
			}

			if bootstrap, bootOk := d[bootstrappedAtField]; bootOk {
				machine.Data[bootstrappedAtField] = bootstrap
			}
		}
		return nil
	}
}