(t *testing.T)
| 743 | } |
| 744 | |
| 745 | func TestFilterAcceptanceScripts(t *testing.T) { |
| 746 | userOnly := acceptanceScript{file: "user.txtar", requiresUserCapability: true} |
| 747 | compatible := acceptanceScript{file: "installation.txtar"} |
| 748 | |
| 749 | tests := []struct { |
| 750 | name string |
| 751 | candidates []acceptanceScript |
| 752 | filtered bool |
| 753 | hasUserCapability bool |
| 754 | wantFiles []string |
| 755 | wantSkip string |
| 756 | wantErr string |
| 757 | }{ |
| 758 | { |
| 759 | name: "user token keeps all scripts", |
| 760 | candidates: []acceptanceScript{userOnly, compatible}, |
| 761 | hasUserCapability: true, |
| 762 | wantFiles: []string{"user.txtar", "installation.txtar"}, |
| 763 | }, |
| 764 | { |
| 765 | name: "installation token omits user-only scripts", |
| 766 | candidates: []acceptanceScript{userOnly, compatible}, |
| 767 | wantFiles: []string{"installation.txtar"}, |
| 768 | }, |
| 769 | { |
| 770 | name: "all incompatible scripts skip", |
| 771 | candidates: []acceptanceScript{userOnly}, |
| 772 | wantSkip: "all scripts require a token that authenticates a user", |
| 773 | }, |
| 774 | { |
| 775 | name: "empty explicit selection skips", |
| 776 | filtered: true, |
| 777 | wantSkip: "no selected script belongs to this command directory", |
| 778 | }, |
| 779 | { |
| 780 | name: "explicit compatible selection remains", |
| 781 | candidates: []acceptanceScript{compatible}, |
| 782 | filtered: true, |
| 783 | wantFiles: []string{"installation.txtar"}, |
| 784 | }, |
| 785 | { |
| 786 | name: "explicit incompatible selection errors", |
| 787 | candidates: []acceptanceScript{userOnly}, |
| 788 | filtered: true, |
| 789 | wantErr: "user.txtar requires a token that authenticates a user", |
| 790 | }, |
| 791 | } |
| 792 | |
| 793 | for _, tt := range tests { |
| 794 | t.Run(tt.name, func(t *testing.T) { |
| 795 | files, skipReason, err := filterAcceptanceScripts(tt.candidates, tt.filtered, tt.hasUserCapability) |
| 796 | if tt.wantErr != "" { |
| 797 | require.EqualError(t, err, tt.wantErr) |
| 798 | return |
| 799 | } |
| 800 | require.NoError(t, err) |
| 801 | assert.Equal(t, tt.wantFiles, files) |
| 802 | assert.Equal(t, tt.wantSkip, skipReason) |
nothing calls this directly
no test coverage detected