package main import ( "reflect" "testing" "github.com/novox/mesh-controller/internal/inventory" "github.com/novox/mesh-controller/internal/link" ) // 1212/AC1 and AC2: the check request names the pulls bucket of each module claiming the delivery seat, in the order // of the claimants' names. func TestACheckNamesThePullsBucketsOfTheSeatsClaimants(t *testing.T) { for name, c := range map[string]struct { entries []inventory.Entry want []string }{ "only the gate": {[]inventory.Entry{claimingTheSeat("mesh-delivery-gate"), namedOnly("mesh-delivery")}, []string{"mesh-delivery-gate_pulls"}}, "only today's": {[]inventory.Entry{claimingTheSeat("mesh-delivery"), namedOnly("gitea")}, []string{"mesh-delivery_pulls"}}, "both, name order": {[]inventory.Entry{claimingTheSeat("mesh-delivery-gate"), claimingTheSeat("mesh-delivery")}, []string{"mesh-delivery_pulls", "mesh-delivery-gate_pulls"}}, "none": {[]inventory.Entry{namedOnly("gitea")}, nil}, } { if got := pullsBucketsOf(c.entries); !reflect.DeepEqual(got, c.want) { t.Errorf("%s: %v, want %v", name, got, c.want) } } } // 1212/AC1 and AC2: the check a request carries names those buckets (the wiring, not only the helper). func TestTheCheckRequestCarriesThePullsBuckets(t *testing.T) { for name, c := range map[string]struct { entries []inventory.Entry want []string }{ "only the gate": {[]inventory.Entry{claimingTheSeat("mesh-delivery-gate")}, []string{"mesh-delivery-gate_pulls"}}, "only today's": {[]inventory.Entry{claimingTheSeat("mesh-delivery")}, []string{"mesh-delivery_pulls"}}, "both, name order": {[]inventory.Entry{claimingTheSeat("mesh-delivery-gate"), claimingTheSeat("mesh-delivery")}, []string{"mesh-delivery_pulls", "mesh-delivery-gate_pulls"}}, } { got := checkOf(link.PullUpdated{Owner: "novox", Repo: "a", Number: 7}, checkScope{}, c.entries, nil, nil, nil, nil) if !reflect.DeepEqual(got.Pulls, c.want) || got.Owner != "novox" || got.Number != 7 { t.Errorf("%s: %+v, want pulls %v", name, got, c.want) } } }