vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
Expand the admin status page into an operational dashboard
4506a4d3d279556435fdd414265e7499c3dada16 · Keenan Nemetz · 14d ago · parent 2e024cc9
server/web/status_test.go +64
| @@ -0,0 +1,64 @@ | |||
| 1 | package web | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bytes" | ||
| 5 | "crypto/sha256" | ||
| 6 | "encoding/hex" | ||
| 7 | "reflect" | ||
| 8 | "strings" | ||
| 9 | "testing" | ||
| 10 | |||
| 11 | "github.com/rodent-software/vole/core/lfs" | ||
| 12 | "github.com/rodent-software/vole/forge/config" | ||
| 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 | } | ||
| 61 | if view.Other.Objects != 1 || view.Logs.Objects != 0 || view.Artifacts.Objects != 0 { | ||
| 62 | t.Fatalf("classification = %+v", view) | ||
| 63 | } | ||
| 64 | } | ||