MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / pollMessageStatus

Function pollMessageStatus

tests/helpers_test.go:165–194  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, messageID string, targetStatus string, timeout time.Duration)

Source from the content-addressed store, hash-verified

163}
164
165func pollMessageStatus(ctx context.Context, t *testing.T, messageID string, targetStatus string, timeout time.Duration) httpsms.Message {
166 t.Helper()
167 deadline := time.Now().Add(timeout)
168
169 for time.Now().Before(deadline) {
170 url := fmt.Sprintf("%s/v1/messages/%s", apiBaseURL, messageID)
171 req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
172 if err == nil {
173 req.Header.Set("x-api-key", userAPIKey)
174 req.Header.Set("Content-Type", "application/json")
175
176 resp, err := http.DefaultClient.Do(req)
177 if err == nil {
178 body, readErr := io.ReadAll(resp.Body)
179 resp.Body.Close()
180 if readErr == nil && resp.StatusCode == http.StatusOK {
181 var result httpsms.MessageResponse
182 if json.Unmarshal(body, &result) == nil && result.Data.Status == targetStatus {
183 return result.Data
184 }
185 }
186 }
187 }
188
189 time.Sleep(500 * time.Millisecond)
190 }
191
192 t.Fatalf("message %s did not reach status %q within %v", messageID, targetStatus, timeout)
193 return httpsms.Message{}
194}
195
196func fetchOutstandingMessage(ctx context.Context, t *testing.T, phoneAPIKey string, messageID string) map[string]interface{} {
197 t.Helper()

Callers 6

TestSendSMS_EncryptedFunction · 0.85
TestReceiveSMS_EncryptedFunction · 0.85
TestSendSMS_RateLimitFunction · 0.85
TestBulkSMS_CSVFunction · 0.85
TestBulkSMS_ExcelFunction · 0.85

Calls 1

SetMethod · 0.65

Tested by

no test coverage detected