Best K6 code snippet using http.Set
players_controller_test.go
Source:players_controller_test.go
...20 e := echo.New()21 req := httptest.NewRequest(http.MethodGet, "/", nil)22 rec := httptest.NewRecorder()23 c := e.NewContext(req, rec)24 c.SetPath("/player")25 // Assertions26 if assert.NoError(t, GetAllPlayers(c)) {27 assert.Equal(t, http.StatusOK, rec.Code)28 }29}30func TestGetOnePlayer(t *testing.T) {31 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)32 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)33 e := echo.New()34 req := httptest.NewRequest(http.MethodGet, "/", nil)35 rec := httptest.NewRecorder()36 c := e.NewContext(req, rec)37 c.SetPath("/player/:id")38 c.SetParamNames("id")39 c.SetParamValues("5e70e4c5d2f3f777c16b29f7")40 // Assertions41 if assert.NoError(t, GetOnePlayer(c)) {42 assert.Equal(t, http.StatusOK, rec.Code)43 }44 req1 := httptest.NewRequest(http.MethodGet, "/", nil)45 rec1 := httptest.NewRecorder()46 c1 := e.NewContext(req1, rec1)47 c1.SetPath("/player/:id")48 c1.SetParamNames("id")49 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")50 if assert.NoError(t, GetOnePlayer(c1)) {51 assert.Equal(t, http.StatusUnprocessableEntity, rec1.Code)52 }53 req2 := httptest.NewRequest(http.MethodGet, "/", nil)54 rec2 := httptest.NewRecorder()55 c2 := e.NewContext(req2, rec2)56 c2.SetPath("/player/:id")57 c2.SetParamNames("id")58 c2.SetParamValues("BLA")59 if assert.NoError(t, GetOnePlayer(c2)) {60 assert.Equal(t, http.StatusBadRequest, rec2.Code)61 }62}63func TestPostPlayer(t *testing.T) {64 appcontext.Current.Add(appcontext.Dice, test.InitDiceMock)65 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)66 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)67 e := echo.New()68 example := "{\"key\":\"value\"}"69 requestByte, _ := json.Marshal(example)70 requestReader := bytes.NewReader(requestByte)71 req := httptest.NewRequest(http.MethodPost, "/", requestReader)72 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)73 rec := httptest.NewRecorder()74 c := e.NewContext(req, rec)75 c.SetPath("/player")76 // Assertions77 if assert.NoError(t, PostPlayer(c)) {78 assert.Equal(t, http.StatusBadRequest, rec.Code)79 }80 // example1 := player.Players{}81 // example1.AdventureID = "BLA"82 // requestByte1, _ := json.Marshal(example1)83 // requestReader1 := bytes.NewReader(requestByte1)84 // req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)85 // req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)86 // rec1 := httptest.NewRecorder()87 // c1 := e.NewContext(req1, rec1)88 // c1.SetPath("/player")89 // // Assertions90 // if assert.NoError(t, PostPlayer(c1)) {91 // assert.Equal(t, http.StatusBadRequest, rec1.Code)92 // }93 // example2 := player.Players{}94 // requestByte2, _ := json.Marshal(example2)95 // requestReader2 := bytes.NewReader(requestByte2)96 // req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)97 // req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)98 // rec2 := httptest.NewRecorder()99 // c2 := e.NewContext(req2, rec2)100 // c2.SetPath("/player")101 // // Assertions102 // if assert.NoError(t, PostPlayer(c2)) {103 // assert.Equal(t, http.StatusBadRequest, rec2.Code)104 // }105 example3 := player.Players{}106 requestByte3, _ := json.Marshal(example3)107 requestReader3 := bytes.NewReader(requestByte3)108 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)109 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)110 rec3 := httptest.NewRecorder()111 c3 := e.NewContext(req3, rec3)112 c3.SetPath("/player")113 // Assertions114 if assert.NoError(t, PostPlayer(c3)) {115 assert.Equal(t, http.StatusOK, rec3.Code)116 }117 // example4 := player.Players{}118 // requestByte4, _ := json.Marshal(example4)119 // requestReader4 := bytes.NewReader(requestByte4)120 // req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)121 // req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)122 // rec4 := httptest.NewRecorder()123 // c4 := e.NewContext(req4, rec4)124 // c4.SetPath("/player")125 // // Assertions126 // if assert.NoError(t, PostPlayer(c4)) {127 // assert.Equal(t, http.StatusBadRequest, rec4.Code)128 // }129}130func TestUpdateOnePlayer(t *testing.T) {131 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)132 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)133 e := echo.New()134 example := "{\"key\":\"value\"}"135 requestByte, _ := json.Marshal(example)136 requestReader := bytes.NewReader(requestByte)137 req := httptest.NewRequest(http.MethodPut, "/", requestReader)138 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)139 rec := httptest.NewRecorder()140 c := e.NewContext(req, rec)141 c.SetPath("/player")142 // Assertions143 if assert.NoError(t, UpdateOnePlayer(c)) {144 assert.Equal(t, http.StatusBadRequest, rec.Code)145 }146 // example1 := player.Players{}147 // requestByte1, _ := json.Marshal(example1)148 // requestReader1 := bytes.NewReader(requestByte1)149 // req1 := httptest.NewRequest(http.MethodPut, "/", requestReader1)150 // req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)151 // rec1 := httptest.NewRecorder()152 // c1 := e.NewContext(req1, rec1)153 // c1.SetPath("/player")154 // // Assertions155 // if assert.NoError(t, UpdateOnePlayer(c1)) {156 // assert.Equal(t, http.StatusBadRequest, rec1.Code)157 // }158 // example2 := player.Players{}159 // requestByte2, _ := json.Marshal(example2)160 // requestReader2 := bytes.NewReader(requestByte2)161 // req2 := httptest.NewRequest(http.MethodPut, "/", requestReader2)162 // req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)163 // rec2 := httptest.NewRecorder()164 // c2 := e.NewContext(req2, rec2)165 // c2.SetPath("/player")166 // // Assertions167 // if assert.NoError(t, UpdateOnePlayer(c2)) {168 // assert.Equal(t, http.StatusBadRequest, rec2.Code)169 // }170 example3 := player.Players{}171 requestByte3, _ := json.Marshal(example3)172 requestReader3 := bytes.NewReader(requestByte3)173 req3 := httptest.NewRequest(http.MethodPut, "/", requestReader3)174 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)175 rec3 := httptest.NewRecorder()176 c3 := e.NewContext(req3, rec3)177 c3.SetPath("/player")178 // Assertions179 if assert.NoError(t, UpdateOnePlayer(c3)) {180 assert.Equal(t, http.StatusOK, rec3.Code)181 }182 config.Values.RuleBuiltin = false183 example4 := player.Players{}184 requestByte4, _ := json.Marshal(example4)185 requestReader4 := bytes.NewReader(requestByte4)186 req4 := httptest.NewRequest(http.MethodPut, "/", requestReader4)187 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)188 rec4 := httptest.NewRecorder()189 c4 := e.NewContext(req4, rec4)190 c4.SetPath("/player")191 // Assertions192 if assert.NoError(t, UpdateOnePlayer(c4)) {193 assert.Equal(t, http.StatusOK, rec4.Code)194 }195}196func TestDeletePlayer(t *testing.T) {197 e := echo.New()198 req := httptest.NewRequest(http.MethodDelete, "/", nil)199 rec := httptest.NewRecorder()200 c := e.NewContext(req, rec)201 c.SetPath("/player/:id")202 c.SetParamNames("id")203 c.SetParamValues("5e70e4c5d2f3f777c16b29f7")204 // Assertions205 if assert.NoError(t, DeletePlayer(c)) {206 assert.Equal(t, http.StatusOK, rec.Code)207 }208 req1 := httptest.NewRequest(http.MethodDelete, "/", nil)209 rec1 := httptest.NewRecorder()210 c1 := e.NewContext(req1, rec1)211 c1.SetPath("/player/:id")212 c1.SetParamNames("id")213 c1.SetParamValues("BLA")214 // Assertions215 if assert.NoError(t, DeletePlayer(c1)) {216 assert.Equal(t, http.StatusBadRequest, rec1.Code)217 }218 //219 req2 := httptest.NewRequest(http.MethodDelete, "/", nil)220 rec2 := httptest.NewRecorder()221 c2 := e.NewContext(req2, rec2)222 c2.SetPath("/player/:id")223 c2.SetParamNames("id")224 c2.SetParamValues("5e70e4c5d2f3f777c16b29f8")225 // Assertions226 if assert.NoError(t, DeletePlayer(c2)) {227 assert.Equal(t, http.StatusBadRequest, rec2.Code)228 }229}230func TestAddCampaignToPlayer(t *testing.T) {231 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)232 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)233 e := echo.New()234 example := player.AddCampaign{}235 requestByte, _ := json.Marshal(example)236 requestReader := bytes.NewReader(requestByte)237 req := httptest.NewRequest(http.MethodPost, "/", requestReader)238 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)239 rec := httptest.NewRecorder()240 c := e.NewContext(req, rec)241 c.SetPath("/player/:id/campaign")242 c.SetParamNames("id")243 c.SetParamValues("BLA")244 // Assertions245 if assert.NoError(t, AddCampaignToPlayer(c)) {246 assert.Equal(t, http.StatusBadRequest, rec.Code)247 }248 example1 := player.AddCampaign{}249 requestByte1, _ := json.Marshal(example1)250 requestReader1 := bytes.NewReader(requestByte1)251 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)252 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)253 rec1 := httptest.NewRecorder()254 c1 := e.NewContext(req1, rec1)255 c1.SetPath("/player/:id/campaign")256 c1.SetParamNames("id")257 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")258 // Assertions259 if assert.NoError(t, AddCampaignToPlayer(c1)) {260 assert.Equal(t, http.StatusBadRequest, rec1.Code)261 }262 example2 := "{\"key\":\"value\"}"263 requestByte2, _ := json.Marshal(example2)264 requestReader2 := bytes.NewReader(requestByte2)265 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)266 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)267 rec2 := httptest.NewRecorder()268 c2 := e.NewContext(req2, rec2)269 c2.SetPath("/player/:id/campaign")270 c2.SetParamNames("id")271 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6")272 // Assertions273 if assert.NoError(t, AddCampaignToPlayer(c2)) {274 assert.Equal(t, http.StatusBadRequest, rec2.Code)275 }276 example3 := player.AddCampaign{}277 requestByte3, _ := json.Marshal(example3)278 requestReader3 := bytes.NewReader(requestByte3)279 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)280 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)281 rec3 := httptest.NewRecorder()282 c3 := e.NewContext(req3, rec3)283 c3.SetPath("/player/:id/campaign")284 c3.SetParamNames("id")285 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6")286 // Assertions287 if assert.NoError(t, AddCampaignToPlayer(c3)) {288 assert.Equal(t, http.StatusOK, rec3.Code)289 }290}291func TestAddOrRemoveHP(t *testing.T) {292 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)293 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)294 e := echo.New()295 req := httptest.NewRequest(http.MethodPut, "/", nil)296 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)297 rec := httptest.NewRecorder()298 c := e.NewContext(req, rec)299 c.SetPath("/player/:id/hp/:action/:value")300 c.SetParamNames("id", "action", "value")301 c.SetParamValues("BLA", "add", "10")302 // Assertions303 if assert.NoError(t, AddOrRemoveHP(c)) {304 assert.Equal(t, http.StatusBadRequest, rec.Code)305 }306 req1 := httptest.NewRequest(http.MethodPut, "/", nil)307 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)308 rec1 := httptest.NewRecorder()309 c1 := e.NewContext(req1, rec1)310 c1.SetPath("/player/:id/hp/:action/:value")311 c1.SetParamNames("id", "action", "value")312 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8", "add", "10")313 // Assertions314 if assert.NoError(t, AddOrRemoveHP(c1)) {315 assert.Equal(t, http.StatusBadRequest, rec1.Code)316 }317 req2 := httptest.NewRequest(http.MethodPut, "/", nil)318 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)319 rec2 := httptest.NewRecorder()320 c2 := e.NewContext(req2, rec2)321 c2.SetPath("/player/:id/hp/:action/:value")322 c2.SetParamNames("id", "action", "value")323 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "delete", "10")324 // Assertions325 if assert.NoError(t, AddOrRemoveHP(c2)) {326 assert.Equal(t, http.StatusBadRequest, rec2.Code)327 }328 req3 := httptest.NewRequest(http.MethodPut, "/", nil)329 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)330 rec3 := httptest.NewRecorder()331 c3 := e.NewContext(req3, rec3)332 c3.SetPath("/player/:id/hp/:action/:value")333 c3.SetParamNames("id", "action", "value")334 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add", "third")335 // Assertions336 if assert.NoError(t, AddOrRemoveHP(c3)) {337 assert.Equal(t, http.StatusBadRequest, rec3.Code)338 }339 req4 := httptest.NewRequest(http.MethodPut, "/", nil)340 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)341 rec4 := httptest.NewRecorder()342 c4 := e.NewContext(req4, rec4)343 c4.SetPath("/player/:id/hp/:action/:value")344 c4.SetParamNames("id", "action", "value")345 c4.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add", "10")346 // Assertions347 if assert.NoError(t, AddOrRemoveHP(c4)) {348 assert.Equal(t, http.StatusOK, rec4.Code)349 }350}351func TestAddPlayerXP(t *testing.T) {352 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)353 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)354 e := echo.New()355 req := httptest.NewRequest(http.MethodPut, "/", nil)356 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)357 rec := httptest.NewRecorder()358 c := e.NewContext(req, rec)359 c.SetPath("/player/:id/xp/:value")360 c.SetParamNames("id", "value")361 c.SetParamValues("BLA", "10")362 // Assertions363 if assert.NoError(t, AddPlayerXP(c)) {364 assert.Equal(t, http.StatusBadRequest, rec.Code)365 }366 req1 := httptest.NewRequest(http.MethodPut, "/", nil)367 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)368 rec1 := httptest.NewRecorder()369 c1 := e.NewContext(req1, rec1)370 c1.SetPath("/player/:id/xp/:value")371 c1.SetParamNames("id", "value")372 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8", "10")373 // Assertions374 if assert.NoError(t, AddPlayerXP(c1)) {375 assert.Equal(t, http.StatusBadRequest, rec1.Code)376 }377 req2 := httptest.NewRequest(http.MethodPut, "/", nil)378 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)379 rec2 := httptest.NewRecorder()380 c2 := e.NewContext(req2, rec2)381 c2.SetPath("/player/:id/xp/:value")382 c2.SetParamNames("id", "value")383 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "third")384 // Assertions385 if assert.NoError(t, AddPlayerXP(c2)) {386 assert.Equal(t, http.StatusBadRequest, rec2.Code)387 }388 req3 := httptest.NewRequest(http.MethodPut, "/", nil)389 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)390 rec3 := httptest.NewRecorder()391 c3 := e.NewContext(req3, rec3)392 c3.SetPath("/player/:id/xp/:value")393 c3.SetParamNames("id", "value")394 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "100")395 // Assertions396 if assert.NoError(t, AddPlayerXP(c3)) {397 assert.Equal(t, http.StatusOK, rec3.Code)398 }399 // req4 := httptest.NewRequest(http.MethodPut, "/", nil)400 // req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)401 // rec4 := httptest.NewRecorder()402 // c4 := e.NewContext(req4, rec4)403 // c4.SetPath("/player/:id/xp/:value")404 // c4.SetParamNames("id", "value")405 // c4.SetParamValues("5e70e4c5d2f3f777c16b29f6", "10")406 // // Assertions407 // if assert.NoError(t, AddPlayerXP(c4)) {408 // assert.Equal(t, http.StatusOK, rec4.Code)409 // }410}411func TestUseSpellByLevel(t *testing.T) {412 //413 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)414 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)415 e := echo.New()416 req := httptest.NewRequest(http.MethodPut, "/", nil)417 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)418 rec := httptest.NewRecorder()419 c := e.NewContext(req, rec)420 c.SetPath("/player/:id/spell/:level/:value")421 c.SetParamNames("id", "level", "value")422 c.SetParamValues("BLA", "1", "1")423 // Assertions424 if assert.NoError(t, UseSpellByLevel(c)) {425 assert.Equal(t, http.StatusBadRequest, rec.Code)426 }427 req1 := httptest.NewRequest(http.MethodPut, "/", nil)428 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)429 rec1 := httptest.NewRecorder()430 c1 := e.NewContext(req1, rec1)431 c1.SetPath("/player/:id/spell/:level/:value")432 c1.SetParamNames("id", "level", "value")433 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8", "1", "1")434 // Assertions435 if assert.NoError(t, UseSpellByLevel(c1)) {436 assert.Equal(t, http.StatusBadRequest, rec1.Code)437 }438 req2 := httptest.NewRequest(http.MethodPut, "/", nil)439 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)440 rec2 := httptest.NewRecorder()441 c2 := e.NewContext(req2, rec2)442 c2.SetPath("/player/:id/spell/:level/:value")443 c2.SetParamNames("id", "level", "value")444 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "10", "1")445 // Assertions446 if assert.NoError(t, UseSpellByLevel(c2)) {447 assert.Equal(t, http.StatusBadRequest, rec2.Code)448 }449 req3 := httptest.NewRequest(http.MethodPut, "/", nil)450 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)451 rec3 := httptest.NewRecorder()452 c3 := e.NewContext(req3, rec3)453 c3.SetPath("/player/:id/spell/:level/:value")454 c3.SetParamNames("id", "level", "value")455 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "1", "one")456 // Assertions457 if assert.NoError(t, UseSpellByLevel(c3)) {458 assert.Equal(t, http.StatusBadRequest, rec3.Code)459 }460 req4 := httptest.NewRequest(http.MethodPut, "/", nil)461 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)462 rec4 := httptest.NewRecorder()463 c4 := e.NewContext(req4, rec4)464 c4.SetPath("/player/:id/spell/:level/:value")465 c4.SetParamNames("id", "level", "value")466 c4.SetParamValues("5e70e4c5d2f3f777c16b29f6", "1", "1")467 // Assertions468 if assert.NoError(t, UseSpellByLevel(c4)) {469 assert.Equal(t, http.StatusOK, rec4.Code)470 }471}472func TestFullRestPlayer(t *testing.T) {473 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)474 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)475 e := echo.New()476 req := httptest.NewRequest(http.MethodPut, "/", nil)477 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)478 rec := httptest.NewRecorder()479 c := e.NewContext(req, rec)480 c.SetPath("/player/:id/fullrest")481 c.SetParamNames("id")482 c.SetParamValues("BLA")483 // Assertions484 if assert.NoError(t, FullRestPlayer(c)) {485 assert.Equal(t, http.StatusBadRequest, rec.Code)486 }487 req1 := httptest.NewRequest(http.MethodPut, "/", nil)488 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)489 rec1 := httptest.NewRecorder()490 c1 := e.NewContext(req1, rec1)491 c1.SetPath("/player/:id/fullrest")492 c1.SetParamNames("id")493 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")494 // Assertions495 if assert.NoError(t, FullRestPlayer(c1)) {496 assert.Equal(t, http.StatusBadRequest, rec1.Code)497 }498 req2 := httptest.NewRequest(http.MethodPut, "/", nil)499 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)500 rec2 := httptest.NewRecorder()501 c2 := e.NewContext(req2, rec2)502 c2.SetPath("/player/:id/fullrest")503 c2.SetParamNames("id")504 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6")505 // Assertions506 if assert.NoError(t, FullRestPlayer(c2)) {507 assert.Equal(t, http.StatusOK, rec2.Code)508 }509 // req3 := httptest.NewRequest(http.MethodPut, "/", nil)510 // req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)511 // rec3 := httptest.NewRecorder()512 // c3 := e.NewContext(req3, rec3)513 // c3.SetPath("/player/:id/fullrest")514 // c3.SetParamNames("id", "value")515 // c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "100")516 // // Assertions517 // if assert.NoError(t, FullRestPlayer(c3)) {518 // assert.Equal(t, http.StatusOK, rec3.Code)519 // }520}521func TestChangeCondition(t *testing.T) {522 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)523 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)524 e := echo.New()525 // player.Condition526 example := player.Condition{}527 requestByte, _ := json.Marshal(example)528 requestReader := bytes.NewReader(requestByte)529 req := httptest.NewRequest(http.MethodPost, "/", requestReader)530 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)531 rec := httptest.NewRecorder()532 c := e.NewContext(req, rec)533 c.SetPath("/player/:id/condition")534 c.SetParamNames("id")535 c.SetParamValues("BLA")536 // Assertions537 if assert.NoError(t, ChangeCondition(c)) {538 assert.Equal(t, http.StatusBadRequest, rec.Code)539 }540 example1 := player.Condition{}541 requestByte1, _ := json.Marshal(example1)542 requestReader1 := bytes.NewReader(requestByte1)543 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)544 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)545 rec1 := httptest.NewRecorder()546 c1 := e.NewContext(req1, rec1)547 c1.SetPath("/player/:id/condition")548 c1.SetParamNames("id")549 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")550 // Assertions551 if assert.NoError(t, ChangeCondition(c1)) {552 assert.Equal(t, http.StatusBadRequest, rec1.Code)553 }554 example2 := "{\"key\":\"value\"}"555 requestByte2, _ := json.Marshal(example2)556 requestReader2 := bytes.NewReader(requestByte2)557 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)558 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)559 rec2 := httptest.NewRecorder()560 c2 := e.NewContext(req2, rec2)561 c2.SetPath("/player/:id/condition")562 c2.SetParamNames("id")563 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6")564 // Assertions565 if assert.NoError(t, ChangeCondition(c2)) {566 assert.Equal(t, http.StatusBadRequest, rec2.Code)567 }568 example3 := player.Condition{}569 requestByte3, _ := json.Marshal(example3)570 requestReader3 := bytes.NewReader(requestByte3)571 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)572 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)573 rec3 := httptest.NewRecorder()574 c3 := e.NewContext(req3, rec3)575 c3.SetPath("/player/:id/condition")576 c3.SetParamNames("id")577 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6")578 // Assertions579 if assert.NoError(t, ChangeCondition(c3)) {580 assert.Equal(t, http.StatusOK, rec3.Code)581 }582}583func TestAddTreasure(t *testing.T) {584 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)585 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)586 e := echo.New()587 example := player.Treasure{}588 requestByte, _ := json.Marshal(example)589 requestReader := bytes.NewReader(requestByte)590 req := httptest.NewRequest(http.MethodPost, "/", requestReader)591 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)592 rec := httptest.NewRecorder()593 c := e.NewContext(req, rec)594 c.SetPath("/player/:id/treasure")595 c.SetParamNames("id")596 c.SetParamValues("BLA")597 // Assertions598 if assert.NoError(t, AddTreasure(c)) {599 assert.Equal(t, http.StatusBadRequest, rec.Code)600 }601 example1 := player.Treasure{}602 requestByte1, _ := json.Marshal(example1)603 requestReader1 := bytes.NewReader(requestByte1)604 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)605 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)606 rec1 := httptest.NewRecorder()607 c1 := e.NewContext(req1, rec1)608 c1.SetPath("/player/:id/treasure")609 c1.SetParamNames("id")610 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")611 // Assertions612 if assert.NoError(t, AddTreasure(c1)) {613 assert.Equal(t, http.StatusBadRequest, rec1.Code)614 }615 example2 := "{\"key\":\"value\"}"616 requestByte2, _ := json.Marshal(example2)617 requestReader2 := bytes.NewReader(requestByte2)618 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)619 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)620 rec2 := httptest.NewRecorder()621 c2 := e.NewContext(req2, rec2)622 c2.SetPath("/player/:id/treasure")623 c2.SetParamNames("id")624 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6")625 // Assertions626 if assert.NoError(t, AddTreasure(c2)) {627 assert.Equal(t, http.StatusBadRequest, rec2.Code)628 }629 example3 := player.Treasure{}630 requestByte3, _ := json.Marshal(example3)631 requestReader3 := bytes.NewReader(requestByte3)632 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)633 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)634 rec3 := httptest.NewRecorder()635 c3 := e.NewContext(req3, rec3)636 c3.SetPath("/player/:id/treasure")637 c3.SetParamNames("id")638 c3.SetParamValues("5e70e4c5d2f3f777c16b29f9")639 // Assertions640 if assert.NoError(t, AddTreasure(c3)) {641 assert.Equal(t, http.StatusBadRequest, rec3.Code)642 }643 example4 := player.Treasure{}644 requestByte4, _ := json.Marshal(example4)645 requestReader4 := bytes.NewReader(requestByte4)646 req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)647 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)648 rec4 := httptest.NewRecorder()649 c4 := e.NewContext(req4, rec4)650 c4.SetPath("/player/:id/treasure")651 c4.SetParamNames("id")652 c4.SetParamValues("5e70e4c5d2f3f777c16b29f6")653 // Assertions654 if assert.NoError(t, AddTreasure(c4)) {655 assert.Equal(t, http.StatusOK, rec4.Code)656 }657}658func TestAddOrRemoveOtherItems(t *testing.T) {659 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)660 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)661 e := echo.New()662 example := rule.SimpleList{}663 requestByte, _ := json.Marshal(example)664 requestReader := bytes.NewReader(requestByte)665 req := httptest.NewRequest(http.MethodPost, "/", requestReader)666 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)667 rec := httptest.NewRecorder()668 c := e.NewContext(req, rec)669 c.SetPath("/player/:id/items/:action")670 c.SetParamNames("id", "action")671 c.SetParamValues("BLA", "add")672 // Assertions673 if assert.NoError(t, AddOrRemoveOtherItems(c)) {674 assert.Equal(t, http.StatusBadRequest, rec.Code)675 }676 example1 := rule.SimpleList{}677 requestByte1, _ := json.Marshal(example1)678 requestReader1 := bytes.NewReader(requestByte1)679 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)680 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)681 rec1 := httptest.NewRecorder()682 c1 := e.NewContext(req1, rec1)683 c1.SetPath("/player/:id/items/:action")684 c1.SetParamNames("id", "action")685 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8", "add")686 // Assertions687 if assert.NoError(t, AddOrRemoveOtherItems(c1)) {688 assert.Equal(t, http.StatusBadRequest, rec1.Code)689 }690 example2 := "{\"key\":\"value\"}"691 requestByte2, _ := json.Marshal(example2)692 requestReader2 := bytes.NewReader(requestByte2)693 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)694 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)695 rec2 := httptest.NewRecorder()696 c2 := e.NewContext(req2, rec2)697 c2.SetPath("/player/:id/items/:action")698 c2.SetParamNames("id", "action")699 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add")700 // Assertions701 if assert.NoError(t, AddOrRemoveOtherItems(c2)) {702 assert.Equal(t, http.StatusBadRequest, rec2.Code)703 }704 example3 := rule.SimpleList{}705 requestByte3, _ := json.Marshal(example3)706 requestReader3 := bytes.NewReader(requestByte3)707 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)708 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)709 rec3 := httptest.NewRecorder()710 c3 := e.NewContext(req3, rec3)711 c3.SetPath("/player/:id/items/:action")712 c3.SetParamNames("id", "action")713 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "delete")714 // Assertions715 if assert.NoError(t, AddOrRemoveOtherItems(c3)) {716 assert.Equal(t, http.StatusBadRequest, rec3.Code)717 }718 example4 := rule.SimpleList{}719 requestByte4, _ := json.Marshal(example4)720 requestReader4 := bytes.NewReader(requestByte4)721 req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)722 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)723 rec4 := httptest.NewRecorder()724 c4 := e.NewContext(req4, rec4)725 c4.SetPath("/player/:id/items/:action")726 c4.SetParamNames("id", "action")727 c4.SetParamValues("5e70e4c5d2f3f777c16b29f9", "add")728 // Assertions729 if assert.NoError(t, AddOrRemoveOtherItems(c4)) {730 assert.Equal(t, http.StatusBadRequest, rec4.Code)731 }732 example5 := rule.SimpleList{}733 requestByte5, _ := json.Marshal(example5)734 requestReader5 := bytes.NewReader(requestByte5)735 req5 := httptest.NewRequest(http.MethodPost, "/", requestReader5)736 req5.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)737 rec5 := httptest.NewRecorder()738 c5 := e.NewContext(req5, rec5)739 c5.SetPath("/player/:id/items/:action")740 c5.SetParamNames("id", "action")741 c5.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add")742 // Assertions743 if assert.NoError(t, AddOrRemoveOtherItems(c5)) {744 assert.Equal(t, http.StatusOK, rec5.Code)745 }746}747func TestAddArmorWeaponPlayerByID(t *testing.T) {748 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)749 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)750 e := echo.New()751 example := player.Armory{}752 requestByte, _ := json.Marshal(example)753 requestReader := bytes.NewReader(requestByte)754 req := httptest.NewRequest(http.MethodPost, "/", requestReader)755 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)756 rec := httptest.NewRecorder()757 c := e.NewContext(req, rec)758 c.SetPath("/player/:id/armory")759 c.SetParamNames("id")760 c.SetParamValues("BLA")761 // Assertions762 if assert.NoError(t, AddArmorWeaponPlayerByID(c)) {763 assert.Equal(t, http.StatusBadRequest, rec.Code)764 }765 example1 := player.Armory{}766 requestByte1, _ := json.Marshal(example1)767 requestReader1 := bytes.NewReader(requestByte1)768 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)769 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)770 rec1 := httptest.NewRecorder()771 c1 := e.NewContext(req1, rec1)772 c1.SetPath("/player/:id/armory")773 c1.SetParamNames("id")774 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")775 // Assertions776 if assert.NoError(t, AddArmorWeaponPlayerByID(c1)) {777 assert.Equal(t, http.StatusBadRequest, rec1.Code)778 }779 example2 := "{\"key\":\"value\"}"780 requestByte2, _ := json.Marshal(example2)781 requestReader2 := bytes.NewReader(requestByte2)782 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)783 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)784 rec2 := httptest.NewRecorder()785 c2 := e.NewContext(req2, rec2)786 c2.SetPath("/player/:id/armory")787 c2.SetParamNames("id")788 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6")789 // Assertions790 if assert.NoError(t, AddArmorWeaponPlayerByID(c2)) {791 assert.Equal(t, http.StatusBadRequest, rec2.Code)792 }793 example3 := player.Armory{}794 requestByte3, _ := json.Marshal(example3)795 requestReader3 := bytes.NewReader(requestByte3)796 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)797 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)798 rec3 := httptest.NewRecorder()799 c3 := e.NewContext(req3, rec3)800 c3.SetPath("/player/:id/armory")801 c3.SetParamNames("id")802 c3.SetParamValues("5e70e4c5d2f3f777c16b29f9")803 // Assertions804 if assert.NoError(t, AddArmorWeaponPlayerByID(c3)) {805 assert.Equal(t, http.StatusBadRequest, rec3.Code)806 }807 example4 := player.Armory{}808 requestByte4, _ := json.Marshal(example4)809 requestReader4 := bytes.NewReader(requestByte4)810 req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)811 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)812 rec4 := httptest.NewRecorder()813 c4 := e.NewContext(req4, rec4)814 c4.SetPath("/player/:id/armory")815 c4.SetParamNames("id")816 c4.SetParamValues("5e70e4c5d2f3f777c16b29f6")817 // Assertions818 if assert.NoError(t, AddArmorWeaponPlayerByID(c4)) {819 assert.Equal(t, http.StatusOK, rec4.Code)820 }821}822func TestAddOrRemoveMagicItems(t *testing.T) {823 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)824 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)825 e := echo.New()826 example := rule.SimpleList{}827 requestByte, _ := json.Marshal(example)828 requestReader := bytes.NewReader(requestByte)829 req := httptest.NewRequest(http.MethodPost, "/", requestReader)830 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)831 rec := httptest.NewRecorder()832 c := e.NewContext(req, rec)833 c.SetPath("/player/:id/magicitems/:action")834 c.SetParamNames("id", "action")835 c.SetParamValues("BLA", "add")836 // Assertions837 if assert.NoError(t, AddOrRemoveMagicItems(c)) {838 assert.Equal(t, http.StatusBadRequest, rec.Code)839 }840 example1 := rule.SimpleList{}841 requestByte1, _ := json.Marshal(example1)842 requestReader1 := bytes.NewReader(requestByte1)843 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)844 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)845 rec1 := httptest.NewRecorder()846 c1 := e.NewContext(req1, rec1)847 c1.SetPath("/player/:id/magicitems/:action")848 c1.SetParamNames("id", "action")849 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8", "add")850 // Assertions851 if assert.NoError(t, AddOrRemoveMagicItems(c1)) {852 assert.Equal(t, http.StatusBadRequest, rec1.Code)853 }854 example2 := "{\"key\":\"value\"}"855 requestByte2, _ := json.Marshal(example2)856 requestReader2 := bytes.NewReader(requestByte2)857 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)858 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)859 rec2 := httptest.NewRecorder()860 c2 := e.NewContext(req2, rec2)861 c2.SetPath("/player/:id/magicitems/:action")862 c2.SetParamNames("id", "action")863 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add")864 // Assertions865 if assert.NoError(t, AddOrRemoveMagicItems(c2)) {866 assert.Equal(t, http.StatusBadRequest, rec2.Code)867 }868 example3 := rule.SimpleList{}869 requestByte3, _ := json.Marshal(example3)870 requestReader3 := bytes.NewReader(requestByte3)871 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)872 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)873 rec3 := httptest.NewRecorder()874 c3 := e.NewContext(req3, rec3)875 c3.SetPath("/player/:id/magicitems/:action")876 c3.SetParamNames("id", "action")877 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "delete")878 // Assertions879 if assert.NoError(t, AddOrRemoveMagicItems(c3)) {880 assert.Equal(t, http.StatusBadRequest, rec3.Code)881 }882 example4 := rule.SimpleList{}883 requestByte4, _ := json.Marshal(example4)884 requestReader4 := bytes.NewReader(requestByte4)885 req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)886 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)887 rec4 := httptest.NewRecorder()888 c4 := e.NewContext(req4, rec4)889 c4.SetPath("/player/:id/magicitems/:action")890 c4.SetParamNames("id", "action")891 c4.SetParamValues("5e70e4c5d2f3f777c16b29f9", "add")892 // Assertions893 if assert.NoError(t, AddOrRemoveMagicItems(c4)) {894 assert.Equal(t, http.StatusBadRequest, rec4.Code)895 }896 example5 := rule.SimpleList{}897 requestByte5, _ := json.Marshal(example5)898 requestReader5 := bytes.NewReader(requestByte5)899 req5 := httptest.NewRequest(http.MethodPost, "/", requestReader5)900 req5.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)901 rec5 := httptest.NewRecorder()902 c5 := e.NewContext(req5, rec5)903 c5.SetPath("/player/:id/magicitems/:action")904 c5.SetParamNames("id", "action")905 c5.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add")906 // Assertions907 if assert.NoError(t, AddOrRemoveMagicItems(c5)) {908 assert.Equal(t, http.StatusOK, rec5.Code)909 }910}...
adventure_controller_test.go
Source:adventure_controller_test.go
...18 e := echo.New()19 req := httptest.NewRequest(http.MethodGet, "/", nil)20 rec := httptest.NewRecorder()21 c := e.NewContext(req, rec)22 c.SetPath("/adventure")23 // Assertions24 if assert.NoError(t, GetAllAdventure(c)) {25 assert.Equal(t, http.StatusOK, rec.Code)26 }27}28func TestGetOneAdventure(t *testing.T) {29 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)30 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)31 e := echo.New()32 req := httptest.NewRequest(http.MethodGet, "/", nil)33 rec := httptest.NewRecorder()34 c := e.NewContext(req, rec)35 c.SetPath("/adventure/:id")36 c.SetParamNames("id")37 c.SetParamValues("5e70e4c5d2f3f777c16b29f7")38 // Assertions39 if assert.NoError(t, GetOneAdventure(c)) {40 assert.Equal(t, http.StatusOK, rec.Code)41 }42 req1 := httptest.NewRequest(http.MethodGet, "/", nil)43 rec1 := httptest.NewRecorder()44 c1 := e.NewContext(req1, rec1)45 c1.SetPath("/adventure/:id")46 c1.SetParamNames("id")47 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")48 if assert.NoError(t, GetOneAdventure(c1)) {49 assert.Equal(t, http.StatusUnprocessableEntity, rec1.Code)50 }51 req2 := httptest.NewRequest(http.MethodGet, "/", nil)52 rec2 := httptest.NewRecorder()53 c2 := e.NewContext(req2, rec2)54 c2.SetPath("/adventure/:id")55 c2.SetParamNames("id")56 c2.SetParamValues("BLA")57 if assert.NoError(t, GetOneAdventure(c2)) {58 assert.Equal(t, http.StatusBadRequest, rec2.Code)59 }60}61func TestPostAdventure(t *testing.T) {62 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)63 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)64 e := echo.New()65 example := "{\"key\":\"value\"}"66 requestByte, _ := json.Marshal(example)67 requestReader := bytes.NewReader(requestByte)68 req := httptest.NewRequest(http.MethodPost, "/", requestReader)69 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)70 rec := httptest.NewRecorder()71 c := e.NewContext(req, rec)72 c.SetPath("/adventure")73 // Assertions74 if assert.NoError(t, PostAdventure(c)) {75 assert.Equal(t, http.StatusBadRequest, rec.Code)76 }77 example1 := adventure.Adventure{}78 example1.CampaignID = "BLA"79 example1.Status = "onhold"80 requestByte1, _ := json.Marshal(example1)81 requestReader1 := bytes.NewReader(requestByte1)82 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)83 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)84 rec1 := httptest.NewRecorder()85 c1 := e.NewContext(req1, rec1)86 c1.SetPath("/adventure")87 // Assertions88 if assert.NoError(t, PostAdventure(c1)) {89 assert.Equal(t, http.StatusBadRequest, rec1.Code)90 }91 example2 := adventure.Adventure{}92 example2.CampaignID = "5e70e4c5d2f3f777c16b29f7"93 example2.Status = "onhold"94 requestByte2, _ := json.Marshal(example2)95 requestReader2 := bytes.NewReader(requestByte2)96 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)97 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)98 rec2 := httptest.NewRecorder()99 c2 := e.NewContext(req2, rec2)100 c2.SetPath("/adventure")101 // Assertions102 if assert.NoError(t, PostAdventure(c2)) {103 assert.Equal(t, http.StatusBadRequest, rec2.Code)104 }105 example3 := adventure.Adventure{}106 example3.CampaignID = "5e70e4c5d2f3f777c16b29f6"107 example3.Status = "onhold"108 requestByte3, _ := json.Marshal(example3)109 requestReader3 := bytes.NewReader(requestByte3)110 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)111 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)112 rec3 := httptest.NewRecorder()113 c3 := e.NewContext(req3, rec3)114 c3.SetPath("/adventure")115 // Assertions116 if assert.NoError(t, PostAdventure(c3)) {117 assert.Equal(t, http.StatusOK, rec3.Code)118 }119 example4 := adventure.Adventure{}120 example4.CampaignID = "5e70e4c5d2f4f777c16b29f6"121 example4.Status = "BLA"122 requestByte4, _ := json.Marshal(example4)123 requestReader4 := bytes.NewReader(requestByte4)124 req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)125 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)126 rec4 := httptest.NewRecorder()127 c4 := e.NewContext(req4, rec4)128 c4.SetPath("/adventure")129 // Assertions130 if assert.NoError(t, PostAdventure(c4)) {131 assert.Equal(t, http.StatusBadRequest, rec4.Code)132 }133}134func TestPutAdventure(t *testing.T) {135 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)136 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)137 e := echo.New()138 example := "{\"key\":\"value\"}"139 requestByte, _ := json.Marshal(example)140 requestReader := bytes.NewReader(requestByte)141 req := httptest.NewRequest(http.MethodPut, "/", requestReader)142 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)143 rec := httptest.NewRecorder()144 c := e.NewContext(req, rec)145 c.SetPath("/adventure")146 // Assertions147 if assert.NoError(t, PutAdventure(c)) {148 assert.Equal(t, http.StatusBadRequest, rec.Code)149 }150 example1 := adventure.Adventure{}151 example1.CampaignID = "BLA"152 example1.Status = "BLA"153 requestByte1, _ := json.Marshal(example1)154 requestReader1 := bytes.NewReader(requestByte1)155 req1 := httptest.NewRequest(http.MethodPut, "/", requestReader1)156 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)157 rec1 := httptest.NewRecorder()158 c1 := e.NewContext(req1, rec1)159 c1.SetPath("/adventure")160 // Assertions161 if assert.NoError(t, PutAdventure(c1)) {162 assert.Equal(t, http.StatusBadRequest, rec1.Code)163 }164 example2 := adventure.Adventure{}165 example2.CampaignID = "BLA"166 example2.Status = "onhold"167 requestByte2, _ := json.Marshal(example2)168 requestReader2 := bytes.NewReader(requestByte2)169 req2 := httptest.NewRequest(http.MethodPut, "/", requestReader2)170 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)171 rec2 := httptest.NewRecorder()172 c2 := e.NewContext(req2, rec2)173 c2.SetPath("/adventure")174 // Assertions175 if assert.NoError(t, PutAdventure(c2)) {176 assert.Equal(t, http.StatusBadRequest, rec2.Code)177 }178 example3 := adventure.Adventure{}179 example3.CampaignID = "5e70e4c5d2f3f777c16b29f8"180 example3.Status = "onhold"181 requestByte3, _ := json.Marshal(example3)182 requestReader3 := bytes.NewReader(requestByte3)183 req3 := httptest.NewRequest(http.MethodPut, "/", requestReader3)184 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)185 rec3 := httptest.NewRecorder()186 c3 := e.NewContext(req3, rec3)187 c3.SetPath("/adventure")188 // Assertions189 if assert.NoError(t, PutAdventure(c3)) {190 assert.Equal(t, http.StatusBadRequest, rec3.Code)191 }192 example4 := adventure.Adventure{}193 example4.CampaignID = "5e70e4c5d2f3f777c16b29f6"194 example4.Status = "onhold"195 requestByte4, _ := json.Marshal(example4)196 requestReader4 := bytes.NewReader(requestByte4)197 req4 := httptest.NewRequest(http.MethodPut, "/", requestReader4)198 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)199 rec4 := httptest.NewRecorder()200 c4 := e.NewContext(req4, rec4)201 c4.SetPath("/adventure")202 // Assertions203 if assert.NoError(t, PutAdventure(c4)) {204 assert.Equal(t, http.StatusOK, rec4.Code)205 }206}207func TestDeleteAdventure(t *testing.T) {208 e := echo.New()209 req := httptest.NewRequest(http.MethodDelete, "/", nil)210 rec := httptest.NewRecorder()211 c := e.NewContext(req, rec)212 c.SetPath("/adventure/:id")213 c.SetParamNames("id")214 c.SetParamValues("5e70e4c5d2f3f777c16b29f7")215 // Assertions216 if assert.NoError(t, DeleteAdventure(c)) {217 assert.Equal(t, http.StatusOK, rec.Code)218 }219 req1 := httptest.NewRequest(http.MethodDelete, "/", nil)220 rec1 := httptest.NewRecorder()221 c1 := e.NewContext(req1, rec1)222 c1.SetPath("/adventure/:id")223 c1.SetParamNames("id")224 c1.SetParamValues("BLA")225 // Assertions226 if assert.NoError(t, DeleteAdventure(c1)) {227 assert.Equal(t, http.StatusBadRequest, rec1.Code)228 }229 //230 req2 := httptest.NewRequest(http.MethodDelete, "/", nil)231 rec2 := httptest.NewRecorder()232 c2 := e.NewContext(req2, rec2)233 c2.SetPath("/adventure/:id")234 c2.SetParamNames("id")235 c2.SetParamValues("5e70e4c5d2f3f777c16b29f8")236 // Assertions237 if assert.NoError(t, DeleteAdventure(c2)) {238 assert.Equal(t, http.StatusUnprocessableEntity, rec2.Code)239 }240}241func TestAddEncounter(t *testing.T) {242 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)243 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)244 e := echo.New()245 example := "{\"key\":\"value\"}"246 requestByte, _ := json.Marshal(example)247 requestReader := bytes.NewReader(requestByte)248 req := httptest.NewRequest(http.MethodPost, "/", requestReader)249 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)250 rec := httptest.NewRecorder()251 c := e.NewContext(req, rec)252 c.SetPath("/adventure/:id/encounter")253 c.SetParamNames("id")254 c.SetParamValues("5e70e4c5d2f3f777c16b29f7")255 // Assertions256 if assert.NoError(t, AddEncounter(c)) {257 assert.Equal(t, http.StatusBadRequest, rec.Code)258 }259 example1 := adventure.Adventure{}260 requestByte1, _ := json.Marshal(example1)261 requestReader1 := bytes.NewReader(requestByte1)262 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)263 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)264 rec1 := httptest.NewRecorder()265 c1 := e.NewContext(req1, rec1)266 c1.SetPath("/adventure/:id/encounter")267 c1.SetParamNames("id")268 c1.SetParamValues("BLA")269 // Assertions270 if assert.NoError(t, AddEncounter(c1)) {271 assert.Equal(t, http.StatusBadRequest, rec1.Code)272 }273 example2 := adventure.Adventure{}274 requestByte2, _ := json.Marshal(example2)275 requestReader2 := bytes.NewReader(requestByte2)276 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)277 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)278 rec2 := httptest.NewRecorder()279 c2 := e.NewContext(req2, rec2)280 c2.SetPath("/adventure/:id/encounter")281 c2.SetParamNames("id")282 c2.SetParamValues("5e70e4c5d2f3f777c16b29f8")283 // Assertions284 if assert.NoError(t, AddEncounter(c2)) {285 assert.Equal(t, http.StatusBadRequest, rec2.Code)286 }287 example3 := adventure.Adventure{}288 requestByte3, _ := json.Marshal(example3)289 requestReader3 := bytes.NewReader(requestByte3)290 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)291 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)292 rec3 := httptest.NewRecorder()293 c3 := e.NewContext(req3, rec3)294 c3.SetPath("/adventure/:id/encounter")295 c3.SetParamNames("id")296 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6")297 // Assertions298 if assert.NoError(t, AddEncounter(c3)) {299 assert.Equal(t, http.StatusOK, rec3.Code)300 }301}302func TestChangeAdventureStatus(t *testing.T) {303 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)304 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)305 e := echo.New()306 example := adventure.Adventure{}307 requestByte, _ := json.Marshal(example)308 requestReader := bytes.NewReader(requestByte)309 req := httptest.NewRequest(http.MethodPut, "/", requestReader)310 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)311 rec := httptest.NewRecorder()312 c := e.NewContext(req, rec)313 c.SetPath("/adventure/:id/:status")314 c.SetParamNames("id", "status")315 c.SetParamValues("5e70e4c5d2f3f777c16b29f7", "living")316 // Assertions317 if assert.NoError(t, ChangeAdventureStatus(c)) {318 assert.Equal(t, http.StatusBadRequest, rec.Code)319 }320 example1 := adventure.Adventure{}321 requestByte1, _ := json.Marshal(example1)322 requestReader1 := bytes.NewReader(requestByte1)323 req1 := httptest.NewRequest(http.MethodPut, "/", requestReader1)324 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)325 rec1 := httptest.NewRecorder()326 c1 := e.NewContext(req1, rec1)327 c1.SetPath("/adventure/:id/:status")328 c1.SetParamNames("id", "status")329 c1.SetParamValues("5e70e4c5d2f3f777c16b29f6", "BLA")330 // Assertions331 if assert.NoError(t, ChangeAdventureStatus(c1)) {332 assert.Equal(t, http.StatusBadRequest, rec1.Code)333 }334 example2 := adventure.Adventure{}335 requestByte2, _ := json.Marshal(example2)336 requestReader2 := bytes.NewReader(requestByte2)337 req2 := httptest.NewRequest(http.MethodPut, "/", requestReader2)338 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)339 rec2 := httptest.NewRecorder()340 c2 := e.NewContext(req2, rec2)341 c2.SetPath("/adventure/:id/:status")342 c2.SetParamNames("id", "status")343 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "living")344 // Assertions345 if assert.NoError(t, ChangeAdventureStatus(c2)) {346 assert.Equal(t, http.StatusOK, rec2.Code)347 }348 example3 := adventure.Adventure{}349 requestByte3, _ := json.Marshal(example3)350 requestReader3 := bytes.NewReader(requestByte3)351 req3 := httptest.NewRequest(http.MethodPut, "/", requestReader3)352 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)353 rec3 := httptest.NewRecorder()354 c3 := e.NewContext(req3, rec3)355 c3.SetPath("/adventure/:id/:status")356 c3.SetParamNames("id", "status")357 c3.SetParamValues("BLA", "living")358 // Assertions359 if assert.NoError(t, ChangeAdventureStatus(c3)) {360 assert.Equal(t, http.StatusBadRequest, rec3.Code)361 }362 example4 := "{\"key\":\"value\"}"363 requestByte4, _ := json.Marshal(example4)364 requestReader4 := bytes.NewReader(requestByte4)365 req4 := httptest.NewRequest(http.MethodPut, "/", requestReader4)366 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)367 rec4 := httptest.NewRecorder()368 c4 := e.NewContext(req4, rec4)369 c4.SetPath("/adventure/:id/:status")370 c4.SetParamNames("id", "status")371 c4.SetParamValues("5e70e4c5d2f3f777c16b29f6", "living")372 // Assertions373 if assert.NoError(t, ChangeAdventureStatus(c4)) {374 assert.Equal(t, http.StatusBadRequest, rec4.Code)375 }376}...
gear_controller_test.go
Source:gear_controller_test.go
...19 e := echo.New()20 req := httptest.NewRequest(http.MethodGet, "/", nil)21 rec := httptest.NewRecorder()22 c := e.NewContext(req, rec)23 c.SetPath("/rule/weapon")24 // Assertions25 if assert.NoError(t, GetAllWeapons(c)) {26 assert.Equal(t, http.StatusOK, rec.Code)27 }28 value1 := make(url.Values)29 value1["names"] = []string{"longsword"}30 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)31 rec1 := httptest.NewRecorder()32 c1 := e.NewContext(req1, rec1)33 c1.SetPath("/rule/weapon")34 // Assertions35 if assert.NoError(t, GetAllWeapons(c1)) {36 assert.Equal(t, http.StatusBadRequest, rec1.Code)37 }38}39func TestGetAllArmors(t *testing.T) {40 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)41 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)42 e := echo.New()43 req := httptest.NewRequest(http.MethodGet, "/", nil)44 rec := httptest.NewRecorder()45 c := e.NewContext(req, rec)46 c.SetPath("/rule/armor")47 // Assertions48 if assert.NoError(t, GetAllArmors(c)) {49 assert.Equal(t, http.StatusOK, rec.Code)50 }51 value1 := make(url.Values)52 value1["names"] = []string{"plate"}53 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)54 rec1 := httptest.NewRecorder()55 c1 := e.NewContext(req1, rec1)56 c1.SetPath("/rule/armor")57 // Assertions58 if assert.NoError(t, GetAllArmors(c1)) {59 assert.Equal(t, http.StatusBadRequest, rec1.Code)60 }61}62func TestGetAllGear(t *testing.T) {63 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)64 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)65 e := echo.New()66 req := httptest.NewRequest(http.MethodGet, "/", nil)67 rec := httptest.NewRecorder()68 c := e.NewContext(req, rec)69 c.SetPath("/rule/gear")70 // Assertions71 if assert.NoError(t, GetAllGear(c)) {72 assert.Equal(t, http.StatusOK, rec.Code)73 }74 value1 := make(url.Values)75 value1["names"] = []string{"something"}76 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)77 rec1 := httptest.NewRecorder()78 c1 := e.NewContext(req1, rec1)79 c1.SetPath("/rule/gear")80 // Assertions81 if assert.NoError(t, GetAllGear(c1)) {82 assert.Equal(t, http.StatusBadRequest, rec1.Code)83 }84}85func TestGetAllPacks(t *testing.T) {86 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)87 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)88 e := echo.New()89 req := httptest.NewRequest(http.MethodGet, "/", nil)90 rec := httptest.NewRecorder()91 c := e.NewContext(req, rec)92 c.SetPath("/rule/packs")93 // Assertions94 if assert.NoError(t, GetAllPacks(c)) {95 assert.Equal(t, http.StatusOK, rec.Code)96 }97 value1 := make(url.Values)98 value1["names"] = []string{"something"}99 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)100 rec1 := httptest.NewRecorder()101 c1 := e.NewContext(req1, rec1)102 c1.SetPath("/rule/packs")103 // Assertions104 if assert.NoError(t, GetAllPacks(c1)) {105 assert.Equal(t, http.StatusBadRequest, rec1.Code)106 }107}108func TestGetAllTools(t *testing.T) {109 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)110 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)111 e := echo.New()112 req := httptest.NewRequest(http.MethodGet, "/", nil)113 rec := httptest.NewRecorder()114 c := e.NewContext(req, rec)115 c.SetPath("/rule/tools")116 // Assertions117 if assert.NoError(t, GetAllTools(c)) {118 assert.Equal(t, http.StatusOK, rec.Code)119 }120 value1 := make(url.Values)121 value1["names"] = []string{"something"}122 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)123 rec1 := httptest.NewRecorder()124 c1 := e.NewContext(req1, rec1)125 c1.SetPath("/rule/tools")126 // Assertions127 if assert.NoError(t, GetAllTools(c1)) {128 assert.Equal(t, http.StatusBadRequest, rec1.Code)129 }130}131func TestGetAllMounts(t *testing.T) {132 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)133 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)134 e := echo.New()135 req := httptest.NewRequest(http.MethodGet, "/", nil)136 rec := httptest.NewRecorder()137 c := e.NewContext(req, rec)138 c.SetPath("/rule/mounts")139 // Assertions140 if assert.NoError(t, GetAllMounts(c)) {141 assert.Equal(t, http.StatusOK, rec.Code)142 }143 value1 := make(url.Values)144 value1["names"] = []string{"something"}145 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)146 rec1 := httptest.NewRecorder()147 c1 := e.NewContext(req1, rec1)148 c1.SetPath("/rule/mounts")149 // Assertions150 if assert.NoError(t, GetAllMounts(c1)) {151 assert.Equal(t, http.StatusBadRequest, rec1.Code)152 }153}154func TestCalcShop(t *testing.T) {155 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)156 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)157 e := echo.New()158 example := rule.SimpleList{159 List: []string{"horse"},160 }161 requestByte, _ := json.Marshal(example)162 requestReader := bytes.NewReader(requestByte)163 req := httptest.NewRequest(http.MethodPost, "/", requestReader)164 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)165 rec := httptest.NewRecorder()166 c := e.NewContext(req, rec)167 c.SetPath("/rule/shops")168 // Assertions169 if assert.NoError(t, CalcShop(c)) {170 assert.Equal(t, http.StatusOK, rec.Code)171 }172 example2 := "{\"key\":\"value\"}"173 requestByte2, _ := json.Marshal(example2)174 requestReader2 := bytes.NewReader(requestByte2)175 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)176 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)177 rec2 := httptest.NewRecorder()178 c2 := e.NewContext(req2, rec2)179 c2.SetPath("/rule/shops")180 // Assertions181 if assert.NoError(t, CalcShop(c2)) {182 assert.Equal(t, http.StatusBadRequest, rec2.Code)183 }184}185func TestRandomTreasure(t *testing.T) {186 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)187 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)188 appcontext.Current.Add(appcontext.Dice, test.InitDiceMock)189 e := echo.New()190 req := httptest.NewRequest(http.MethodGet, "/", nil)191 rec := httptest.NewRecorder()192 c := e.NewContext(req, rec)193 c.SetPath("/rule/randomtreasure/:level")194 c.SetParamNames("level")195 c.SetParamValues("1")196 // Assertions197 if assert.NoError(t, RandomTreasure(c)) {198 assert.Equal(t, http.StatusOK, rec.Code)199 }200 req2 := httptest.NewRequest(http.MethodPost, "/", nil)201 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)202 rec2 := httptest.NewRecorder()203 c2 := e.NewContext(req2, rec2)204 c2.SetPath("/rule/randomtreasure/:level")205 c2.SetParamNames("level")206 c2.SetParamValues("a")207 // Assertions208 if assert.NoError(t, RandomTreasure(c2)) {209 assert.Equal(t, http.StatusBadRequest, rec2.Code)210 }211 req3 := httptest.NewRequest(http.MethodPost, "/", nil)212 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)213 rec3 := httptest.NewRecorder()214 c3 := e.NewContext(req3, rec3)215 c3.SetPath("/rule/randomtreasure/:level")216 c3.SetParamNames("level")217 c3.SetParamValues("31")218 // Assertions219 if assert.NoError(t, RandomTreasure(c3)) {220 assert.Equal(t, http.StatusBadRequest, rec3.Code)221 }222}223func TestFastTreasure(t *testing.T) {224 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)225 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)226 appcontext.Current.Add(appcontext.Dice, test.InitDiceMock)227 e := echo.New()228 req := httptest.NewRequest(http.MethodGet, "/", nil)229 rec := httptest.NewRecorder()230 c := e.NewContext(req, rec)231 c.SetPath("/rule/averagetreasure/:level")232 c.SetParamNames("level")233 c.SetParamValues("1")234 // Assertions235 if assert.NoError(t, FastTreasure(c)) {236 assert.Equal(t, http.StatusOK, rec.Code)237 }238 req2 := httptest.NewRequest(http.MethodPost, "/", nil)239 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)240 rec2 := httptest.NewRecorder()241 c2 := e.NewContext(req2, rec2)242 c2.SetPath("/rule/averagetreasure/:level")243 c2.SetParamNames("level")244 c2.SetParamValues("a")245 // Assertions246 if assert.NoError(t, FastTreasure(c2)) {247 assert.Equal(t, http.StatusBadRequest, rec2.Code)248 }249 req3 := httptest.NewRequest(http.MethodPost, "/", nil)250 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)251 rec3 := httptest.NewRecorder()252 c3 := e.NewContext(req3, rec3)253 c3.SetPath("/rule/averagetreasure/:level")254 c3.SetParamNames("level")255 c3.SetParamValues("31")256 // Assertions257 if assert.NoError(t, FastTreasure(c3)) {258 assert.Equal(t, http.StatusBadRequest, rec3.Code)259 }260}261func TestRandomTreasureHoard(t *testing.T) {262 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)263 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)264 appcontext.Current.Add(appcontext.Dice, test.InitDiceMock)265 e := echo.New()266 req := httptest.NewRequest(http.MethodGet, "/", nil)267 rec := httptest.NewRecorder()268 c := e.NewContext(req, rec)269 c.SetPath("/rule/treasurehoard/:level")270 c.SetParamNames("level")271 c.SetParamValues("1")272 // Assertions273 if assert.NoError(t, RandomTreasureHoard(c)) {274 assert.Equal(t, http.StatusOK, rec.Code)275 }276 req2 := httptest.NewRequest(http.MethodPost, "/", nil)277 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)278 rec2 := httptest.NewRecorder()279 c2 := e.NewContext(req2, rec2)280 c2.SetPath("/rule/treasurehoard/:level")281 c2.SetParamNames("level")282 c2.SetParamValues("a")283 // Assertions284 if assert.NoError(t, RandomTreasureHoard(c2)) {285 assert.Equal(t, http.StatusBadRequest, rec2.Code)286 }287 req3 := httptest.NewRequest(http.MethodPost, "/", nil)288 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)289 rec3 := httptest.NewRecorder()290 c3 := e.NewContext(req3, rec3)291 c3.SetPath("/rule/treasurehoard/:level")292 c3.SetParamNames("level")293 c3.SetParamValues("31")294 // Assertions295 if assert.NoError(t, RandomTreasureHoard(c3)) {296 assert.Equal(t, http.StatusBadRequest, rec3.Code)297 }298}299func TestGetAllServices(t *testing.T) {300 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)301 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)302 e := echo.New()303 req := httptest.NewRequest(http.MethodGet, "/", nil)304 rec := httptest.NewRecorder()305 c := e.NewContext(req, rec)306 c.SetPath("/rule/services")307 // Assertions308 if assert.NoError(t, GetAllServices(c)) {309 assert.Equal(t, http.StatusOK, rec.Code)310 }311 value1 := make(url.Values)312 value1["names"] = []string{"something"}313 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)314 rec1 := httptest.NewRecorder()315 c1 := e.NewContext(req1, rec1)316 c1.SetPath("/rule/services")317 // Assertions318 if assert.NoError(t, GetAllServices(c1)) {319 assert.Equal(t, http.StatusBadRequest, rec1.Code)320 }321}...
Set
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Println(err)5 }6 req.Header.Set("Content-Type", "application/json")7 fmt.Println(req)8}
Set
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Print(err.Error())5 }6 req.Header.Add("If-None-Match", `W/"wyzzy"`)7 client := &http.Client{}8 resp, err := client.Do(req)9 if err != nil {10 fmt.Print(err.Error())11 } else {12 fmt.Print(resp.Status)13 }14}
Set
Using AI Code Generation
1import (2func main() {3 if err != nil {4 }5 req.Header.Set("If-None-Match", `W/"wyzzy"`)6}7import (8func main() {9 if err != nil {10 }11 req.Header.Add("If-None-Match", `W/"wyzzy"`)12}13import (14func main() {15 if err != nil {16 }17 req.Header.Del("If-None-Match")18}19import (20func main() {21 if err != nil {22 }23 req.Header.Get("If-None-Match")24}25import (26func main() {27 if err != nil {28 }29 req.Header.Write(os.Stdout)30}31import
Set
Using AI Code Generation
1import (2func main() {3 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {4 fmt.Fprintf(w, "Hello, %q", r.URL.Path)5 })6 http.ListenAndServe(":8080", nil)7}8import (9func main() {10 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {11 fmt.Fprintf(w, "Hello, %q", r.URL.Path)12 })13 http.ListenAndServe(":8080", nil)14}15import (16func main() {17 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {18 fmt.Fprintf(w, "Hello, %q", r.URL.Path)19 })20 http.ListenAndServe(":8080", nil)21}22import (23func main() {24 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {25 fmt.Fprintf(w, "Hello, %q", r.URL.Path)26 })27 http.ListenAndServe(":8080", nil)28}29import (30func main() {31 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {32 fmt.Fprintf(w, "Hello, %q", r.URL.Path)33 })34 http.ListenAndServe(":8080", nil)35}36import (37func main() {38 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {39 fmt.Fprintf(w, "Hello, %q", r.URL.Path)40 })41 http.ListenAndServe(":8080", nil)42}43import (44func main() {45 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {46 fmt.Fprintf(w, "Hello, %q", r.URL.Path)47 })
Set
Using AI Code Generation
1http.SetCookie(w, &http.Cookie{2})3http.AddCookie(w, &http.Cookie{4})5http.AddCookie(w, &http.Cookie{6})7http.AddCookie(w, &http.Cookie{8})9http.AddCookie(w, &http.Cookie{10})11http.AddCookie(w, &http.Cookie{12})13http.AddCookie(w, &http.Cookie{14})15http.AddCookie(w, &http.Cookie{16})17http.AddCookie(w, &http.Cookie{18})19http.AddCookie(w, &http.Cookie{20})21http.AddCookie(w, &http.Cookie{22})23http.AddCookie(w, &http.Cookie{24})
Set
Using AI Code Generation
1import (2func main() {3http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {4w.Header().Set("Content-Type", "text/html")5w.Write([]byte("Hello World"))6})7log.Fatal(http.ListenAndServe(":8080", nil))8}9import (10func main() {11http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {12w.Header().Add("Content-Type", "text/html")13w.Write([]byte("Hello World"))14})15log.Fatal(http.ListenAndServe(":8080", nil))16}17import (18func main() {19http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {20w.Header().Del("Content-Type")21w.Write([]byte("Hello World"))22})23log.Fatal(http.ListenAndServe(":8080", nil))24}25import (26func main() {27http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {28w.Header().Set("Content-Type", "text/html")29w.Write([]byte("Hello World"))30})31log.Fatal(http.ListenAndServe(":8080", nil))32}33import (34func main() {35http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {36w.Header().Set("Content-Type", "text/html")37w.Write([]byte("Hello World"))38})39log.Fatal(http.ListenAndServe(":8080", nil))40}41import (42func main() {43http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {44w.Header().Set("Content-Type", "text/html")45w.Write([]byte("Hello World"))46})47log.Fatal(http.ListenAndServe(":8080", nil))48}49import (50func main() {51http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request)
Set
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Println(err)5 }6 req.Header.Set("If-None-Match", `W/"wyzzy"`)7 client := &http.Client{}8 resp, err := client.Do(req)9 if err != nil {10 fmt.Println(err)11 }12 fmt.Println("Response Status:", resp.Status)13 fmt.Println("Response Headers:", resp.Header)14}15Response Headers: map[Alt-Svc:[quic=":443"; ma=2592000; v="46,44,43,39"], Cache-Control:[private, max-age=0], Content-Type:[text/html; charset=ISO-8859-1], Date:[Thu, 18 Mar 2021 15:19:57 GMT], Expires:[-1], P3p:[CP="This is not a P3P policy! See g.co/p3phelp for more info."], Server:[gws], Set-Cookie:[1P_JAR=2021-03-18-15; expires=Sat, 17-Apr-2
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!