Exemple #1
0
func (representation *appRepresentation) buildApp() (*models.App, error) {
	appGuid := ""
	appVersion := ""

	desiredState := models.DesiredAppState{}
	if representation.hasDesired() {
		desiredState = representation.desiredState
		appGuid = desiredState.AppGuid
		appVersion = desiredState.AppVersion
	}

	actualState := representation.actualState
	if len(actualState) > 0 {
		appGuid = actualState[0].AppGuid
		appVersion = actualState[0].AppVersion
	}

	if appGuid == "" || appVersion == "" {
		return nil, nil
	}

	crashCounts := make(map[int]models.CrashCount)
	for _, crashCount := range representation.crashCounts {
		crashCounts[crashCount.InstanceIndex] = crashCount
	}

	return models.NewApp(appGuid, appVersion, desiredState, actualState, crashCounts), nil
}
				instanceHeartbeats := []models.InstanceHeartbeat{
					app.InstanceAtIndex(0).Heartbeat(),
					app.InstanceAtIndex(1).Heartbeat(),
					app.InstanceAtIndex(2).Heartbeat(),
				}
				crashCount := models.CrashCount{
					AppGuid:       app.AppGuid,
					AppVersion:    app.AppVersion,
					InstanceIndex: 1,
					CrashCount:    2,
				}
				expectedApp = models.NewApp(
					app.AppGuid,
					app.AppVersion,
					app.DesiredState(3),
					instanceHeartbeats,
					map[int]models.CrashCount{1: crashCount},
				)

				store.SyncDesiredState(app.DesiredState(3))
				store.SyncHeartbeats(app.Heartbeat(3))
				store.SaveCrashCounts(crashCount)
				validRequestPayload = fmt.Sprintf(`{"droplet":"%s","version":"%s"}`, app.AppGuid, app.AppVersion)
			})

			Context("when the store is fresh", func() {
				BeforeEach(func() {
					store.BumpDesiredFreshness(time.Unix(0, 0))
					store.BumpActualFreshness(time.Unix(0, 0))
				})