How to use All method of utils Package

Best Rod code snippet using utils.All

router_test.go

Source:router_test.go Github

copy

Full Screen

...31 })32 resp, err := app.Test(httptest.NewRequest(MethodGet, "/:param", nil))33 utils.AssertEqual(t, nil, err, "app.Test(req)")34 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")35 body, err := ioutil.ReadAll(resp.Body)36 utils.AssertEqual(t, nil, err, "app.Test(req)")37 utils.AssertEqual(t, ":param", app.getString(body))38 // with param39 resp, err = app.Test(httptest.NewRequest(MethodGet, "/test", nil))40 utils.AssertEqual(t, nil, err, "app.Test(req)")41 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")42 body, err = ioutil.ReadAll(resp.Body)43 utils.AssertEqual(t, nil, err, "app.Test(req)")44 utils.AssertEqual(t, "test", app.getString(body))45}46func Test_Route_Match_Star(t *testing.T) {47 app := New()48 app.Get("/*", func(c *Ctx) error {49 return c.SendString(c.Params("*"))50 })51 resp, err := app.Test(httptest.NewRequest(MethodGet, "/*", nil))52 utils.AssertEqual(t, nil, err, "app.Test(req)")53 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")54 body, err := ioutil.ReadAll(resp.Body)55 utils.AssertEqual(t, nil, err, "app.Test(req)")56 utils.AssertEqual(t, "*", app.getString(body))57 // with param58 resp, err = app.Test(httptest.NewRequest(MethodGet, "/test", nil))59 utils.AssertEqual(t, nil, err, "app.Test(req)")60 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")61 body, err = ioutil.ReadAll(resp.Body)62 utils.AssertEqual(t, nil, err, "app.Test(req)")63 utils.AssertEqual(t, "test", app.getString(body))64 // without parameter65 route := Route{66 star: true,67 path: "/*",68 routeParser: routeParser{},69 }70 params := [maxParams]string{}71 match := route.match("", "", &params)72 utils.AssertEqual(t, true, match)73 utils.AssertEqual(t, [maxParams]string{}, params)74 // with parameter75 match = route.match("/favicon.ico", "/favicon.ico", &params)76 utils.AssertEqual(t, true, match)77 utils.AssertEqual(t, [maxParams]string{"favicon.ico"}, params)78 // without parameter again79 match = route.match("", "", &params)80 utils.AssertEqual(t, true, match)81 utils.AssertEqual(t, [maxParams]string{}, params)82}83func Test_Route_Match_Root(t *testing.T) {84 app := New()85 app.Get("/", func(c *Ctx) error {86 return c.SendString("root")87 })88 resp, err := app.Test(httptest.NewRequest(MethodGet, "/", nil))89 utils.AssertEqual(t, nil, err, "app.Test(req)")90 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")91 body, err := ioutil.ReadAll(resp.Body)92 utils.AssertEqual(t, nil, err, "app.Test(req)")93 utils.AssertEqual(t, "root", app.getString(body))94}95func Test_Route_Match_Parser(t *testing.T) {96 app := New()97 app.Get("/foo/:ParamName", func(c *Ctx) error {98 return c.SendString(c.Params("ParamName"))99 })100 app.Get("/Foobar/*", func(c *Ctx) error {101 return c.SendString(c.Params("*"))102 })103 resp, err := app.Test(httptest.NewRequest(MethodGet, "/foo/bar", nil))104 utils.AssertEqual(t, nil, err, "app.Test(req)")105 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")106 body, err := ioutil.ReadAll(resp.Body)107 utils.AssertEqual(t, nil, err, "app.Test(req)")108 utils.AssertEqual(t, "bar", app.getString(body))109 // with star110 resp, err = app.Test(httptest.NewRequest(MethodGet, "/Foobar/test", nil))111 utils.AssertEqual(t, nil, err, "app.Test(req)")112 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")113 body, err = ioutil.ReadAll(resp.Body)114 utils.AssertEqual(t, nil, err, "app.Test(req)")115 utils.AssertEqual(t, "test", app.getString(body))116}117func Test_Route_Match_Middleware(t *testing.T) {118 app := New()119 app.Use("/foo/*", func(c *Ctx) error {120 return c.SendString(c.Params("*"))121 })122 resp, err := app.Test(httptest.NewRequest(MethodGet, "/foo/*", nil))123 utils.AssertEqual(t, nil, err, "app.Test(req)")124 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")125 body, err := ioutil.ReadAll(resp.Body)126 utils.AssertEqual(t, nil, err, "app.Test(req)")127 utils.AssertEqual(t, "*", app.getString(body))128 // with param129 resp, err = app.Test(httptest.NewRequest(MethodGet, "/foo/bar/fasel", nil))130 utils.AssertEqual(t, nil, err, "app.Test(req)")131 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")132 body, err = ioutil.ReadAll(resp.Body)133 utils.AssertEqual(t, nil, err, "app.Test(req)")134 utils.AssertEqual(t, "bar/fasel", app.getString(body))135}136func Test_Route_Match_UnescapedPath(t *testing.T) {137 app := New(Config{UnescapePath: true})138 app.Use("/créer", func(c *Ctx) error {139 return c.SendString("test")140 })141 resp, err := app.Test(httptest.NewRequest(MethodGet, "/cr%C3%A9er", nil))142 utils.AssertEqual(t, nil, err, "app.Test(req)")143 utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code")144 body, err := ioutil.ReadAll(resp.Body)145 utils.AssertEqual(t, nil, err, "app.Test(req)")146 utils.AssertEqual(t, "test", app.getString(body))147 // without special chars148 resp, err = app.Test(httptest.NewRequest(MethodGet, "/créer", nil))149 utils.AssertEqual(t, nil, err, "app.Test(req)")150 utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code")151 // check deactivated behavior152 app.config.UnescapePath = false153 resp, err = app.Test(httptest.NewRequest(MethodGet, "/cr%C3%A9er", nil))154 utils.AssertEqual(t, nil, err, "app.Test(req)")155 utils.AssertEqual(t, StatusNotFound, resp.StatusCode, "Status code")156}157func Test_Route_Match_WithEscapeChar(t *testing.T) {158 app := New()159 // static route and escaped part160 app.Get("/v1/some/resource/name\\:customVerb", func(c *Ctx) error {161 return c.SendString("static")162 })163 // group route164 group := app.Group("/v2/\\:firstVerb")165 group.Get("/\\:customVerb", func(c *Ctx) error {166 return c.SendString("group")167 })168 // route with resource param and escaped part169 app.Get("/v3/:resource/name\\:customVerb", func(c *Ctx) error {170 return c.SendString(c.Params("resource"))171 })172 // check static route173 resp, err := app.Test(httptest.NewRequest(MethodGet, "/v1/some/resource/name:customVerb", nil))174 utils.AssertEqual(t, nil, err, "app.Test(req)")175 utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code")176 body, err := ioutil.ReadAll(resp.Body)177 utils.AssertEqual(t, nil, err, "app.Test(req)")178 utils.AssertEqual(t, "static", app.getString(body))179 // check group route180 resp, err = app.Test(httptest.NewRequest(MethodGet, "/v2/:firstVerb/:customVerb", nil))181 utils.AssertEqual(t, nil, err, "app.Test(req)")182 utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code")183 body, err = ioutil.ReadAll(resp.Body)184 utils.AssertEqual(t, nil, err, "app.Test(req)")185 utils.AssertEqual(t, "group", app.getString(body))186 // check param route187 resp, err = app.Test(httptest.NewRequest(MethodGet, "/v3/awesome/name:customVerb", nil))188 utils.AssertEqual(t, nil, err, "app.Test(req)")189 utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code")190 body, err = ioutil.ReadAll(resp.Body)191 utils.AssertEqual(t, nil, err, "app.Test(req)")192 utils.AssertEqual(t, "awesome", app.getString(body))193}194func Test_Route_Match_Middleware_HasPrefix(t *testing.T) {195 app := New()196 app.Use("/foo", func(c *Ctx) error {197 return c.SendString("middleware")198 })199 resp, err := app.Test(httptest.NewRequest(MethodGet, "/foo/bar", nil))200 utils.AssertEqual(t, nil, err, "app.Test(req)")201 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")202 body, err := ioutil.ReadAll(resp.Body)203 utils.AssertEqual(t, nil, err, "app.Test(req)")204 utils.AssertEqual(t, "middleware", app.getString(body))205}206func Test_Route_Match_Middleware_Root(t *testing.T) {207 app := New()208 app.Use("/", func(c *Ctx) error {209 return c.SendString("middleware")210 })211 resp, err := app.Test(httptest.NewRequest(MethodGet, "/everything", nil))212 utils.AssertEqual(t, nil, err, "app.Test(req)")213 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")214 body, err := ioutil.ReadAll(resp.Body)215 utils.AssertEqual(t, nil, err, "app.Test(req)")216 utils.AssertEqual(t, "middleware", app.getString(body))217}218func Test_Router_Register_Missing_Handler(t *testing.T) {219 app := New()220 defer func() {221 if err := recover(); err != nil {222 utils.AssertEqual(t, "missing handler in route: /doe\n", fmt.Sprintf("%v", err))223 }224 }()225 app.register("USE", "/doe")226}227func Test_Ensure_Router_Interface_Implementation(t *testing.T) {228 var app interface{} = (*App)(nil)229 _, ok := app.(Router)230 utils.AssertEqual(t, true, ok)231 var group interface{} = (*Group)(nil)232 _, ok = group.(Router)233 utils.AssertEqual(t, true, ok)234}235func Test_Router_Handler_SetETag(t *testing.T) {236 app := New()237 app.config.ETag = true238 app.Get("/", func(c *Ctx) error {239 return c.SendString("Hello, World!")240 })241 c := &fasthttp.RequestCtx{}242 app.Handler()(c)243 utils.AssertEqual(t, `"13-1831710635"`, string(c.Response.Header.Peek(HeaderETag)))244}245func Test_Router_Handler_Catch_Error(t *testing.T) {246 app := New()247 app.config.ErrorHandler = func(ctx *Ctx, err error) error {248 return errors.New("fake error")249 }250 app.Get("/", func(c *Ctx) error {251 return ErrForbidden252 })253 c := &fasthttp.RequestCtx{}254 app.Handler()(c)255 utils.AssertEqual(t, StatusInternalServerError, c.Response.Header.StatusCode())256}257func Test_Route_Static_Root(t *testing.T) {258 dir := "./.github/testdata/fs/css"259 app := New()260 app.Static("/", dir, Static{261 Browse: true,262 })263 resp, err := app.Test(httptest.NewRequest(MethodGet, "/", nil))264 utils.AssertEqual(t, nil, err, "app.Test(req)")265 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")266 resp, err = app.Test(httptest.NewRequest(MethodGet, "/style.css", nil))267 utils.AssertEqual(t, nil, err, "app.Test(req)")268 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")269 body, err := ioutil.ReadAll(resp.Body)270 utils.AssertEqual(t, nil, err, "app.Test(req)")271 utils.AssertEqual(t, true, strings.Contains(app.getString(body), "color"))272 app = New()273 app.Static("/", dir)274 resp, err = app.Test(httptest.NewRequest(MethodGet, "/", nil))275 utils.AssertEqual(t, nil, err, "app.Test(req)")276 utils.AssertEqual(t, 404, resp.StatusCode, "Status code")277 resp, err = app.Test(httptest.NewRequest(MethodGet, "/style.css", nil))278 utils.AssertEqual(t, nil, err, "app.Test(req)")279 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")280 body, err = ioutil.ReadAll(resp.Body)281 utils.AssertEqual(t, nil, err, "app.Test(req)")282 utils.AssertEqual(t, true, strings.Contains(app.getString(body), "color"))283}284func Test_Route_Static_HasPrefix(t *testing.T) {285 dir := "./.github/testdata/fs/css"286 app := New()287 app.Static("/static", dir, Static{288 Browse: true,289 })290 resp, err := app.Test(httptest.NewRequest(MethodGet, "/static", nil))291 utils.AssertEqual(t, nil, err, "app.Test(req)")292 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")293 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static/", nil))294 utils.AssertEqual(t, nil, err, "app.Test(req)")295 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")296 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static/style.css", nil))297 utils.AssertEqual(t, nil, err, "app.Test(req)")298 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")299 body, err := ioutil.ReadAll(resp.Body)300 utils.AssertEqual(t, nil, err, "app.Test(req)")301 utils.AssertEqual(t, true, strings.Contains(app.getString(body), "color"))302 app = New()303 app.Static("/static/", dir, Static{304 Browse: true,305 })306 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static", nil))307 utils.AssertEqual(t, nil, err, "app.Test(req)")308 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")309 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static/", nil))310 utils.AssertEqual(t, nil, err, "app.Test(req)")311 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")312 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static/style.css", nil))313 utils.AssertEqual(t, nil, err, "app.Test(req)")314 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")315 body, err = ioutil.ReadAll(resp.Body)316 utils.AssertEqual(t, nil, err, "app.Test(req)")317 utils.AssertEqual(t, true, strings.Contains(app.getString(body), "color"))318 app = New()319 app.Static("/static", dir)320 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static", nil))321 utils.AssertEqual(t, nil, err, "app.Test(req)")322 utils.AssertEqual(t, 404, resp.StatusCode, "Status code")323 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static/", nil))324 utils.AssertEqual(t, nil, err, "app.Test(req)")325 utils.AssertEqual(t, 404, resp.StatusCode, "Status code")326 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static/style.css", nil))327 utils.AssertEqual(t, nil, err, "app.Test(req)")328 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")329 body, err = ioutil.ReadAll(resp.Body)330 utils.AssertEqual(t, nil, err, "app.Test(req)")331 utils.AssertEqual(t, true, strings.Contains(app.getString(body), "color"))332 app = New()333 app.Static("/static/", dir)334 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static", nil))335 utils.AssertEqual(t, nil, err, "app.Test(req)")336 utils.AssertEqual(t, 404, resp.StatusCode, "Status code")337 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static/", nil))338 utils.AssertEqual(t, nil, err, "app.Test(req)")339 utils.AssertEqual(t, 404, resp.StatusCode, "Status code")340 resp, err = app.Test(httptest.NewRequest(MethodGet, "/static/style.css", nil))341 utils.AssertEqual(t, nil, err, "app.Test(req)")342 utils.AssertEqual(t, 200, resp.StatusCode, "Status code")343 body, err = ioutil.ReadAll(resp.Body)344 utils.AssertEqual(t, nil, err, "app.Test(req)")345 utils.AssertEqual(t, true, strings.Contains(app.getString(body), "color"))346}347//////////////////////////////////////////////348///////////////// BENCHMARKS /////////////////349//////////////////////////////////////////////350func registerDummyRoutes(app *App) {351 h := func(c *Ctx) error {352 return nil353 }354 for _, r := range routesFixture.GithubAPI {355 app.Add(r.Method, r.Path, h)356 }357}358// go test -v -run=^$ -bench=Benchmark_App_MethodNotAllowed -benchmem -count=4359func Benchmark_App_MethodNotAllowed(b *testing.B) {360 app := New()361 h := func(c *Ctx) error {362 return c.SendString("Hello World!")363 }364 app.All("/this/is/a/", h)365 app.Get("/this/is/a/dummy/route/oke", h)366 appHandler := app.Handler()367 c := &fasthttp.RequestCtx{}368 c.Request.Header.SetMethod("DELETE")369 c.URI().SetPath("/this/is/a/dummy/route/oke")370 b.ResetTimer()371 for n := 0; n < b.N; n++ {372 appHandler(c)373 }374 b.StopTimer()375 utils.AssertEqual(b, 405, c.Response.StatusCode())376 utils.AssertEqual(b, "GET, HEAD", string(c.Response.Header.Peek("Allow")))377 utils.AssertEqual(b, utils.StatusMessage(StatusMethodNotAllowed), string(c.Response.Body()))378}379// go test -v ./... -run=^$ -bench=Benchmark_Router_NotFound -benchmem -count=4380func Benchmark_Router_NotFound(b *testing.B) {381 app := New()382 app.Use(func(c *Ctx) error {383 return c.Next()384 })385 registerDummyRoutes(app)386 appHandler := app.Handler()387 c := &fasthttp.RequestCtx{}388 c.Request.Header.SetMethod("DELETE")389 c.URI().SetPath("/this/route/does/not/exist")390 b.ResetTimer()391 for n := 0; n < b.N; n++ {...

