github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/feedback/reporter_test.go (about) 1 /* 2 * Copyright (C) 2021 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package feedback 19 20 import ( 21 "fmt" 22 "testing" 23 24 "github.com/stretchr/testify/assert" 25 ) 26 27 func TestUserReport_Validate(t *testing.T) { 28 for _, data := range []struct { 29 email string 30 description string 31 expectToFail bool 32 testMSG string 33 }{ 34 { 35 email: "bad email", 36 description: "A proper description that has no trailing spaces to pad out it's length and has some grain of meaning", 37 expectToFail: true, 38 testMSG: "fail bad email", 39 }, 40 { 41 email: "", 42 description: "A proper description that has no trailing spaces to pad out it's length and has some grain of meaning", 43 expectToFail: true, 44 testMSG: "fail missing email", 45 }, 46 { 47 email: " ", 48 description: "A proper description that has no trailing spaces to pad out it's length and has some grain of meaning", 49 expectToFail: true, 50 testMSG: "fail missing email 2", 51 }, 52 { 53 email: "qa@qa.qa", 54 description: "A proper description that has no trailing spaces to pad out it's length and has some grain of meaning", 55 expectToFail: false, 56 testMSG: "pass valid report", 57 }, 58 { 59 email: "qa@qa.qa", 60 description: "Bad", 61 expectToFail: true, 62 testMSG: "fail short description", 63 }, 64 { 65 email: "qa@qa.qa", 66 description: " ", 67 expectToFail: true, 68 testMSG: "fail empty description", 69 }, 70 { 71 email: " test@email.com ", 72 description: " A proper description that has no trailing spaces to pad out it's length and has some grain of meaning ", 73 expectToFail: false, 74 testMSG: "pass valid email and description with spaces", 75 }, 76 } { 77 t.Run(data.testMSG, func(t *testing.T) { 78 r := UserReport{ 79 BugReport: BugReport{ 80 Email: data.email, 81 Description: data.description, 82 }, 83 } 84 85 assert.Equal(t, data.expectToFail, r.Validate() != nil, fmt.Sprintf("email= %s description= %s expected=%t", data.email, data.description, data.expectToFail)) 86 assert.Equal(t, data.expectToFail, r.BugReport.Validate() != nil, fmt.Sprintf("email= %s description= %s expected=%t", data.email, data.description, data.expectToFail)) 87 }) 88 } 89 }