MCPcopy Index your code
hub / github.com/ddev/ddev / TestDebugGobDecodeWithRealCacheFiles

Function TestDebugGobDecodeWithRealCacheFiles

cmd/ddev/cmd/debug-gob-decode_test.go:238–321  ·  view source on GitHub ↗

TestDebugGobDecodeWithRealCacheFiles tests with actual cache files if they exist

(t *testing.T)

Source from the content-addressed store, hash-verified

236
237// TestDebugGobDecodeWithRealCacheFiles tests with actual cache files if they exist
238func TestDebugGobDecodeWithRealCacheFiles(t *testing.T) {
239 // Try to find home directory
240 homeDir, err := os.UserHomeDir()
241 if err != nil {
242 t.Skip("Cannot determine home directory")
243 }
244
245 t.Run("RemoteConfig", func(t *testing.T) {
246 filePath := filepath.Join(homeDir, ".ddev", ".remote-config")
247 if _, err := os.Stat(filePath); os.IsNotExist(err) {
248 t.Skip("No real remote config file found, skipping test")
249 }
250
251 // Test decoding the file
252 out, err := exec.RunHostCommandSeparateStreams(DdevBin, "utility", "gob-decode", filePath)
253 require.NoError(t, err)
254
255 // Verify it's valid JSON
256 var data types.RemoteConfigData
257 err = json.Unmarshal([]byte(out), &data)
258 require.NoError(t, err, "Real remote config should decode to valid JSON")
259
260 // Basic structure validation
261 require.GreaterOrEqual(t, data.UpdateInterval, 0, "Update interval should be non-negative")
262
263 // If there are ticker messages, validate structure
264 if len(data.Messages.Ticker.Messages) > 0 {
265 for i, msg := range data.Messages.Ticker.Messages {
266 require.NotEmpty(t, msg.Message, "Ticker message %d should not be empty", i)
267 }
268 }
269 })
270
271 t.Run("SponsorshipData", func(t *testing.T) {
272 filePath := filepath.Join(homeDir, ".ddev", ".sponsorship-data")
273 if _, err := os.Stat(filePath); os.IsNotExist(err) {
274 t.Skip("No real sponsorship data file found, skipping test")
275 }
276
277 // Test decoding the file
278 out, err := exec.RunHostCommandSeparateStreams(DdevBin, "utility", "gob-decode", filePath)
279 require.NoError(t, err)
280
281 // Verify it's valid JSON
282 var data types.SponsorshipData
283 err = json.Unmarshal([]byte(out), &data)
284 require.NoError(t, err, "Real sponsorship data should decode to valid JSON")
285
286 // Basic structure validation
287 require.GreaterOrEqual(t, data.TotalMonthlyAverageIncome, 0.0, "Total income should be non-negative")
288 require.GreaterOrEqual(t, data.GitHubDDEVSponsorships.TotalSponsors, 0, "GitHub DDEV sponsors should be non-negative")
289 require.False(t, data.UpdatedDateTime.IsZero(), "Updated datetime should be set")
290 })
291
292 t.Run("AddonData", func(t *testing.T) {
293 filePath := filepath.Join(homeDir, ".ddev", ".addon-data")
294 if _, err := os.Stat(filePath); os.IsNotExist(err) {
295 t.Skip("No real add-on data file found, skipping test")

Callers

nothing calls this directly

Calls 2

UnmarshalMethod · 0.65

Tested by

no test coverage detected