Full Screen

Full Screen

cache_test.go

Source:cache_test.go Github

copy

Full Screen

...41 return c.SendString(fmt.Sprintf("%d", time.Now().UnixNano()))42 })43 resp, err := app.Test(httptest.NewRequest("GET", "/", nil))44 utils.AssertEqual(t, nil, err)45 body, err := ioutil.ReadAll(resp.Body)46 utils.AssertEqual(t, nil, err)47 // Sleep until the cache is expired48 time.Sleep(3 * time.Second)49 respCached, err := app.Test(httptest.NewRequest("GET", "/", nil))50 utils.AssertEqual(t, nil, err)51 bodyCached, err := ioutil.ReadAll(respCached.Body)52 utils.AssertEqual(t, nil, err)53 if bytes.Equal(body, bodyCached) {54 t.Errorf("Cache should have expired: %s, %s", body, bodyCached)55 }56 // Next response should be also cached57 respCachedNextRound, err := app.Test(httptest.NewRequest("GET", "/", nil))58 utils.AssertEqual(t, nil, err)59 bodyCachedNextRound, err := ioutil.ReadAll(respCachedNextRound.Body)60 utils.AssertEqual(t, nil, err)61 if !bytes.Equal(bodyCachedNextRound, bodyCached) {62 t.Errorf("Cache should not have expired: %s, %s", bodyCached, bodyCachedNextRound)63 }64}65func Test_Cache(t *testing.T) {66 t.Parallel()67 app := fiber.New()68 app.Use(New())69 app.Get("/", func(c *fiber.Ctx) error {70 now := fmt.Sprintf("%d", time.Now().UnixNano())71 return c.SendString(now)72 })73 req := httptest.NewRequest("GET", "/", nil)74 resp, err := app.Test(req)75 utils.AssertEqual(t, nil, err)76 cachedReq := httptest.NewRequest("GET", "/", nil)77 cachedResp, err := app.Test(cachedReq)78 utils.AssertEqual(t, nil, err)79 body, err := ioutil.ReadAll(resp.Body)80 utils.AssertEqual(t, nil, err)81 cachedBody, err := ioutil.ReadAll(cachedResp.Body)82 utils.AssertEqual(t, nil, err)83 utils.AssertEqual(t, cachedBody, body)84}85func Test_Cache_WithSeveralRequests(t *testing.T) {86 t.Parallel()87 app := fiber.New()88 app.Use(New(Config{89 CacheControl: true,90 Expiration: 10 * time.Second,91 }))92 app.Get("/:id", func(c *fiber.Ctx) error {93 return c.SendString(c.Params("id"))94 })95 for runs := 0; runs < 10; runs++ {96 for i := 0; i < 10; i++ {97 func(id int) {98 rsp, err := app.Test(httptest.NewRequest(http.MethodGet, fmt.Sprintf("/%d", id), nil))99 utils.AssertEqual(t, nil, err)100 defer func(Body io.ReadCloser) {101 err := Body.Close()102 utils.AssertEqual(t, nil, err)103 }(rsp.Body)104 idFromServ, err := ioutil.ReadAll(rsp.Body)105 utils.AssertEqual(t, nil, err)106 a, err := strconv.Atoi(string(idFromServ))107 utils.AssertEqual(t, nil, err)108 // SomeTimes,The id is not equal with a109 utils.AssertEqual(t, id, a)110 }(i)111 }112 }113}114func Test_Cache_Invalid_Expiration(t *testing.T) {115 t.Parallel()116 app := fiber.New()117 cache := New(Config{Expiration: 0 * time.Second})118 app.Use(cache)119 app.Get("/", func(c *fiber.Ctx) error {120 now := fmt.Sprintf("%d", time.Now().UnixNano())121 return c.SendString(now)122 })123 req := httptest.NewRequest("GET", "/", nil)124 resp, err := app.Test(req)125 utils.AssertEqual(t, nil, err)126 cachedReq := httptest.NewRequest("GET", "/", nil)127 cachedResp, err := app.Test(cachedReq)128 utils.AssertEqual(t, nil, err)129 body, err := ioutil.ReadAll(resp.Body)130 utils.AssertEqual(t, nil, err)131 cachedBody, err := ioutil.ReadAll(cachedResp.Body)132 utils.AssertEqual(t, nil, err)133 utils.AssertEqual(t, cachedBody, body)134}135func Test_Cache_Get(t *testing.T) {136 t.Parallel()137 app := fiber.New()138 app.Use(New())139 app.Post("/", func(c *fiber.Ctx) error {140 return c.SendString(c.Query("cache"))141 })142 app.Get("/get", func(c *fiber.Ctx) error {143 return c.SendString(c.Query("cache"))144 })145 resp, err := app.Test(httptest.NewRequest("POST", "/?cache=123", nil))146 utils.AssertEqual(t, nil, err)147 body, err := ioutil.ReadAll(resp.Body)148 utils.AssertEqual(t, nil, err)149 utils.AssertEqual(t, "123", string(body))150 resp, err = app.Test(httptest.NewRequest("POST", "/?cache=12345", nil))151 utils.AssertEqual(t, nil, err)152 body, err = ioutil.ReadAll(resp.Body)153 utils.AssertEqual(t, nil, err)154 utils.AssertEqual(t, "12345", string(body))155 resp, err = app.Test(httptest.NewRequest("GET", "/get?cache=123", nil))156 utils.AssertEqual(t, nil, err)157 body, err = ioutil.ReadAll(resp.Body)158 utils.AssertEqual(t, nil, err)159 utils.AssertEqual(t, "123", string(body))160 resp, err = app.Test(httptest.NewRequest("GET", "/get?cache=12345", nil))161 utils.AssertEqual(t, nil, err)162 body, err = ioutil.ReadAll(resp.Body)163 utils.AssertEqual(t, nil, err)164 utils.AssertEqual(t, "123", string(body))165}166func Test_Cache_Post(t *testing.T) {167 t.Parallel()168 app := fiber.New()169 app.Use(New(Config{170 Methods: []string{fiber.MethodPost},171 }))172 app.Post("/", func(c *fiber.Ctx) error {173 return c.SendString(c.Query("cache"))174 })175 app.Get("/get", func(c *fiber.Ctx) error {176 return c.SendString(c.Query("cache"))177 })178 resp, err := app.Test(httptest.NewRequest("POST", "/?cache=123", nil))179 utils.AssertEqual(t, nil, err)180 body, err := ioutil.ReadAll(resp.Body)181 utils.AssertEqual(t, nil, err)182 utils.AssertEqual(t, "123", string(body))183 resp, err = app.Test(httptest.NewRequest("POST", "/?cache=12345", nil))184 utils.AssertEqual(t, nil, err)185 body, err = ioutil.ReadAll(resp.Body)186 utils.AssertEqual(t, nil, err)187 utils.AssertEqual(t, "123", string(body))188 resp, err = app.Test(httptest.NewRequest("GET", "/get?cache=123", nil))189 utils.AssertEqual(t, nil, err)190 body, err = ioutil.ReadAll(resp.Body)191 utils.AssertEqual(t, nil, err)192 utils.AssertEqual(t, "123", string(body))193 resp, err = app.Test(httptest.NewRequest("GET", "/get?cache=12345", nil))194 utils.AssertEqual(t, nil, err)195 body, err = ioutil.ReadAll(resp.Body)196 utils.AssertEqual(t, nil, err)197 utils.AssertEqual(t, "12345", string(body))198}199func Test_Cache_NothingToCache(t *testing.T) {200 t.Parallel()201 app := fiber.New()202 app.Use(New(Config{Expiration: -(time.Second * 1)}))203 app.Get("/", func(c *fiber.Ctx) error {204 return c.SendString(time.Now().String())205 })206 resp, err := app.Test(httptest.NewRequest("GET", "/", nil))207 utils.AssertEqual(t, nil, err)208 body, err := ioutil.ReadAll(resp.Body)209 utils.AssertEqual(t, nil, err)210 time.Sleep(500 * time.Millisecond)211 respCached, err := app.Test(httptest.NewRequest("GET", "/", nil))212 utils.AssertEqual(t, nil, err)213 bodyCached, err := ioutil.ReadAll(respCached.Body)214 utils.AssertEqual(t, nil, err)215 if bytes.Equal(body, bodyCached) {216 t.Errorf("Cache should have expired: %s, %s", body, bodyCached)217 }218}219func Test_Cache_CustomNext(t *testing.T) {220 t.Parallel()221 app := fiber.New()222 app.Use(New(Config{223 Next: func(c *fiber.Ctx) bool {224 return c.Response().StatusCode() != fiber.StatusOK225 },226 CacheControl: true,227 }))228 app.Get("/", func(c *fiber.Ctx) error {229 return c.SendString(time.Now().String())230 })231 app.Get("/error", func(c *fiber.Ctx) error {232 return c.Status(fiber.StatusInternalServerError).SendString(time.Now().String())233 })234 resp, err := app.Test(httptest.NewRequest("GET", "/", nil))235 utils.AssertEqual(t, nil, err)236 body, err := ioutil.ReadAll(resp.Body)237 utils.AssertEqual(t, nil, err)238 respCached, err := app.Test(httptest.NewRequest("GET", "/", nil))239 utils.AssertEqual(t, nil, err)240 bodyCached, err := ioutil.ReadAll(respCached.Body)241 utils.AssertEqual(t, nil, err)242 utils.AssertEqual(t, true, bytes.Equal(body, bodyCached))243 utils.AssertEqual(t, true, respCached.Header.Get(fiber.HeaderCacheControl) != "")244 _, err = app.Test(httptest.NewRequest("GET", "/error", nil))245 utils.AssertEqual(t, nil, err)246 errRespCached, err := app.Test(httptest.NewRequest("GET", "/error", nil))247 utils.AssertEqual(t, nil, err)248 utils.AssertEqual(t, true, errRespCached.Header.Get(fiber.HeaderCacheControl) == "")249}250func Test_CustomKey(t *testing.T) {251 t.Parallel()252 app := fiber.New()253 var called bool254 app.Use(New(Config{KeyGenerator: func(c *fiber.Ctx) string {255 called = true256 return utils.CopyString(c.Path())257 }}))258 app.Get("/", func(c *fiber.Ctx) error {259 return c.SendString("hi")260 })261 req := httptest.NewRequest("GET", "/", nil)262 _, err := app.Test(req)263 utils.AssertEqual(t, nil, err)264 utils.AssertEqual(t, true, called)265}266func Test_CustomExpiration(t *testing.T) {267 t.Parallel()268 app := fiber.New()269 var called bool270 var newCacheTime int271 app.Use(New(Config{ExpirationGenerator: func(c *fiber.Ctx, cfg *Config) time.Duration {272 called = true273 newCacheTime, _ = strconv.Atoi(c.GetRespHeader("Cache-Time", "600"))274 return time.Second * time.Duration(newCacheTime)275 }}))276 app.Get("/", func(c *fiber.Ctx) error {277 c.Response().Header.Add("Cache-Time", "1")278 now := fmt.Sprintf("%d", time.Now().UnixNano())279 return c.SendString(now)280 })281 resp, err := app.Test(httptest.NewRequest("GET", "/", nil))282 utils.AssertEqual(t, nil, err)283 utils.AssertEqual(t, true, called)284 utils.AssertEqual(t, 1, newCacheTime)285 // Sleep until the cache is expired286 time.Sleep(1 * time.Second)287 cachedResp, err := app.Test(httptest.NewRequest("GET", "/", nil))288 utils.AssertEqual(t, nil, err)289 body, err := ioutil.ReadAll(resp.Body)290 utils.AssertEqual(t, nil, err)291 cachedBody, err := ioutil.ReadAll(cachedResp.Body)292 utils.AssertEqual(t, nil, err)293 if bytes.Equal(body, cachedBody) {294 t.Errorf("Cache should have expired: %s, %s", body, cachedBody)295 }296 // Next response should be cached297 cachedRespNextRound, err := app.Test(httptest.NewRequest("GET", "/", nil))298 utils.AssertEqual(t, nil, err)299 cachedBodyNextRound, err := ioutil.ReadAll(cachedRespNextRound.Body)300 utils.AssertEqual(t, nil, err)301 if !bytes.Equal(cachedBodyNextRound, cachedBody) {302 t.Errorf("Cache should not have expired: %s, %s", cachedBodyNextRound, cachedBody)303 }304}305func Test_AdditionalE2EResponseHeaders(t *testing.T) {306 t.Parallel()307 app := fiber.New()308 app.Use(New(Config{309 StoreResponseHeaders: true,310 }))311 app.Get("/", func(c *fiber.Ctx) error {312 c.Response().Header.Add("X-Foobar", "foobar")313 return c.SendString("hi")314 })315 req := httptest.NewRequest("GET", "/", nil)316 resp, err := app.Test(req)317 utils.AssertEqual(t, nil, err)318 utils.AssertEqual(t, "foobar", resp.Header.Get("X-Foobar"))319 req = httptest.NewRequest("GET", "/", nil)320 resp, err = app.Test(req)321 utils.AssertEqual(t, nil, err)322 utils.AssertEqual(t, "foobar", resp.Header.Get("X-Foobar"))323}324func Test_CacheHeader(t *testing.T) {325 t.Parallel()326 app := fiber.New()327 app.Use(New(Config{328 Expiration: 10 * time.Second,329 Next: func(c *fiber.Ctx) bool {330 return c.Response().StatusCode() != fiber.StatusOK331 },332 }))333 app.Get("/", func(c *fiber.Ctx) error {334 return c.SendString("Hello, World!")335 })336 app.Post("/", func(c *fiber.Ctx) error {337 return c.SendString(c.Query("cache"))338 })339 app.Get("/error", func(c *fiber.Ctx) error {340 return c.Status(fiber.StatusInternalServerError).SendString(time.Now().String())341 })342 resp, err := app.Test(httptest.NewRequest("GET", "/", nil))343 utils.AssertEqual(t, nil, err)344 utils.AssertEqual(t, cacheMiss, resp.Header.Get("X-Cache"))345 resp, err = app.Test(httptest.NewRequest("GET", "/", nil))346 utils.AssertEqual(t, nil, err)347 utils.AssertEqual(t, cacheHit, resp.Header.Get("X-Cache"))348 resp, err = app.Test(httptest.NewRequest("POST", "/?cache=12345", nil))349 utils.AssertEqual(t, nil, err)350 utils.AssertEqual(t, cacheUnreachable, resp.Header.Get("X-Cache"))351 errRespCached, err := app.Test(httptest.NewRequest("GET", "/error", nil))352 utils.AssertEqual(t, nil, err)353 utils.AssertEqual(t, cacheUnreachable, errRespCached.Header.Get("X-Cache"))354}355func Test_Cache_WithHead(t *testing.T) {356 t.Parallel()357 app := fiber.New()358 app.Use(New())359 app.Get("/", func(c *fiber.Ctx) error {360 now := fmt.Sprintf("%d", time.Now().UnixNano())361 return c.SendString(now)362 })363 req := httptest.NewRequest("HEAD", "/", nil)364 resp, err := app.Test(req)365 utils.AssertEqual(t, nil, err)366 utils.AssertEqual(t, cacheMiss, resp.Header.Get("X-Cache"))367 cachedReq := httptest.NewRequest("HEAD", "/", nil)368 cachedResp, err := app.Test(cachedReq)369 utils.AssertEqual(t, nil, err)370 utils.AssertEqual(t, cacheHit, cachedResp.Header.Get("X-Cache"))371 body, err := ioutil.ReadAll(resp.Body)372 utils.AssertEqual(t, nil, err)373 cachedBody, err := ioutil.ReadAll(cachedResp.Body)374 utils.AssertEqual(t, nil, err)375 utils.AssertEqual(t, cachedBody, body)376}377func Test_Cache_WithHeadThenGet(t *testing.T) {378 t.Parallel()379 app := fiber.New()380 app.Use(New())381 app.Get("/", func(c *fiber.Ctx) error {382 return c.SendString(c.Query("cache"))383 })384 headResp, err := app.Test(httptest.NewRequest("HEAD", "/?cache=123", nil))385 utils.AssertEqual(t, nil, err)386 headBody, err := ioutil.ReadAll(headResp.Body)387 utils.AssertEqual(t, nil, err)388 utils.AssertEqual(t, "", string(headBody))389 utils.AssertEqual(t, cacheMiss, headResp.Header.Get("X-Cache"))390 headResp, err = app.Test(httptest.NewRequest("HEAD", "/?cache=123", nil))391 utils.AssertEqual(t, nil, err)392 headBody, err = ioutil.ReadAll(headResp.Body)393 utils.AssertEqual(t, nil, err)394 utils.AssertEqual(t, "", string(headBody))395 utils.AssertEqual(t, cacheHit, headResp.Header.Get("X-Cache"))396 getResp, err := app.Test(httptest.NewRequest("GET", "/?cache=123", nil))397 utils.AssertEqual(t, nil, err)398 getBody, err := ioutil.ReadAll(getResp.Body)399 utils.AssertEqual(t, nil, err)400 utils.AssertEqual(t, "123", string(getBody))401 utils.AssertEqual(t, cacheMiss, getResp.Header.Get("X-Cache"))402 getResp, err = app.Test(httptest.NewRequest("GET", "/?cache=123", nil))403 utils.AssertEqual(t, nil, err)404 getBody, err = ioutil.ReadAll(getResp.Body)405 utils.AssertEqual(t, nil, err)406 utils.AssertEqual(t, "123", string(getBody))407 utils.AssertEqual(t, cacheHit, getResp.Header.Get("X-Cache"))408}409func Test_CustomCacheHeader(t *testing.T) {410 t.Parallel()411 app := fiber.New()412 app.Use(New(Config{413 CacheHeader: "Cache-Status",414 }))415 app.Get("/", func(c *fiber.Ctx) error {416 return c.SendString("Hello, World!")417 })418 resp, err := app.Test(httptest.NewRequest("GET", "/", nil))419 utils.AssertEqual(t, nil, err)420 utils.AssertEqual(t, cacheMiss, resp.Header.Get("Cache-Status"))421}422// Because time points are updated once every X milliseconds, entries in tests can often have423// equal expiration times and thus be in an random order. This closure hands out increasing424// time intervals to maintain strong ascending order of expiration425func stableAscendingExpiration() func(c1 *fiber.Ctx, c2 *Config) time.Duration {426 i := 0427 return func(c1 *fiber.Ctx, c2 *Config) time.Duration {428 i += 1429 return time.Hour * time.Duration(i)430 }431}432func Test_Cache_MaxBytesOrder(t *testing.T) {433 t.Parallel()434 app := fiber.New()435 app.Use(New(Config{436 MaxBytes: 2,437 ExpirationGenerator: stableAscendingExpiration(),438 }))439 app.Get("/*", func(c *fiber.Ctx) error {440 return c.SendString("1")441 })442 cases := [][]string{443 // Insert a, b into cache of size 2 bytes (responses are 1 byte)444 {"/a", cacheMiss},445 {"/b", cacheMiss},446 {"/a", cacheHit},447 {"/b", cacheHit},448 // Add c -> a evicted449 {"/c", cacheMiss},450 {"/b", cacheHit},451 // Add a again -> b evicted452 {"/a", cacheMiss},453 {"/c", cacheHit},454 // Add b -> c evicted455 {"/b", cacheMiss},456 {"/c", cacheMiss},457 }458 for idx, tcase := range cases {459 rsp, err := app.Test(httptest.NewRequest("GET", tcase[0], nil))460 utils.AssertEqual(t, nil, err)461 utils.AssertEqual(t, tcase[1], rsp.Header.Get("X-Cache"), fmt.Sprintf("Case %v", idx))462 }463}464func Test_Cache_MaxBytesSizes(t *testing.T) {465 t.Parallel()466 app := fiber.New()467 app.Use(New(Config{468 MaxBytes: 7,469 ExpirationGenerator: stableAscendingExpiration(),470 }))471 app.Get("/*", func(c *fiber.Ctx) error {472 path := c.Context().URI().LastPathSegment()473 size, _ := strconv.Atoi(string(path))474 return c.Send(make([]byte, size))475 })476 cases := [][]string{477 {"/1", cacheMiss},478 {"/2", cacheMiss},479 {"/3", cacheMiss},480 {"/4", cacheMiss}, // 1+2+3+4 > 7 => 1,2 are evicted now481 {"/3", cacheHit},482 {"/1", cacheMiss},483 {"/2", cacheMiss},484 {"/8", cacheUnreachable}, // too big to cache -> unreachable485 }486 for idx, tcase := range cases {487 rsp, err := app.Test(httptest.NewRequest("GET", tcase[0], nil))488 utils.AssertEqual(t, nil, err)489 utils.AssertEqual(t, tcase[1], rsp.Header.Get("X-Cache"), fmt.Sprintf("Case %v", idx))490 }491}492// go test -v -run=^$ -bench=Benchmark_Cache -benchmem -count=4493func Benchmark_Cache(b *testing.B) {494 app := fiber.New()495 app.Use(New())496 app.Get("/demo", func(c *fiber.Ctx) error {497 data, _ := ioutil.ReadFile("../../.github/README.md")498 return c.Status(fiber.StatusTeapot).Send(data)499 })500 h := app.Handler()501 fctx := &fasthttp.RequestCtx{}502 fctx.Request.Header.SetMethod("GET")503 fctx.Request.SetRequestURI("/demo")504 b.ReportAllocs()505 b.ResetTimer()506 for n := 0; n < b.N; n++ {507 h(fctx)508 }509 utils.AssertEqual(b, fiber.StatusTeapot, fctx.Response.Header.StatusCode())510 utils.AssertEqual(b, true, len(fctx.Response.Body()) > 30000)511}512// go test -v -run=^$ -bench=Benchmark_Cache_Storage -benchmem -count=4513func Benchmark_Cache_Storage(b *testing.B) {514 app := fiber.New()515 app.Use(New(Config{516 Storage: memory.New(),517 }))518 app.Get("/demo", func(c *fiber.Ctx) error {519 data, _ := ioutil.ReadFile("../../.github/README.md")520 return c.Status(fiber.StatusTeapot).Send(data)521 })522 h := app.Handler()523 fctx := &fasthttp.RequestCtx{}524 fctx.Request.Header.SetMethod("GET")525 fctx.Request.SetRequestURI("/demo")526 b.ReportAllocs()527 b.ResetTimer()528 for n := 0; n < b.N; n++ {529 h(fctx)530 }531 utils.AssertEqual(b, fiber.StatusTeapot, fctx.Response.Header.StatusCode())532 utils.AssertEqual(b, true, len(fctx.Response.Body()) > 30000)533}534func Benchmark_Cache_AdditionalHeaders(b *testing.B) {535 app := fiber.New()536 app.Use(New(Config{537 StoreResponseHeaders: true,538 }))539 app.Get("/demo", func(c *fiber.Ctx) error {540 c.Response().Header.Add("X-Foobar", "foobar")541 return c.SendStatus(418)542 })543 h := app.Handler()544 fctx := &fasthttp.RequestCtx{}545 fctx.Request.Header.SetMethod("GET")546 fctx.Request.SetRequestURI("/demo")547 b.ReportAllocs()548 b.ResetTimer()549 for n := 0; n < b.N; n++ {550 h(fctx)551 }552 utils.AssertEqual(b, fiber.StatusTeapot, fctx.Response.Header.StatusCode())553 utils.AssertEqual(b, []byte("foobar"), fctx.Response.Header.Peek("X-Foobar"))554}555func Benchmark_Cache_MaxSize(b *testing.B) {556 // The benchmark is run with three different MaxSize parameters557 // 1) 0: Tracking is disabled = no overhead558 // 2) MaxInt32: Enough to store all entries = no removals559 // 3) 100: Small size = constant insertions and removals560 cases := []uint{0, math.MaxUint32, 100}561 names := []string{"Disabled", "Unlim", "LowBounded"}562 for i, size := range cases {563 b.Run(names[i], func(b *testing.B) {564 app := fiber.New()565 app.Use(New(Config{MaxBytes: size}))566 app.Get("/*", func(c *fiber.Ctx) error {567 return c.Status(fiber.StatusTeapot).SendString("1")568 })569 h := app.Handler()570 fctx := &fasthttp.RequestCtx{}571 fctx.Request.Header.SetMethod("GET")572 b.ReportAllocs()573 b.ResetTimer()574 for n := 0; n < b.N; n++ {575 fctx.Request.SetRequestURI(fmt.Sprintf("/%v", n))576 h(fctx)577 }578 utils.AssertEqual(b, fiber.StatusTeapot, fctx.Response.Header.StatusCode())579 })580 }581}...

