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

Function TestDebugRemoteDataCmd

cmd/ddev/cmd/debug-remote-data_test.go:17–123  ·  view source on GitHub ↗

TestDebugRemoteDataCmd tests the ddev utility remote-data command

(t *testing.T)

Source from the content-addressed store, hash-verified

15
16// TestDebugRemoteDataCmd tests the ddev utility remote-data command
17func TestDebugRemoteDataCmd(t *testing.T) {
18 // Test help functionality
19 t.Run("Help", func(t *testing.T) {
20 out, err := exec.RunHostCommand(DdevBin, "utility", "remote-data", "--help")
21 require.NoError(t, err)
22 require.Contains(t, out, "Download and display remote data used by DDEV from GitHub repositories")
23 require.Contains(t, out, "remote-config: DDEV remote configuration")
24 require.Contains(t, out, "sponsorship-data: DDEV sponsorship information")
25 require.Contains(t, out, "addon-data: DDEV add-on registry")
26 require.Contains(t, out, "--type string")
27 require.Contains(t, out, "--update-storage")
28 })
29
30 // Test invalid data type
31 t.Run("InvalidDataType", func(t *testing.T) {
32 _, err := exec.RunHostCommand(DdevBin, "utility", "remote-data", "--type=invalid")
33 require.Error(t, err, "Should return error for invalid data type")
34 })
35
36 // Test remote config download (without updating storage)
37 t.Run("RemoteConfigDownload", func(t *testing.T) {
38 out, err := exec.RunHostCommandSeparateStreams(DdevBin, "utility", "remote-data", "--type=remote-config", "--update-storage=false")
39 require.NoError(t, err, "Should successfully download remote config, output='%v'", out)
40
41 // Parse the JSON output
42 var remoteConfig types.RemoteConfigData
43 err = json.Unmarshal([]byte(out), &remoteConfig)
44 require.NoError(t, err, "Output should be valid JSON: %s", out)
45
46 // Verify basic structure
47 require.GreaterOrEqual(t, remoteConfig.UpdateInterval, 0, "Update interval should be non-negative")
48 require.Greater(t, remoteConfig.Messages.Ticker.Interval, 0, "Ticker interval should be positive")
49 require.Greater(t, len(remoteConfig.Messages.Ticker.Messages), 0, "Should have ticker messages")
50
51 // Verify at least one ticker message has content
52 hasValidMessage := false
53 for _, msg := range remoteConfig.Messages.Ticker.Messages {
54 if msg.Message != "" {
55 hasValidMessage = true
56 break
57 }
58 }
59 require.True(t, hasValidMessage, "Should have at least one valid ticker message")
60 })
61
62 // Test sponsorship data download (without updating storage)
63 t.Run("SponsorshipDataDownload", func(t *testing.T) {
64 out, err := exec.RunHostCommandSeparateStreams(DdevBin, "utility", "remote-data", "--type=sponsorship-data", "--update-storage=false")
65 require.NoError(t, err, "Should successfully download sponsorship data, output='%v'", out)
66
67 // Parse the JSON output
68 var sponsorshipData types.SponsorshipData
69 err = json.Unmarshal([]byte(out), &sponsorshipData)
70 require.NoError(t, err, "Output should be valid JSON: %s", out)
71
72 // Verify basic structure - these should be reasonable values
73 require.GreaterOrEqual(t, sponsorshipData.TotalMonthlyAverageIncome, 0.0, "Total income should be non-negative")
74 require.GreaterOrEqual(t, sponsorshipData.GitHubDDEVSponsorships.TotalSponsors, 0, "GitHub DDEV sponsors should be non-negative")

Callers

nothing calls this directly

Calls 4

RunHostCommandFunction · 0.92
ErrorMethod · 0.80
UnmarshalMethod · 0.65

Tested by

no test coverage detected