(candidates []acceptanceScript, filtered, hasUserCapability bool)
| 721 | } |
| 722 | |
| 723 | func filterAcceptanceScripts(candidates []acceptanceScript, filtered, hasUserCapability bool) ([]string, string, error) { |
| 724 | if filtered && len(candidates) == 0 { |
| 725 | return nil, "no selected script belongs to this command directory", nil |
| 726 | } |
| 727 | |
| 728 | files := make([]string, 0, len(candidates)) |
| 729 | for _, candidate := range candidates { |
| 730 | if candidate.requiresUserCapability && !hasUserCapability { |
| 731 | if filtered { |
| 732 | return nil, "", fmt.Errorf("%s requires a token that authenticates a user", candidate.file) |
| 733 | } |
| 734 | continue |
| 735 | } |
| 736 | files = append(files, candidate.file) |
| 737 | } |
| 738 | if len(files) == 0 { |
| 739 | return nil, "all scripts require a token that authenticates a user", nil |
| 740 | } |
| 741 | |
| 742 | return files, "", nil |
| 743 | } |
| 744 | |
| 745 | func TestFilterAcceptanceScripts(t *testing.T) { |
| 746 | userOnly := acceptanceScript{file: "user.txtar", requiresUserCapability: true} |
no test coverage detected