Full Screen

Full Screen

gear_controller.go

Source:gear_controller.go Github

copy

Full Screen

...6 usecase "github.com/betorvs/playbypost-dnd/usecase/rule"7 "github.com/betorvs/playbypost-dnd/utils"8 "github.com/labstack/echo/v4"9)10// GetAllWeapons controller11func GetAllWeapons(c echo.Context) (err error) {12 queryParams := c.QueryParams()13 allowedParams := []string{"name", "kind", "type", "damage_type"}14 for paramName := range queryParams {15 if !utils.StringInSlice(paramName, allowedParams) {16 errString := "Allowed query params: name, kind, damage_type"17 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))18 }19 }20 result := usecase.GetAllWeapons(queryParams)21 return c.JSON(http.StatusOK, result)22}23// GetAllArmors controller24func GetAllArmors(c echo.Context) (err error) {25 queryParams := c.QueryParams()26 allowedParams := []string{"name", "kind"}27 for paramName := range queryParams {28 if !utils.StringInSlice(paramName, allowedParams) {29 errString := "Allowed query params: name, kind"30 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))31 }32 }33 result := usecase.GetAllArmor(queryParams)34 return c.JSON(http.StatusOK, result)35}36// GetAllGear controller37func GetAllGear(c echo.Context) (err error) {38 queryParams := c.QueryParams()39 allowedParams := []string{"name", "kind"}40 for paramName := range queryParams {41 if !utils.StringInSlice(paramName, allowedParams) {42 errString := "Allowed query params: name, kind"43 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))44 }45 }46 result := usecase.GetAllGears(queryParams)47 return c.JSON(http.StatusOK, result)48}49// GetAllPacks controller50func GetAllPacks(c echo.Context) (err error) {51 queryParams := c.QueryParams()52 allowedParams := []string{"name"}53 for paramName := range queryParams {54 if !utils.StringInSlice(paramName, allowedParams) {55 errString := "Allowed query params: name"56 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))57 }58 }59 result := usecase.GetAllPacks(queryParams)60 return c.JSON(http.StatusOK, result)61}62// GetAllTools controller63func GetAllTools(c echo.Context) (err error) {64 queryParams := c.QueryParams()65 allowedParams := []string{"name", "kind"}66 for paramName := range queryParams {67 if !utils.StringInSlice(paramName, allowedParams) {68 errString := "Allowed query params: name, kind"69 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))70 }71 }72 result := usecase.GetAllTools(queryParams)73 return c.JSON(http.StatusOK, result)74}75// GetAllMounts controller76func GetAllMounts(c echo.Context) (err error) {77 queryParams := c.QueryParams()78 allowedParams := []string{"name"}79 for paramName := range queryParams {80 if !utils.StringInSlice(paramName, allowedParams) {81 errString := "Allowed query params: name"82 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))83 }84 }85 result := usecase.GetAllMounts(queryParams)86 return c.JSON(http.StatusOK, result)87}88// CalcShop controller89func CalcShop(c echo.Context) (err error) {90 list := new(rule.SimpleList)91 if err = c.Bind(list); err != nil {92 errString := "Cannot parse json"93 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))94 }95 result := usecase.CalcShoppingCart(list)96 return c.JSON(http.StatusOK, result)97}98// RandomTreasure controller99func RandomTreasure(c echo.Context) (err error) {100 initialLevel := c.Param("level")101 level, err := strconv.Atoi(initialLevel)102 if err != nil {103 errString := "Value not allowed. Use valid int."104 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))105 }106 if level < 0 || level > 30 {107 errString := "Value not allowed. Use valid int: 0 to 30"108 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))109 }110 result, err := usecase.CalcRandomTreasureByChallengeLevel(level, true)111 if err != nil {112 errString := "Cannot calculate"113 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))114 }115 return c.JSON(http.StatusOK, result)116}117// FastTreasure controller118func FastTreasure(c echo.Context) (err error) {119 initialLevel := c.Param("level")120 level, err := strconv.Atoi(initialLevel)121 if err != nil {122 errString := "Value not allowed. Use valid int."123 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))124 }125 if level < 0 || level > 30 {126 errString := "Value not allowed. Use valid int: 0 to 30"127 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))128 }129 result, err := usecase.CalcRandomTreasureByChallengeLevel(level, false)130 if err != nil {131 errString := "Cannot calculate"132 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))133 }134 return c.JSON(http.StatusOK, result)135}136// RandomTreasureHoard controller137func RandomTreasureHoard(c echo.Context) (err error) {138 initialLevel := c.Param("level")139 level, err := strconv.Atoi(initialLevel)140 if err != nil {141 errString := "Value not allowed. Use valid int."142 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))143 }144 if level < 0 || level > 30 {145 errString := "Value not allowed. Use valid int: 0 to 30"146 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))147 }148 result := usecase.CalcHoardPercentageByLevel(level)149 return c.JSON(http.StatusOK, result)150}151// GetAllServices controller152func GetAllServices(c echo.Context) (err error) {153 queryParams := c.QueryParams()154 allowedParams := []string{"name", "source"}155 for paramName := range queryParams {156 if !utils.StringInSlice(paramName, allowedParams) {157 errString := "Allowed query params: name, source"158 return c.JSON(http.StatusBadRequest, utils.FormatMessage(errString))159 }160 }161 result := usecase.GetAllServices(queryParams)162 return c.JSON(http.StatusOK, result)163}...

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(utils.All(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))4}5import (6func main() {7 fmt.Println(utils.Any(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))8}

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import "utils"2func main() {3 utils.All()4}5import "utils"6func main() {7 utils.All()8}9import "utils"10func main() {11 utils.All()12}13import "utils"14func main() {15 utils.All()16}17import "utils"18func main() {19 utils.All()20}21import "utils"22func main() {23 utils.All()24}25import "utils"26func main() {27 utils.All()28}29import "utils"30func main() {31 utils.All()32}33import "utils"34func main() {35 utils.All()36}37import "utils"38func main() {39 utils.All()40}41import "utils"42func main() {43 utils.All()44}45import "utils"46func main() {47 utils.All()48}49import "utils"50func main() {51 utils.All()52}53import "utils"54func main() {55 utils.All()56}57import "utils"58func main() {59 utils.All()60}

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import "utils"2func main() {3 utils.All()4}5import "fmt"6func All() {7 fmt.Println("All")8}9import "testing"10func TestAll(t *testing.T) {11 All()12}13import "testing"14func TestAll(t *testing.T) {15 All()16}17import "testing"18func TestAll(t *testing.T) {19 All()20}21import "testing"22func TestAll(t *testing.T) {23 All()24}25import "testing"26func TestAll(t *testing.T) {27 All()28}29import "testing"30func TestAll(t *testing.T) {31 All()32}33import "testing"34func TestAll(t *testing.T) {35 All()36}37import "testing"38func TestAll(t *testing.T) {39 All()40}41import "testing"42func TestAll(t *testing.T) {43 All()44}45import "testing"46func TestAll(t *testing.T) {47 All()48}49import "testing"50func TestAll(t *testing.T) {51 All()52}53import "testing"54func TestAll(t

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(utils.All(1, 2, 3, 4, 5))4}5func All(vs ...int) int {6 for _, v := range vs {7 }8}

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(utils.All(1, 2, 3, 4))4}5func All(numbers ...int) bool {6 for _, v := range numbers {7 if v == 0 {8 }9 }10}

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 fmt.Println(utils.All(1, 2, 3, 4, 5))5}6This is how you can create a package in Go. You can also create a package in a single file. You can also import a package in Go. You

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import "utils";2utils.All();3import "utils";4utils.All();5package utils;6func All() {7 println("utils.All");8}9import "utils";10utils.All();11We can also import a package with an alias. For example, we have created a package named utils. We can import it with an alias as below:12import u "utils";13u.All();14We can also import a package with the dot operator. For example, we have created a package named utils. We can import it with the dot operator as below:15import . "utils";16All();17We can also import multiple packages in a single line. For example, we have created two packages named utils and utils2. We can import them in a single line as below:18import u "utils", u2 "utils2";19u.All();20u2.All();21We can also import multiple packages with the dot operator in a single line. For example, we have created two packages named utils and utils2. We can import them with the

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