a73x

internal/shape/classify_test.go

Ref:   Size: 1.6 KiB   History

package shape

import "testing"

func TestSynopsisTakesFirstSentence(t *testing.T) {
	cases := map[string]string{
		"":                            "",
		"Package reconcile does X.":   "Package reconcile does X.",
		"First sentence. Second one.": "First sentence.",
		"Two\nlines collapsed.":       "Two lines collapsed.",
		"Para one.\n\nPara two.":      "Para one.",
		// A run-on synopsis: cut at the first ". " boundary, dropping the tail.
		"Brings up the stack until Ctrl-C. It is the companion.": "Brings up the stack until Ctrl-C.",
	}
	for in, want := range cases {
		if got := synopsis(in); got != want {
			t.Errorf("synopsis(%q) = %q, want %q", in, got, want)
		}
	}
}

func TestClassifyAssignsPlaneByPrefix(t *testing.T) {
	cases := map[string]Plane{
		"internal/server/api":      PlaneControl,
		"internal/server/store":    PlaneControl,
		"internal/agent/reconcile": PlaneData,
		"internal/agent/exec":      PlaneData,
		"internal/pb":              PlaneWire,
		"internal/transport":       PlaneWire,
		"internal/guest":           PlaneWire,
		"internal/names":           PlaneWire,
		"internal/random":          PlaneWire,
		"cmd/eitri-server":         PlaneBinaries,
		"cmd/eitri-shape":          PlaneBinaries,
		"internal/arch":            PlaneTooling,
		"internal/covsnap":         PlaneTooling,
		"internal/gateclient":      PlaneTooling,
		"internal/shape":           PlaneTooling,
		"internal/smoke":           PlaneTooling,
		"internal/somethingnew":    PlaneUnclassified,
		"pkg/whatever":             PlaneUnclassified,
	}
	for rel, want := range cases {
		if got := classify(rel); got != want {
			t.Errorf("classify(%q) = %q, want %q", rel, got, want)
		}
	}
}