Path: blob/main/vendor/github.com/onsi/gomega/matchers/be_closed_matcher.go
2880 views
// untested sections: 212package matchers34import (5"fmt"6"reflect"78"github.com/onsi/gomega/format"9)1011type BeClosedMatcher struct {12}1314func (matcher *BeClosedMatcher) Match(actual any) (success bool, err error) {15if !isChan(actual) {16return false, fmt.Errorf("BeClosed matcher expects a channel. Got:\n%s", format.Object(actual, 1))17}1819channelType := reflect.TypeOf(actual)20channelValue := reflect.ValueOf(actual)2122if channelType.ChanDir() == reflect.SendDir {23return false, fmt.Errorf("BeClosed matcher cannot determine if a send-only channel is closed or open. Got:\n%s", format.Object(actual, 1))24}2526winnerIndex, _, open := reflect.Select([]reflect.SelectCase{27{Dir: reflect.SelectRecv, Chan: channelValue},28{Dir: reflect.SelectDefault},29})3031var closed bool32if winnerIndex == 0 {33closed = !open34} else if winnerIndex == 1 {35closed = false36}3738return closed, nil39}4041func (matcher *BeClosedMatcher) FailureMessage(actual any) (message string) {42return format.Message(actual, "to be closed")43}4445func (matcher *BeClosedMatcher) NegatedFailureMessage(actual any) (message string) {46return format.Message(actual, "to be open")47}484950