func TestState_LoadCluster(t *testing.T) {
	t.Parallel()

	testPrefix := "TestState_LoadClusterState"
	etcdApi := testutil.ResetEtcd(t, testPrefix)
	logger := testutil.NewTestLogger(testPrefix, t)

	state, err := NewStateEtcdWithPrefix(testutil.LocalEtcdConfig, testPrefix, logger)
	if err != nil {
		t.Fatalf("Could not create state", err)
	}

	instanceID := structs.ClusterID(uuid.New())
	planID := uuid.New()

	node := structs.Node{ID: "node_id", CellGUID: "cell_guid"}
	clusterState := structs.ClusterState{
		InstanceID:       instanceID,
		OrganizationGUID: "OrganizationGUID",
		PlanID:           planID,
		ServiceID:        "ServiceID",
		SpaceGUID:        "SpaceGUID",
		SchedulingInfo: structs.SchedulingInfo{
			Status: structs.SchedulingStatusInProgress,
		},
	}
	clusterState.Nodes = []*structs.Node{&node}
	err = state.SaveCluster(clusterState)
	if err != nil {
		t.Fatalf("SaveCluster failed %s", err)
	}
	data, err := json.Marshal(node)
	key := fmt.Sprintf(
		"/%s/service/%s/nodes/%s", testPrefix, clusterState.InstanceID, node.ID)
	etcdApi.Set(context.Background(), key, string(data), &etcd.SetOptions{})

	loadedState, err := state.LoadCluster(instanceID)
	if !reflect.DeepEqual(clusterState, loadedState) {
		t.Fatalf("Failed to load ClusterState. Expected: %v, actual: %v", clusterState, loadedState)
	}
}
// If broker has credentials for a Cloud Foundry,
// attempt to look up service instance to get its user-provided name.
// This can then be used in future to undo/recreate-from-backup when user
// only knows the name they provided; and not the internal service instance ID.
// If operation fails, that's temporarily unfortunate but might be due to credentials
// not yet having SpaceDeveloper role for the Space being used.
func (bkr *Broker) fetchAndBackupServiceInstanceName(instanceID structs.ClusterID, clusterState *structs.ClusterState, logger lager.Logger) {
	if bkr.callbacks.Configured() {
		serviceInstanceName, err := bkr.cf.LookupServiceName(instanceID)
		if err != nil {
			logger.Error("backup-name.error", err,
				lager.Data{"action-required": "Fix issue and run errand/script to update clusterdata backups to include service names"})
		}
		if serviceInstanceName == "" {
			logger.Info("backup-name.not-found")
		} else {
			clusterState.ServiceInstanceName = serviceInstanceName
			bkr.callbacks.WriteRecreationData(clusterState.RecreationData())
			data, err := bkr.callbacks.RestoreRecreationData(instanceID)
			if !reflect.DeepEqual(clusterState.RecreationData(), data) {
				logger.Error("backup-name.update-recreation-data.failure", err)
			} else {
				logger.Info("backup-name.update-recreation-data.saved", lager.Data{"name": serviceInstanceName})
			}
		}
	}
}