github.com/wtfutil/wtf@v0.43.0/app/exit_message_test.go (about) 1 package app 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/wtfutil/wtf/support" 8 "gotest.tools/assert" 9 ) 10 11 func Test_displayExitMessage(t *testing.T) { 12 tests := []struct { 13 name string 14 isDisplayable bool 15 isContributor bool 16 isSponsor bool 17 compareWith string 18 expected string 19 }{ 20 { 21 name: "when not displayable", 22 isDisplayable: false, 23 isContributor: true, 24 isSponsor: true, 25 compareWith: "equals", 26 expected: "", 27 }, 28 { 29 name: "when contributor", 30 isDisplayable: true, 31 isContributor: true, 32 compareWith: "contains", 33 expected: "thank you for contributing", 34 }, 35 { 36 name: "when sponsor", 37 isDisplayable: true, 38 isSponsor: true, 39 compareWith: "contains", 40 expected: "Thank you for sponsoring", 41 }, 42 { 43 name: "when user", 44 isDisplayable: true, 45 isContributor: false, 46 isSponsor: false, 47 compareWith: "contains", 48 expected: "supported by sponsorships", 49 }, 50 } 51 52 for _, tt := range tests { 53 t.Run(tt.name, func(t *testing.T) { 54 wtfApp := WtfApp{} 55 wtfApp.ghUser = &support.GitHubUser{ 56 IsContributor: tt.isContributor, 57 IsSponsor: tt.isSponsor, 58 } 59 60 actual := wtfApp.displayExitMsg(tt.isDisplayable) 61 62 if tt.compareWith == "equals" { 63 assert.Equal(t, actual, tt.expected) 64 } 65 66 if tt.compareWith == "contains" { 67 assert.Equal(t, true, strings.Contains(actual, tt.expected)) 68 } 69 }) 70 } 71 }