| 1402 | } |
| 1403 | |
| 1404 | func Test_App_GetBytes(t *testing.T) { |
| 1405 | t.Parallel() |
| 1406 | |
| 1407 | b := []byte("fiber") |
| 1408 | appMutable := New() |
| 1409 | same := appMutable.GetBytes(b) |
| 1410 | if unsafe.SliceData(same) != unsafe.SliceData(b) { |
| 1411 | t.Error("expected original slice when immutable is disabled") |
| 1412 | } |
| 1413 | |
| 1414 | alias := make([]byte, 10) |
| 1415 | copy(alias, b) |
| 1416 | sub := alias[:5] |
| 1417 | appImmutable := New(Config{Immutable: true}) |
| 1418 | copied := appImmutable.GetBytes(sub) |
| 1419 | if unsafe.SliceData(copied) == unsafe.SliceData(sub) { |
| 1420 | t.Error("expected a copy for aliased slice when immutable is enabled") |
| 1421 | } |
| 1422 | |
| 1423 | full := make([]byte, 5) |
| 1424 | copy(full, b) |
| 1425 | detached := appImmutable.GetBytes(full) |
| 1426 | if unsafe.SliceData(detached) == unsafe.SliceData(full) { |
| 1427 | t.Error("expected a copy even when cap==len") |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | func Test_App_Shutdown(t *testing.T) { |
| 1432 | t.Parallel() |