Files
George Karr a25ae3ddfc Adding initial tool - dibble the tapir for seeding data (#46122)
## Overview

`dibble` is a one-stop CLI for seeding a Fleet server with test data —
users, teams, policies, reports, labels, scripts, MDM profiles,
software, secrets, CAs, and vulns — replacing ~8 ad-hoc seeding tools
with a single binary.

It makes it easy to:
- **Spin up a populated dev/test server in one command** — `dibble all`
plants everything with sensible, idempotent defaults.
- **Skip the flag-memorization** — running `dibble` with no args
launches an interactive wizard that prompts for Fleet URL, API token,
theme, and which entities to seed, and offers to save the config to
`~/.dibble.yaml`.
- **Seed individual entity types** — `dibble users`, `dibble teams`,
`dibble policies`, etc., when you only need one slice.
- **Get themed, recognizable test data** — pick a theme (hitchhikers,
tng, lotr, ghibli, parksrec, …) so seeded names are easy to eyeball in
the UI.

Hosts are intentionally out of scope — `cmd/osquery-perf` still owns
that. `dibble hosts` is a thin convenience wrapper that picks a fleet,
fetches its enroll secret, and prints/runs the osquery-perf invocation
for you.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Dibble: a CLI tool to seed realistic test data, including an
interactive wizard and subcommands for
teams/users/software/policies/scripts/reports/profiles/labels/activities/enroll-secrets/hosts/vulns,
plus theme-driven “cas” and “ping”.
* Theme system: multiple curated themes to generate consistent seeded
identities, policies, software, labels, and scripts.
* **Chores**
* Ignored the built dibble binary and added a Makefile build target to
compile the dibble tool.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-17 11:07:05 -05:00

61 lines
1.4 KiB
Go

package themes
import (
"strings"
"testing"
)
func TestAllThemesRegistered(t *testing.T) {
want := []string{
"hitchhikers", "goodplace", "parksrec", "tng", "lotr",
"dbz", "robin_williams", "ghibli", "cosmere", "sailor_moon",
}
for _, name := range want {
if _, err := Get(name); err != nil {
t.Errorf("theme %q not registered: %v", name, err)
}
}
}
func TestMixIsNonEmpty(t *testing.T) {
m := Mix()
if len(m.Users) == 0 || len(m.Teams) == 0 || len(m.Policies) == 0 {
t.Fatalf("mix theme came back empty: %+v", m)
}
}
func TestEmailWrapsWithoutCollision(t *testing.T) {
th, err := Get("hitchhikers")
if err != nil {
t.Fatal(err)
}
seen := map[string]bool{}
n := len(th.Users) * 3
for i := 0; i < n; i++ {
e := Email(th, i)
if seen[e] {
t.Errorf("duplicate email at i=%d: %s", i, e)
}
seen[e] = true
if !strings.Contains(e, "@") {
t.Errorf("not an email: %s", e)
}
}
}
func TestPickReturnsKindAwareDefault(t *testing.T) {
th, _ := Get("hitchhikers")
if got := Pick(th, "policy", 0); got.Name == "" {
t.Fatalf("Pick policy returned empty name")
}
if got := Pick(th, "nonsense-kind", 0); !strings.HasPrefix(got.Name, "item-") {
t.Errorf("expected fallback name for unknown kind, got %q", got.Name)
}
}
func TestGetUnknownErrors(t *testing.T) {
if _, err := Get("notreal"); err == nil {
t.Error("expected error for unknown theme")
}
}