|
1 | | -// Copyright 2021 The Gitea Authors. All rights reserved. |
| 1 | +// Copyright 2023 The Gitea Authors. All rights reserved. |
2 | 2 | // SPDX-License-Identifier: MIT |
3 | 3 |
|
4 | 4 | package install |
5 | 5 |
|
6 | 6 | import ( |
7 | | - "context" |
| 7 | + "net/http/httptest" |
| 8 | + "path/filepath" |
8 | 9 | "testing" |
9 | 10 |
|
| 11 | + "code.gitea.io/gitea/models/unittest" |
| 12 | + |
10 | 13 | "github.com/stretchr/testify/assert" |
11 | 14 | ) |
12 | 15 |
|
13 | 16 | func TestRoutes(t *testing.T) { |
14 | | - // TODO: this test seems not really testing the handlers |
15 | | - ctx, cancel := context.WithCancel(context.Background()) |
16 | | - defer cancel() |
17 | | - base := Routes(ctx) |
18 | | - assert.NotNil(t, base) |
19 | | - r := base.R.Routes()[1] |
20 | | - routes := r.SubRoutes.Routes()[0] |
21 | | - assert.EqualValues(t, "/", routes.Pattern) |
22 | | - assert.Nil(t, routes.SubRoutes) |
23 | | - assert.Len(t, routes.Handlers, 2) |
| 17 | + r := Routes() |
| 18 | + assert.NotNil(t, r) |
| 19 | + |
| 20 | + w := httptest.NewRecorder() |
| 21 | + req := httptest.NewRequest("GET", "/", nil) |
| 22 | + r.ServeHTTP(w, req) |
| 23 | + assert.EqualValues(t, 200, w.Code) |
| 24 | + assert.Contains(t, w.Body.String(), `class="page-content install"`) |
| 25 | + |
| 26 | + w = httptest.NewRecorder() |
| 27 | + req = httptest.NewRequest("GET", "/no-such", nil) |
| 28 | + r.ServeHTTP(w, req) |
| 29 | + assert.EqualValues(t, 404, w.Code) |
| 30 | + |
| 31 | + w = httptest.NewRecorder() |
| 32 | + req = httptest.NewRequest("GET", "/assets/img/gitea.svg", nil) |
| 33 | + r.ServeHTTP(w, req) |
| 34 | + assert.EqualValues(t, 200, w.Code) |
| 35 | +} |
| 36 | + |
| 37 | +func TestMain(m *testing.M) { |
| 38 | + unittest.MainTest(m, &unittest.TestOptions{ |
| 39 | + GiteaRootPath: filepath.Join("..", ".."), |
| 40 | + }) |
24 | 41 | } |
0 commit comments