package kpoll import ( "fmt" "strings" "gotest.tools/v3/poll" ) // JoinResults combines one or more polling results into a single // [gotest.tools/v3/poll.Result]. // // At least one poll.Result must be provided. If a single poll.Result is passed // in, it is returned directly. // // If any results contain an error, it is immediately returned. Otherwise, all // unfinished results have their messages combined into a single // [gotest.tools/v3/poll.Continue] call. If all results indicate they are done, // [gotest.tools/v3/poll.Success] is returned. // // TODO(aw18576): Consider generalizing this func JoinResults(results ...poll.Result) poll.Result { if len(results) == 0 { return poll.Error(fmt.Errorf("can't join 0 results, need at least one")) } if len(results) == 1 { return results[0] //nolint:gosec // I know the array has a length of 1 } var msgs []string for _, r := range results { if r.Error() != nil { return r } if !r.Done() { msgs = append(msgs, r.Message()) } } if len(msgs) > 0 { return poll.Continue("waiting on %d checks (%d/%d complete):\n%s", len(msgs), len(results)-len(msgs), len(results), strings.Join(msgs, "\n\n")) } return poll.Success() }