How to use TearDown method of validation Package

Best Gauge code snippet using validation.TearDown

api_test.go

Source:api_test.go Github

copy

Full Screen

1package tests2import (3 "testing"4 "encoding/json"5 "gopkg.in/resty.v1"6 "io/ioutil"7 "os"8 "github.com/bbernhard/imagemonkey-core/datastructures"9)10//const UNVERIFIED_DONATIONS_DIR string = "../unverified_donations/"11//const DONATIONS_DIR string = "../donations/"12type LoginResult struct {13 Token string `json:"token"`14}15type ValidateResult struct {16 Id string `json:"uuid"`17 Url string `json:"url"`18 Label string `json:"label"`19 Provider string `json:"provider"`20 Probability float32 `json:"probability"`21 NumOfValid int32 `json:"num_yes"`22 NumOfInvalid int32 `json:"num_no"`23}24type AnnotationRow struct {25 Image struct {26 Id string `json:"uuid"`27 } `json:"image"`28 Validation struct {29 Id string `json:"uuid"`30 Label string `json:"label"`31 Sublabel string `json:"sublabel"`32 } `json:"validation"`33}34func testSignUp(t *testing.T, username string, password string, email string) {35 numBefore, err := db.GetNumberOfUsers()36 ok(t, err)37 url := BASE_URL + API_VERSION + "/signup"38 resp, err := resty.R().39 SetHeader("Content-Type", "application/json").40 SetBody(map[string]interface{}{"username": username, "password": password, "email": email}).41 Post(url)42 equals(t, resp.StatusCode(), 201)43 numAfter, err := db.GetNumberOfUsers(); 44 ok(t, err)45 equals(t, numAfter, (numBefore + 1))46}47func testLogin(t *testing.T, username string, password string, requiredStatusCode int) string {48 url := BASE_URL + API_VERSION + "/login"49 resp, err := resty.R().50 SetBasicAuth(username, password).51 SetResult(&LoginResult{}).52 Post(url)53 ok(t, err)54 equals(t, resp.StatusCode(), requiredStatusCode)55 return resp.Result().(*LoginResult).Token56}57func testAnnotate(t *testing.T, imageId string, label string, sublabel string, annotations string, token string, expectedStatusCode int) {58 annotationEntry := datastructures.Annotations{Label: label, Sublabel: sublabel}59 err := json.Unmarshal([]byte(annotations), &annotationEntry.Annotations)60 ok(t, err)61 var annotationEntries []datastructures.Annotations62 annotationEntries = append(annotationEntries, annotationEntry)63 url := BASE_URL + API_VERSION + "/donation/" + imageId + "/annotate"64 req := resty.R().65 SetHeader("Content-Type", "application/json").66 SetBody(annotationEntries)67 if token != "" {68 req.SetAuthToken(token)69 }70 resp, err := req.Post(url)71 ok(t, err)72 equals(t, resp.StatusCode(), expectedStatusCode)73 if expectedStatusCode == 201 {74 //export annotations again75 url = resp.Header().Get("Location")76 req = resty.R().77 SetHeader("Content-Type", "application/json").78 SetResult(&datastructures.AnnotatedImage{})79 80 if token != "" {81 req.SetAuthToken(token)82 }83 resp, err = req.Get(url)84 ok(t, err)85 equals(t, resp.StatusCode(), 200)86 j, err := json.Marshal(&resp.Result().(*datastructures.AnnotatedImage).Annotations)87 ok(t, err)88 equal, err := equalJson(string(j), annotations)89 equals(t, equal, true)90 ok(t, err)91 }92}93func testRandomAnnotate(t *testing.T, num int, annotations string) {94 for i := 0; i < num; i++ {95 annotationRow, err := db.GetRandomImageForAnnotation()96 ok(t, err)97 testAnnotate(t, annotationRow.Image.Id, annotationRow.Validation.Label, 98 annotationRow.Validation.Sublabel, annotations, "", 201)99 }100}101func testDonate(t *testing.T, path string, label string, unlockImage bool, token string, imageCollectionName string, expectedStatusCode int) {102 numBefore, err := db.GetNumberOfImages()103 ok(t, err)104 url := BASE_URL + API_VERSION + "/donate"105 req := resty.R()106 if label == "" {107 req.108 SetFile("image", path)109 } else {110 req.111 SetFile("image", path)112 113 if imageCollectionName == "" {114 req.SetFormData(map[string]string{115 "label": label,116 })117 } else {118 req.SetFormData(map[string]string{119 "label": label,120 "image_collection": imageCollectionName,121 })122 }123 124 }125 if token != "" {126 req.SetAuthToken(token)127 }128 resp, err := req.Post(url)129 equals(t, resp.StatusCode(), expectedStatusCode)130 if expectedStatusCode == 200 {131 numAfter, err := db.GetNumberOfImages(); 132 ok(t, err)133 equals(t, numAfter, numBefore + 1)134 if unlockImage {135 //after image donation, unlock all images136 err = db.UnlockAllImages()137 ok(t, err)138 imageId, err := db.GetLatestDonatedImageId()139 ok(t, err)140 err = os.Rename(UNVERIFIED_DONATIONS_DIR + imageId, DONATIONS_DIR + imageId)141 ok(t, err)142 }143 }144}145func testMultipleDonate(t *testing.T, label string) int {146 dirname := "./images/apples/"147 files, err := ioutil.ReadDir(dirname)148 ok(t, err)149 num := 0150 for _, f := range files {151 testDonate(t, dirname + f.Name(), label, true, "", "", 200)152 num += 1153 }154 return num155}156/*func testMultipleDonateWithToken(t *testing.T, label string, token string) int {157 dirname := "./images/apples/"158 files, err := ioutil.ReadDir(dirname)159 ok(t, err)160 num := 0161 for _, f := range files {162 testDonate(t, dirname + f.Name(), label, true, token, "")163 num += 1164 }165 return num166}*/167func testGetImageForAnnotation(t *testing.T, imageId string, token string, validationId string, requiredStatusCode int) {168 url := BASE_URL + API_VERSION + "/annotate"169 req := resty.R()170 if token != "" {171 req.SetAuthToken(token)172 }173 if imageId != "" {174 req.SetQueryParams(map[string]string{175 "image_id": imageId,176 })177 }178 if validationId != "" {179 req.SetQueryParams(map[string]string{180 "validation_id": validationId,181 })182 }183 resp, err := req.Get(url)184 ok(t, err)185 equals(t, resp.StatusCode(), requiredStatusCode)186}187func testRandomLabel(t *testing.T, num int, skipLabel string) {188 imageIds, err := db.GetAllImageIds()189 ok(t, err)190 if num > len(imageIds) {191 t.Errorf("num can't be greater than the number of available images!")192 }193 for i := 0; i < num; i++ {194 image := imageIds[i]195 label, err := db.GetRandomLabelName(skipLabel)196 ok(t, err)197 testLabelImage(t, image, label, "", "", 200)198 }199}200func testGetImageToLabel(t *testing.T, imageId string, token string, requiredStatusCode int) {201 url := BASE_URL + API_VERSION + "/labelme"202 req := resty.R()203 if token != "" {204 req.SetAuthToken(token)205 }206 if imageId != "" {207 req.SetQueryParams(map[string]string{208 "image_id": imageId,209 })210 }211 resp, err := req.212 Get(url)213 ok(t, err)214 equals(t, resp.StatusCode(), requiredStatusCode)215}216func testGetImageDonation(t *testing.T, imageId string, imageUnlocked bool, token string, requiredStatusCode int) {217 url := "" 218 if imageUnlocked {219 url = BASE_URL + API_VERSION + "/donation/" + imageId220 } else {221 url = BASE_URL + API_VERSION + "/unverified-donation/" + imageId222 if token != "" {223 url += "?token=" + token224 }225 }226 req := resty.R()227 resp, err := req.Get(url)228 ok(t, err)229 equals(t, resp.StatusCode(), requiredStatusCode)230}231func testGetRandomImageQuiz(t *testing.T, requiredStatusCode int) {232 url := BASE_URL + API_VERSION + "/quiz-refine"233 req := resty.R()234 resp, err := req.Get(url)235 ok(t, err)236 equals(t, resp.StatusCode(), requiredStatusCode)237}238func testMarkValidationAsNotAnnotatable(t *testing.T, validationId string, num int) {239 for i := 0; i < num; i++ {240 url := BASE_URL + API_VERSION + "/validation/" + validationId + "/not-annotatable"241 resp, err := resty.R().242 Post(url)243 ok(t, err)244 equals(t, resp.StatusCode(), 200)245 }246}247func testBlacklistAnnotation(t *testing.T, validationId string, token string) {248 url := BASE_URL + API_VERSION + "/validation/" + validationId + "/blacklist-annotation"249 resp, err := resty.R().250 SetAuthToken(token).251 Post(url)252 ok(t, err)253 equals(t, resp.StatusCode(), 200)254}255func TestMultipleDonate(t *testing.T) {256 teardownTestCase := setupTestCase(t)257 defer teardownTestCase(t)258 testMultipleDonate(t, "apple")259}260func TestRandomAnnotate(t *testing.T) {261 teardownTestCase := setupTestCase(t)262 defer teardownTestCase(t)263 testMultipleDonate(t, "apple")264 testRandomAnnotate(t, 2, `[{"top":100,"left":200,"type":"rect","angle":0,"width":40,"height":60,"stroke":{"color":"red","width":1}}]`)265}266func TestSignUp(t *testing.T) {267 teardownTestCase := setupTestCase(t)268 defer teardownTestCase(t)269 testSignUp(t, "testuser", "testpassword", "testuser@imagemonkey.io")270}271func TestLogin(t *testing.T) {272 teardownTestCase := setupTestCase(t)273 defer teardownTestCase(t)274 testSignUp(t, "testuser", "testpassword", "testuser@imagemonkey.io")275 testLogin(t, "testuser", "testpassword", 200)276}277func TestLoginShouldFailDueToWrongPassword(t *testing.T) {278 teardownTestCase := setupTestCase(t)279 defer teardownTestCase(t)280 testSignUp(t, "testuser", "testpassword", "testuser@imagemonkey.io")281 testLogin(t, "testuser", "wrongpassword", 401)282}283func TestLoginShouldFailDueToWrongUsername(t *testing.T) {284 teardownTestCase := setupTestCase(t)285 defer teardownTestCase(t)286 testSignUp(t, "testuser", "testpassword", "testuser@imagemonkey.io")287 testLogin(t, "wronguser", "testpassword", 401)288}289func TestRandomLabel(t *testing.T) {290 teardownTestCase := setupTestCase(t)291 defer teardownTestCase(t)292 num, err := db.GetAllImageIds()293 ok(t, err)294 equals(t, int(len(num)), int(0))295 testMultipleDonate(t, "apple")296 testRandomLabel(t, 7, "apple")297}298func TestGetImageToLabel(t *testing.T) {299 teardownTestCase := setupTestCase(t)300 defer teardownTestCase(t)301 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)302 testGetImageToLabel(t, "", "", 200)303}304func TestGetUnlabeledImageToLabel(t *testing.T) {305 teardownTestCase := setupTestCase(t)306 defer teardownTestCase(t)307 testDonate(t, "./images/apples/apple1.jpeg", "", true, "", "", 200)308 testGetImageToLabel(t, "", "", 200)309}310func TestGetImageToLabel1(t *testing.T) {311 teardownTestCase := setupTestCase(t)312 defer teardownTestCase(t)313 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)314 testDonate(t, "./images/apples/apple2.jpeg", "", true, "", "", 200)315 testGetImageToLabel(t, "", "", 200)316}317func TestGetImageToLabelNotUnlocked(t *testing.T) {318 teardownTestCase := setupTestCase(t)319 defer teardownTestCase(t)320 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, "", "", 200)321 testGetImageToLabel(t, "", "", 422)322}323func TestGetImageToLabelNotUnlocked1(t *testing.T) {324 teardownTestCase := setupTestCase(t)325 defer teardownTestCase(t)326 testDonate(t, "./images/apples/apple1.jpeg", "", false, "", "", 200)327 testDonate(t, "./images/apples/apple2.jpeg", "apple", false, "", "", 200)328 testGetImageToLabel(t, "", "", 422)329}330func TestGetImageToLabelLockedButOwnDonation(t *testing.T) {331 teardownTestCase := setupTestCase(t)332 defer teardownTestCase(t)333 testSignUp(t, "user", "pwd", "user@imagemonkey.io")334 token := testLogin(t, "user", "pwd", 200)335 testDonate(t, "./images/apples/apple1.jpeg", "", false, token, "", 200)336 testGetImageToLabel(t, "", token, 200)337}338func TestGetImageToLabelLockedButOwnDonation1(t *testing.T) {339 teardownTestCase := setupTestCase(t)340 defer teardownTestCase(t)341 testSignUp(t, "user", "pwd", "user@imagemonkey.io")342 token := testLogin(t, "user", "pwd", 200)343 testDonate(t, "./images/apples/apple1.jpeg", "", false, token, "", 200)344 testDonate(t, "./images/apples/apple2.jpeg", "", true, token, "", 200)345 testGetImageToLabel(t, "", token, 200)346}347func TestGetImageToLabelLockedAndForeignDonation(t *testing.T) {348 teardownTestCase := setupTestCase(t)349 defer teardownTestCase(t)350 testSignUp(t, "user", "pwd", "user@imagemonkey.io")351 userToken := testLogin(t, "user", "pwd", 200)352 testSignUp(t, "user1", "pwd1", "user1@imagemonkey.io")353 userToken1 := testLogin(t, "user1", "pwd1", 200)354 testDonate(t, "./images/apples/apple1.jpeg", "", false, userToken, "", 200)355 testGetImageToLabel(t, "", userToken1, 422)356}357func TestGetImageByImageId(t *testing.T) {358 teardownTestCase := setupTestCase(t)359 defer teardownTestCase(t)360 //testSignUp(t, "user", "pwd", "user@imagemonkey.io")361 //userToken := testLogin(t, "user", "pwd", 200)362 testDonate(t, "./images/apples/apple1.jpeg", "", true, "", "", 200)363 imageId, err := db.GetLatestDonatedImageId()364 ok(t, err)365 testGetImageToLabel(t, imageId, "", 200)366}367func TestGetImageByImageIdForeignDonation(t *testing.T) {368 teardownTestCase := setupTestCase(t)369 defer teardownTestCase(t)370 testSignUp(t, "user", "pwd", "user@imagemonkey.io")371 userToken := testLogin(t, "user", "pwd", 200)372 testSignUp(t, "user1", "pwd1", "user1@imagemonkey.io")373 userToken1 := testLogin(t, "user1", "pwd1", 200)374 testDonate(t, "./images/apples/apple1.jpeg", "", false, userToken, "", 200)375 imageId, err := db.GetLatestDonatedImageId()376 ok(t, err)377 testGetImageToLabel(t, imageId, userToken1, 422)378}379func TestGetImageByImageIdOwnDonation(t *testing.T) {380 teardownTestCase := setupTestCase(t)381 defer teardownTestCase(t)382 testSignUp(t, "user", "pwd", "user@imagemonkey.io")383 userToken := testLogin(t, "user", "pwd", 200)384 testDonate(t, "./images/apples/apple1.jpeg", "", false, userToken, "", 200)385 imageId, err := db.GetLatestDonatedImageId()386 ok(t, err)387 testGetImageToLabel(t, imageId, userToken, 200)388}389func TestGetImageOwnDonationButPutInQuarantine(t *testing.T) {390 teardownTestCase := setupTestCase(t)391 defer teardownTestCase(t)392 testSignUp(t, "user", "pwd", "user@imagemonkey.io")393 userToken := testLogin(t, "user", "pwd", 200)394 testDonate(t, "./images/apples/apple1.jpeg", "", false, userToken, "", 200)395 imageId, err := db.GetLatestDonatedImageId()396 ok(t, err)397 err = db.PutImageInQuarantine(imageId)398 ok(t, err)399 testGetImageToLabel(t, "", userToken, 422)400}401func TestGetImageByIdOwnDonationButPutInQuarantine(t *testing.T) {402 teardownTestCase := setupTestCase(t)403 defer teardownTestCase(t)404 testSignUp(t, "user", "pwd", "user@imagemonkey.io")405 userToken := testLogin(t, "user", "pwd", 200)406 testDonate(t, "./images/apples/apple1.jpeg", "", false, userToken, "", 200)407 imageId, err := db.GetLatestDonatedImageId()408 ok(t, err)409 err = db.PutImageInQuarantine(imageId)410 ok(t, err)411 testGetImageToLabel(t, imageId, userToken, 422)412}413func TestGetImageToAnnotateButNotEnoughValidation(t *testing.T) {414 teardownTestCase := setupTestCase(t)415 defer teardownTestCase(t)416 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)417 testGetImageForAnnotation(t, "", "", "", 422)418}419func TestGetImageToAnnotate(t *testing.T) {420 teardownTestCase := setupTestCase(t)421 defer teardownTestCase(t)422 imageIds, err := db.GetAllImageIds()423 ok(t, err)424 equals(t, int(len(imageIds)), int(0))425 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)426 validationIds, err := db.GetAllValidationIds()427 ok(t, err)428 equals(t, int(len(validationIds)), int(1))429 err = db.SetValidationValid(validationIds[0], 5)430 ok(t, err)431 432 testGetImageForAnnotation(t, "", "", "", 200)433}434func TestGetImageToAnnotateButLocked(t *testing.T) {435 teardownTestCase := setupTestCase(t)436 defer teardownTestCase(t)437 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, "", "", 200)438 validationIds, err := db.GetAllValidationIds()439 ok(t, err)440 equals(t, len(validationIds), 1)441 err = db.SetValidationValid(validationIds[0], 5)442 ok(t, err)443 testGetImageForAnnotation(t, "", "", "", 422)444}445func TestGetImageToAnnotateUnlockedButBlacklistedBySignedUpUser(t *testing.T) {446 teardownTestCase := setupTestCase(t)447 defer teardownTestCase(t)448 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)449 validationIds, err := db.GetAllValidationIds()450 ok(t, err)451 err = db.SetValidationValid(validationIds[0], 5)452 ok(t, err)453 testSignUp(t, "user", "pwd", "user@imagemonkey.io")454 userToken := testLogin(t, "user", "pwd", 200)455 testBlacklistAnnotation(t, validationIds[0], userToken)456 testGetImageForAnnotation(t, "", "", "", 200)457}458func TestGetImageToAnnotateUnlockedButBlacklistedByOtherUser(t *testing.T) {459 teardownTestCase := setupTestCase(t)460 defer teardownTestCase(t)461 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)462 validationIds, err := db.GetAllValidationIds()463 ok(t, err)464 err = db.SetValidationValid(validationIds[0], 5)465 ok(t, err)466 testSignUp(t, "user", "pwd", "user@imagemonkey.io")467 userToken := testLogin(t, "user", "pwd", 200)468 testSignUp(t, "user1", "pwd1", "user1@imagemonkey.io")469 userToken1 := testLogin(t, "user1", "pwd1", 200)470 testBlacklistAnnotation(t, validationIds[0], userToken1)471 testGetImageForAnnotation(t, "", userToken, "", 200)472}473func TestGetImageToAnnotateUnlockedButBlacklistedByOwnUser(t *testing.T) {474 teardownTestCase := setupTestCase(t)475 defer teardownTestCase(t)476 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)477 validationIds, err := db.GetAllValidationIds()478 ok(t, err)479 err = db.SetValidationValid(validationIds[0], 5)480 ok(t, err)481 testSignUp(t, "user", "pwd", "user@imagemonkey.io")482 userToken := testLogin(t, "user", "pwd", 200)483 testBlacklistAnnotation(t, validationIds[0], userToken)484 testGetImageForAnnotation(t, "", userToken, "", 422)485}486func TestGetImageToAnnotateUnlockedButNotAnnotateable(t *testing.T) {487 teardownTestCase := setupTestCase(t)488 defer teardownTestCase(t)489 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)490 validationIds, err := db.GetAllValidationIds()491 ok(t, err)492 err = db.SetValidationValid(validationIds[0], 5)493 ok(t, err)494 testSignUp(t, "user", "pwd", "user@imagemonkey.io")495 userToken := testLogin(t, "user", "pwd", 200)496 //we need 3 not-annotatable votes until a annotation task won't show up anymore497 //(that's an arbitrary number that's set in the imagemonkey sourcecode)498 testMarkValidationAsNotAnnotatable(t, validationIds[0], 3)499 testGetImageForAnnotation(t, "", userToken, "", 422)500}501func TestGetImageToAnnotateLockedButOwnDonation(t *testing.T) {502 teardownTestCase := setupTestCase(t)503 defer teardownTestCase(t)504 testSignUp(t, "user", "pwd", "user@imagemonkey.io")505 userToken := testLogin(t, "user", "pwd", 200)506 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)507 validationIds, err := db.GetAllValidationIds()508 ok(t, err)509 err = db.SetValidationValid(validationIds[0], 5)510 ok(t, err)511 testGetImageForAnnotation(t, "", userToken, "", 200)512}513func TestGetImageToAnnotateLockedButForeignDonation(t *testing.T) {514 teardownTestCase := setupTestCase(t)515 defer teardownTestCase(t)516 testSignUp(t, "user", "pwd", "user@imagemonkey.io")517 userToken := testLogin(t, "user", "pwd", 200)518 testSignUp(t, "user1", "pwd1", "user1@imagemonkey.io")519 userToken1 := testLogin(t, "user1", "pwd1", 200)520 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)521 validationIds, err := db.GetAllValidationIds()522 ok(t, err)523 err = db.SetValidationValid(validationIds[0], 5)524 ok(t, err)525 testGetImageForAnnotation(t, "", userToken1, "", 422)526}527func TestGetImageToAnnotateLockedOwnDonationButQuarantine(t *testing.T) {528 teardownTestCase := setupTestCase(t)529 defer teardownTestCase(t)530 testSignUp(t, "user", "pwd", "user@imagemonkey.io")531 userToken := testLogin(t, "user", "pwd", 200)532 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)533 validationIds, err := db.GetAllValidationIds()534 ok(t, err)535 err = db.SetValidationValid(validationIds[0], 5)536 ok(t, err)537 imageId, err := db.GetLatestDonatedImageId()538 ok(t, err)539 err = db.PutImageInQuarantine(imageId)540 ok(t, err)541 testGetImageForAnnotation(t, "", userToken, "", 422)542}543func TestGetImageToAnnotateById(t *testing.T) {544 teardownTestCase := setupTestCase(t)545 defer teardownTestCase(t)546 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)547 validationIds, err := db.GetAllValidationIds()548 ok(t, err)549 err = db.SetValidationValid(validationIds[0], 5)550 ok(t, err)551 imageId, err := db.GetLatestDonatedImageId()552 ok(t, err)553 testGetImageForAnnotation(t, imageId, "", "", 200)554}555func TestGetImageToAnnotateByValidationId(t *testing.T) {556 teardownTestCase := setupTestCase(t)557 defer teardownTestCase(t)558 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)559 validationIds, err := db.GetAllValidationIds()560 ok(t, err)561 err = db.SetValidationValid(validationIds[0], 5)562 ok(t, err)563 testGetImageForAnnotation(t, "", "", validationIds[0], 200)564}565func TestGetImageToAnnotateLockedButOwnDonationByValidationId(t *testing.T) {566 teardownTestCase := setupTestCase(t)567 defer teardownTestCase(t)568 testSignUp(t, "user", "pwd", "user@imagemonkey.io")569 userToken := testLogin(t, "user", "pwd", 200)570 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)571 validationIds, err := db.GetAllValidationIds()572 ok(t, err)573 err = db.SetValidationValid(validationIds[0], 5)574 ok(t, err)575 testGetImageForAnnotation(t, "", userToken, validationIds[0], 200)576}577func TestGetImageToAnnotateByIdAuthenticated(t *testing.T) {578 teardownTestCase := setupTestCase(t)579 defer teardownTestCase(t)580 testSignUp(t, "user", "pwd", "user@imagemonkey.io")581 userToken := testLogin(t, "user", "pwd", 200)582 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)583 validationIds, err := db.GetAllValidationIds()584 ok(t, err)585 err = db.SetValidationValid(validationIds[0], 5)586 ok(t, err)587 imageId, err := db.GetLatestDonatedImageId()588 ok(t, err)589 testGetImageForAnnotation(t, imageId, userToken, "", 200)590}591func TestGetImageToAnnotateByIdButLocked(t *testing.T) {592 teardownTestCase := setupTestCase(t)593 defer teardownTestCase(t)594 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, "", "", 200)595 validationIds, err := db.GetAllValidationIds()596 ok(t, err)597 err = db.SetValidationValid(validationIds[0], 5)598 ok(t, err)599 imageId, err := db.GetLatestDonatedImageId()600 ok(t, err)601 testGetImageForAnnotation(t, imageId, "", "", 422)602}603func TestGetImageToAnnotateByIdLockedButOwnDonation(t *testing.T) {604 teardownTestCase := setupTestCase(t)605 defer teardownTestCase(t)606 testSignUp(t, "user", "pwd", "user@imagemonkey.io")607 userToken := testLogin(t, "user", "pwd", 200)608 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)609 validationIds, err := db.GetAllValidationIds()610 ok(t, err)611 err = db.SetValidationValid(validationIds[0], 5)612 ok(t, err)613 imageId, err := db.GetLatestDonatedImageId()614 ok(t, err)615 testGetImageForAnnotation(t, imageId, userToken, "", 200)616}617func TestGetImageToAnnotateByIdLockedAndForeignDonation(t *testing.T) {618 teardownTestCase := setupTestCase(t)619 defer teardownTestCase(t)620 testSignUp(t, "user", "pwd", "user@imagemonkey.io")621 userToken := testLogin(t, "user", "pwd", 200)622 testSignUp(t, "user1", "pwd1", "user1@imagemonkey.io")623 userToken1 := testLogin(t, "user1", "pwd1", 200)624 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)625 validationIds, err := db.GetAllValidationIds()626 ok(t, err)627 err = db.SetValidationValid(validationIds[0], 5)628 ok(t, err)629 imageId, err := db.GetLatestDonatedImageId()630 ok(t, err)631 testGetImageForAnnotation(t, imageId, userToken1, "", 422)632}633func TestGetImageToAnnotateByIdLockedOwnDonationButQuarantine(t *testing.T) {634 teardownTestCase := setupTestCase(t)635 defer teardownTestCase(t)636 testSignUp(t, "user", "pwd", "user@imagemonkey.io")637 userToken := testLogin(t, "user", "pwd", 200)638 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)639 validationIds, err := db.GetAllValidationIds()640 ok(t, err)641 err = db.SetValidationValid(validationIds[0], 5)642 ok(t, err)643 imageId, err := db.GetLatestDonatedImageId()644 ok(t, err)645 err = db.PutImageInQuarantine(imageId)646 ok(t, err)647 testGetImageForAnnotation(t, imageId, userToken, "", 422)648}649func TestGetUnlockedImageDonation(t *testing.T) {650 teardownTestCase := setupTestCase(t)651 defer teardownTestCase(t)652 testMultipleDonate(t, "apple")653 imageIds, err := db.GetAllImageIds()654 ok(t, err)655 for i := 0; i < len(imageIds); i++ {656 testGetImageDonation(t, imageIds[i], true, "", 200)657 }658}659func TestGetLockedImageDonationWithoutValidToken(t *testing.T) {660 teardownTestCase := setupTestCase(t)661 defer teardownTestCase(t)662 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, "", "", 200)663 imageId, err := db.GetLatestDonatedImageId()664 ok(t, err)665 testGetImageDonation(t, imageId, false, "", 403)666}667func TestGetLockedImageDonationOwnDonation(t *testing.T) {668 teardownTestCase := setupTestCase(t)669 defer teardownTestCase(t)670 testSignUp(t, "user", "pwd", "user@imagemonkey.io")671 userToken := testLogin(t, "user", "pwd", 200)672 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)673 imageId, err := db.GetLatestDonatedImageId()674 ok(t, err)675 testGetImageDonation(t, imageId, false, userToken, 200)676}677func TestGetLockedImageDonationForeignDonation(t *testing.T) {678 teardownTestCase := setupTestCase(t)679 defer teardownTestCase(t)680 testSignUp(t, "user", "pwd", "user@imagemonkey.io")681 userToken := testLogin(t, "user", "pwd", 200)682 testSignUp(t, "user1", "pwd1", "user1@imagemonkey.io")683 userToken1 := testLogin(t, "user1", "pwd1", 200)684 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)685 imageId, err := db.GetLatestDonatedImageId()686 ok(t, err)687 testGetImageDonation(t, imageId, false, userToken1, 403)688}...

