Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Blame · server/web/status_test.go

Line attribution on main · 64 line(s)

4506a4d3
Keenan Nemetz
13d ago
1 package web
2
3 import (
4 "bytes"
5 "crypto/sha256"
6 "encoding/hex"
7 "reflect"
8 "strings"
9 "testing"
10
d37d301f
Keenan Nemetz
15h ago
11 "rodent.software/vole/core/lfs"
12 "rodent.software/vole/forge/config"
4506a4d3
Keenan Nemetz
13d ago
13 )
14
15 // TestStatusConfigListsEverySetting keeps the read-only configuration view
16 // honest as the config grows: a new TOML field must be presented somewhere on
17 // the page, not silently omitted.
18 func TestStatusConfigListsEverySetting(t *testing.T) {
19 t.Parallel()
20 v := (&Web{Cfg: &config.Config{}}).statusConfig()
21 if v == nil {
22 t.Fatal("statusConfig returned nil")
23 }
24 listed := map[string]bool{}
25 for _, group := range v.Groups {
26 for _, setting := range group.Settings {
27 listed[setting.Key] = true
28 }
29 }
30
31 typ := reflect.TypeOf(config.Config{})
32 for i := 0; i < typ.NumField(); i++ {
33 field := typ.Field(i)
34 key := strings.Split(field.Tag.Get("toml"), ",")[0]
35 if key == "" || key == "-" {
36 continue
37 }
38 if !listed[key] {
39 t.Errorf("status configuration does not list %s", key)
40 }
41 }
42 }
43
44 func TestLFSUsageReadsTheObjectPool(t *testing.T) {
45 t.Parallel()
46 store := lfs.New(t.TempDir(), 0)
47 data := []byte("a build artifact")
48 sum := sha256.Sum256(data)
49 oid := hex.EncodeToString(sum[:])
50 if _, _, err := store.Put("demo", oid, int64(len(data)), bytes.NewReader(data)); err != nil {
51 t.Fatal(err)
52 }
53
54 view := (&Web{LFS: store}).lfsUsage()
55 if view.Disabled || view.Err != "" {
56 t.Fatalf("LFS usage = %+v", view)
57 }
58 if view.Total.Objects != 1 || view.Total.Bytes != int64(len(data)) {
59 t.Fatalf("total = %+v", view.Total)
60 }
5ece70a5
Keenan Nemetz
10d ago
61 if view.Other.Objects != 1 || view.Artifacts.Objects != 0 {
4506a4d3
Keenan Nemetz
13d ago
62 t.Fatalf("classification = %+v", view)
63 }
64 }