Full Screen

Full Screen

image_validation_test.go

Source:image_validation_test.go Github

copy

Full Screen

1package tests2import (3 "testing"4 "gopkg.in/resty.v1"5 datastructures "github.com/bbernhard/imagemonkey-core/datastructures"6 "net/url"7)8func testValidate(t *testing.T) {9 url := BASE_URL + API_VERSION + "/validate"10 _, err := resty.R().11 SetResult(&ValidateResult{}).12 Get(url)13 ok(t, err)14}15func testImageValidation(t *testing.T, uuid string, param string, moderated bool, token string) {16 url := BASE_URL + API_VERSION + "/validation/" + uuid + "/validate/" + param17 var resp *resty.Response18 var err error19 if moderated {20 resp, err = resty.R().21 SetHeader("X-Moderation", "true").22 SetAuthToken(token).23 Post(url)24 } else {25 resp, err = resty.R().26 Post(url)27 }28 equals(t, resp.StatusCode(), 200)29 ok(t, err)30}31func testRandomImageValidation(t *testing.T, num int) {32 for i := 0; i < num; i++ {33 param := ""34 randomBool := randomBool()35 if randomBool {36 param = "yes"37 } else {38 param = "no"39 }40 randomValidationId, err := db.GetRandomValidationId()41 ok(t, err)42 beforeChangeNumValid, beforeChangeNumInvalid, err := db.GetValidationCount(randomValidationId)43 ok(t, err)44 testImageValidation(t, randomValidationId, param, false, "")45 afterChangeNumValid, afterChangeNumInvalid, err := db.GetValidationCount(randomValidationId)46 ok(t, err)47 if param == "yes" {48 equals(t, afterChangeNumValid, (beforeChangeNumValid + 1))49 } else {50 equals(t, afterChangeNumInvalid, (beforeChangeNumInvalid + 1))51 }52 }53}54func testRandomModeratedImageValidation(t *testing.T, num int, token string) {55 for i := 0; i < num; i++ {56 randomValidationId, err := db.GetRandomValidationId()57 ok(t, err)58 _, beforeChangeNumInvalid, err := db.GetValidationCount(randomValidationId)59 ok(t, err)60 testImageValidation(t, randomValidationId, "no", true, token)61 _, afterChangeNumInvalid, err := db.GetValidationCount(randomValidationId)62 ok(t, err)63 equals(t, afterChangeNumInvalid, (beforeChangeNumInvalid + 5))64 }65}66func testGetImageToValidate(t *testing.T, validationId string, token string, requiredStatusCode int) {67 url := BASE_URL + API_VERSION + "/validation"68 if validationId != "" {69 url += "/" + validationId70 }71 req := resty.R()72 if token != "" {73 req.SetAuthToken(token)74 }75 resp, err := req.Get(url)76 ok(t, err)77 equals(t, resp.StatusCode(), requiredStatusCode)78}79func testGetImagesForValidation(t *testing.T, query string, token string, requiredStatusCode int, numOfExpectedResults int) {80 var validations []datastructures.Validation81 u := BASE_URL + API_VERSION + "/validations"82 req := resty.R().83 SetQueryParams(map[string]string{84 "query": url.QueryEscape(query),85 }).86 SetResult(&validations)87 if token != "" {88 req.SetAuthToken(token)89 }90 resp, err := req.Get(u)91 ok(t, err)92 equals(t, resp.StatusCode(), requiredStatusCode)93 equals(t, len(validations), numOfExpectedResults)94}95func testBatchValidation(t *testing.T, validations []datastructures.ImageValidation, requiredStatusCode int) {96 var imageValidationBatch datastructures.ImageValidationBatch97 imageValidationBatch.Validations = validations98 u := BASE_URL + API_VERSION + "/validation/validate"99 req := resty.R().100 SetBody(imageValidationBatch)101 resp, err := req.Patch(u)102 ok(t, err)103 equals(t, resp.StatusCode(), requiredStatusCode)104}105func TestRandomImageValidation(t *testing.T) {106 teardownTestCase := setupTestCase(t)107 defer teardownTestCase(t)108 testMultipleDonate(t, "apple")109 testRandomImageValidation(t, 100)110}111func TestRandomModeratedImageValidation(t *testing.T) {112 teardownTestCase := setupTestCase(t)113 defer teardownTestCase(t)114 testMultipleDonate(t, "apple")115 testSignUp(t, "moderator", "moderator", "moderator@imagemonkey.io")116 moderatorToken := testLogin(t, "moderator", "moderator", 200)117 db.GiveUserModeratorRights("moderator") //give user moderator rights118 testRandomModeratedImageValidation(t, 100, moderatorToken)119}120func TestGetImageToValidate(t *testing.T) {121 teardownTestCase := setupTestCase(t)122 defer teardownTestCase(t)123 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)124 testGetImageToValidate(t, "", "", 200)125}126func TestGetImageToValidateById(t *testing.T) {127 teardownTestCase := setupTestCase(t)128 defer teardownTestCase(t)129 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)130 validationIds, err := db.GetAllValidationIds()131 ok(t, err)132 equals(t, len(validationIds), 1)133 testGetImageToValidate(t, validationIds[0], "", 200)134}135func TestGetImageToValidateByIdAuthenticatedWrongUser(t *testing.T) {136 teardownTestCase := setupTestCase(t)137 defer teardownTestCase(t)138 testSignUp(t, "user", "pwd", "user@imagemonkey.io")139 userToken := testLogin(t, "user", "pwd", 200)140 testSignUp(t, "user1", "pwd1", "user1@imagemonkey.io")141 userToken1 := testLogin(t, "user1", "pwd1", 200)142 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)143 validationIds, err := db.GetAllValidationIds()144 ok(t, err)145 equals(t, len(validationIds), 1)146 testGetImageToValidate(t, validationIds[0], userToken1, 422)147}148func TestGetImageToValidateAuthenticated(t *testing.T) {149 teardownTestCase := setupTestCase(t)150 defer teardownTestCase(t)151 testSignUp(t, "user", "pwd", "user@imagemonkey.io")152 userToken := testLogin(t, "user", "pwd", 200)153 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, userToken, "", 200)154 testGetImageToValidate(t, "", userToken, 200)155}156func TestGetImageToValidateByIdAuthenticated(t *testing.T) {157 teardownTestCase := setupTestCase(t)158 defer teardownTestCase(t)159 testSignUp(t, "user", "pwd", "user@imagemonkey.io")160 userToken := testLogin(t, "user", "pwd", 200)161 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, userToken, "", 200)162 validationIds, err := db.GetAllValidationIds()163 ok(t, err)164 equals(t, len(validationIds), 1)165 testGetImageToValidate(t, validationIds[0], userToken, 200)166}167func TestGetImageToValidateLocked(t *testing.T) {168 teardownTestCase := setupTestCase(t)169 defer teardownTestCase(t)170 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, "", "", 200)171 testGetImageToValidate(t, "", "", 422)172}173func TestGetImageToValidateLockedButOwnDonation(t *testing.T) {174 teardownTestCase := setupTestCase(t)175 defer teardownTestCase(t)176 testSignUp(t, "user", "pwd", "user@imagemonkey.io")177 userToken := testLogin(t, "user", "pwd", 200)178 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)179 testGetImageToValidate(t, "", userToken, 200)180}181func TestGetImagesForValidation(t *testing.T) {182 teardownTestCase := setupTestCase(t)183 defer teardownTestCase(t)184 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)185 testGetImagesForValidation(t, "apple", "", 200, 1)186}187func TestGetImagesForValidationStaticQueryAttributes1(t *testing.T) {188 teardownTestCase := setupTestCase(t)189 defer teardownTestCase(t)190 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)191 testGetImagesForValidation(t, "apple & image.width > 200px", "", 200, 1)192}193func TestGetImagesForValidationStaticQueryAttributes2(t *testing.T) {194 teardownTestCase := setupTestCase(t)195 defer teardownTestCase(t)196 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)197 testGetImagesForValidation(t, "apple & annotation.coverage = 0%", "", 200, 1)198}199func TestGetImagesForValidationEmptyResultSet(t *testing.T) {200 teardownTestCase := setupTestCase(t)201 defer teardownTestCase(t)202 testDonate(t, "./images/apples/apple1.jpeg", "apple", true, "", "", 200)203 testGetImagesForValidation(t, "car", "", 200, 0)204}205func TestGetImagesForValidationLockedEmptyResultSet(t *testing.T) {206 teardownTestCase := setupTestCase(t)207 defer teardownTestCase(t)208 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, "", "", 200)209 testGetImagesForValidation(t, "apple", "", 200, 0)210}211func TestGetImagesForValidationLockedAndOwnDonation(t *testing.T) {212 teardownTestCase := setupTestCase(t)213 defer teardownTestCase(t)214 testSignUp(t, "user", "pwd", "user@imagemonkey.io")215 userToken := testLogin(t, "user", "pwd", 200)216 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)217 testGetImagesForValidation(t, "apple", userToken, 200, 1)218}219func TestGetImagesForValidationLockedButForeignDonation(t *testing.T) {220 teardownTestCase := setupTestCase(t)221 defer teardownTestCase(t)222 testSignUp(t, "user", "pwd", "user@imagemonkey.io")223 userToken := testLogin(t, "user", "pwd", 200)224 testSignUp(t, "user1", "pwd1", "user1@imagemonkey.io")225 userToken1 := testLogin(t, "user1", "pwd1", 200)226 testDonate(t, "./images/apples/apple1.jpeg", "apple", false, userToken, "", 200)227 testGetImagesForValidation(t, "apple", userToken1, 200, 0)228}229func TestBatchValidation(t *testing.T) {230 teardownTestCase := setupTestCase(t)231 defer teardownTestCase(t)232 testMultipleDonate(t, "apple")233 validationIds, err := db.GetAllValidationIds()234 ok(t, err)235 validationId1NumOfValidBefore, validationId1NumOfInvalidBefore, err := db.GetValidationCount(validationIds[0])236 ok(t, err)237 validationId2NumOfValidBefore, validationId2NumOfInvalidBefore, err := db.GetValidationCount(validationIds[1])238 ok(t, err)239 var validations []datastructures.ImageValidation240 validation1 := datastructures.ImageValidation{Uuid: validationIds[0], Valid: "yes"}241 validations = append(validations, validation1)242 validation2 := datastructures.ImageValidation{Uuid: validationIds[1], Valid: "no"}243 validations = append(validations, validation2)244 testBatchValidation(t, validations, 204)245 validationId1NumOfValidAfter, validationId1NumOfInvalidAfter, err := db.GetValidationCount(validationIds[0])246 ok(t, err)247 validationId2NumOfValidAfter, validationId2NumOfInvalidAfter, err := db.GetValidationCount(validationIds[1])248 ok(t, err)249 equals(t, (validationId1NumOfValidBefore + 1), validationId1NumOfValidAfter)250 equals(t, validationId1NumOfInvalidBefore, validationId1NumOfInvalidAfter)251 equals(t, validationId2NumOfValidBefore, validationId2NumOfValidAfter)252 equals(t, (validationId2NumOfInvalidBefore + 1), validationId2NumOfInvalidAfter)253}...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

1package main2import (3 "bufio"4 "fmt"5 "io"6 "io/ioutil"7 "os"8 "os/exec"9 "path/filepath"10 "regexp"11 "strings"12 "time"13 yaml "gopkg.in/yaml.v2"14)15type Config struct {16 ValidationCmd string `yaml:"validation_cmd"`17 TeardownCmd string `yaml:"teardown_cmd"`18 Timeout int `yaml:"timeout"`19 ExpectedOutput string `yaml:"expected_output"`20}21func (c *Config) LoadFrom(path string) error {22 file, err := ioutil.ReadFile(path)23 if err != nil {24 return err25 }26 err = yaml.Unmarshal(file, c)27 if err != nil {28 return err29 }30 return nil31}32func main() {33 walkErr := filepath.Walk(".", func(exampleConfig string, f os.FileInfo, _ error) error {34 matches, _ := filepath.Match(".validate_example*.yml", f.Name())35 if !matches {36 return nil37 }38 exampleDirectory := filepath.Dir(exampleConfig)39 fmt.Printf("validating %s\n", exampleDirectory)40 ok, err := validate(exampleConfig)41 if err != nil {42 fmt.Printf("validation for %s failed, err: %v\n", exampleDirectory, err)43 return nil44 }45 if ok {46 fmt.Printf("validation for %s succeeded\n", exampleDirectory)47 return nil48 }49 fmt.Printf("validation for %s failed\n", exampleDirectory)50 return nil51 })52 if walkErr != nil {53 panic(walkErr)54 }55}56func validate(path string) (bool, error) {57 config := &Config{}58 err := config.LoadFrom(path)59 if err != nil {60 return false, fmt.Errorf("could not load config, err: %v", err)61 }62 cmdAndArgs := strings.Fields(config.ValidationCmd)63 validationCmd := exec.Command(cmdAndArgs[0], cmdAndArgs[1:]...)64 validationCmd.Dir = filepath.Dir(path)65 defer func() {66 if config.TeardownCmd == "" {67 return68 }69 cmdAndArgs := strings.Fields(config.TeardownCmd)70 teardownCmd := exec.Command(cmdAndArgs[0], cmdAndArgs[1:]...)71 teardownCmd.Dir = filepath.Dir(path)72 _ = teardownCmd.Run()73 }()74 stdout, err := validationCmd.StdoutPipe()75 if err != nil {76 return false, fmt.Errorf("could not attach to stdout, err: %v", err)77 }78 fmt.Printf("running: %v\n", validationCmd.Args)79 err = validationCmd.Start()80 if err != nil {81 return false, fmt.Errorf("could not start validation, err: %v", err)82 }83 success := make(chan bool)84 go func() {85 output := bufio.NewReader(stdout)86 for {87 line, _, err := output.ReadLine()88 if err != nil {89 if err == io.EOF {90 break91 }92 }93 ok, _ := regexp.Match(config.ExpectedOutput, line)94 if ok {95 success <- true96 return97 }98 }99 success <- false100 }()101 select {102 case success := <-success:103 return success, nil104 case <-time.After(time.Duration(config.Timeout) * time.Second):105 return false, fmt.Errorf("validation command timed out")106 }107}...

Full Screen

Full Screen

TearDown

Using AI Code Generation

copy

Full Screen

1import (2var (3 name = flag.String("name", "", "name")4 email = flag.String("email", "", "email")5func main() {6 flag.Parse()7 valid := validation.Validation{}8 valid.Required(*name, "name").Message("name is required")9 valid.MaxSize(*name, 10, "name").Message("name is too long")10 valid.Required(*email, "email").Message("email is required")11 valid.Email(*email, "email").Message("email is invalid")12 valid.MaxSize(*email, 20, "email").Message("email is too long")13 if valid.HasErrors() {14 for _, err := range valid.Errors {15 fmt.Println(err.Key, err.Message)16 }17 }18}

Full Screen

Full Screen

TearDown

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func (p Person) validate() error {5 if p.FirstName == "" {6 return fmt.Errorf("FirstName is empty")7 }8 if p.LastName == "" {9 return fmt.Errorf("LastName is empty")10 }11}12func (p Person) TearDown() {13 fmt.Println("TearDown")14}15func main() {16 p := Person{FirstName: "John", LastName: "Doe"}17 err := p.validate()18 if err != nil {19 fmt.Println(err)20 }21 teardown(p)22}23func teardown(i interface{}) {24 v := reflect.ValueOf(i)25 m := v.MethodByName("TearDown")26 if m.IsValid() {27 m.Call([]reflect.Value{})28 }29}

Full Screen

Full Screen

TearDown

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 validation := new(Validation)4 validation.TearDown()5}6type Validation struct {7}8func (v *Validation) TearDown() {9 fmt.Println("Enter the number of test cases:")10 fmt.Scanln(&testCases)11 for i := 0; i < testCases; i++ {12 fmt.Println("Enter the number of strings:")13 fmt.Scanln(&numberOfStrings)14 for j := 0; j < numberOfStrings; j++ {15 fmt.Println("Enter the string:")16 fmt.Scanln(&str)17 stringsArray = append(stringsArray, str)18 }19 fmt.Println("Enter the number of queries:")20 fmt.Scanln(&numberOfQueries)21 for j := 0; j < numberOfQueries; j++ {22 fmt.Println("Enter the query:")23 fmt.Scanln(&query)24 queriesArray = append(queriesArray, query)25 }26 v.ValidateStrings(stringsArray, queriesArray)27 }28}29func (v *Validation) ValidateStrings(stringsArray []string, queriesArray []string) {30}31import (32func main() {33 validation := new(Validation)34 validation.TearDown()35}36type Validation struct {37}38func (v *Validation) TearDown() {39 fmt.Println("Enter the number of test cases:")40 fmt.Scanln(&testCases)41 for i := 0; i < testCases; i++ {42 fmt.Println("Enter the number of strings:")43 fmt.Scanln(&numberOfStrings)44 for j := 0; j < numberOfStrings; j++ {45 fmt.Println("Enter the string:")

Full Screen

Full Screen

TearDown

Using AI Code Generation

copy

Full Screen

1func TestMain(m *testing.M) {2 validation := Validation{}3 validation.SetUp()4 code := m.Run()5 validation.TearDown()6 os.Exit(code)7}8func TestMain(m *testing.M) {9 validation := Validation{}10 validation.SetUp()11 code := m.Run()12 validation.TearDown()13 os.Exit(code)14}15import "strings"16func main() {17}18import "testing"19func TestString(t *testing.T) {20 result := String(s)21 if result != "HELLO WORLD" {22 t.Errorf("String(%s) = %s; want HELLO WORLD", s, result)23 }24}25import "strings"26func String(s string) string {27 return strings.ToUpper(s)28}29import "testing"30func TestString(t *testing.T) {31 result := String(s)32 if result != "HELLO WORLD" {33 t.Errorf("String(%s) = %s; want HELLO WORLD", s, result)34 }35}

Full Screen

Full Screen

TearDown

Using AI Code Generation

copy

Full Screen

1import (2type MyValidation struct {3}4func (v *MyValidation) TearDown() {5 fmt.Println("TearDown")6}7func main() {8 val := reflect.ValueOf(&MyValidation{})9 method := val.MethodByName("TearDown")10 method.Call([]reflect.Value{})11}12import (13type MyValidation struct {14}15func (v *MyValidation) TearDown() {16 fmt.Println("TearDown")17}18func main() {19 val := reflect.ValueOf(&MyValidation{})20 method := val.MethodByName("TearDown")21 method.Call([]reflect.Value{})22}23import (24type MyValidation struct {25}26func (v *MyValidation) TearDown() {27 fmt.Println("TearDown")28}29func main() {30 val := reflect.ValueOf(&MyValidation{})31 method := val.MethodByName("TearDown")32 method.Call([]reflect.Value{})33}34import (35type MyValidation struct {36}37func (v *MyValidation) TearDown() {38 fmt.Println("TearDown")39}40func main() {41 val := reflect.ValueOf(&MyValidation{})42 method := val.MethodByName("TearDown")43 method.Call([]reflect.Value{})44}45import (46type MyValidation struct {47}48func (v *MyValidation) TearDown() {49 fmt.Println("TearDown")50}51func main() {52 val := reflect.ValueOf(&MyValidation{})53 method := val.MethodByName("TearDown")54 method.Call([]reflect.Value{})55}56import (57type MyValidation struct {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful