tests
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package video
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPatterns(t *testing.T) {
|
||||
got := Patterns()
|
||||
if len(got) == 0 {
|
||||
t.Fatal("Patterns returned no video patterns")
|
||||
}
|
||||
|
||||
seen := make(map[string]struct{}, len(got))
|
||||
for i, pattern := range got {
|
||||
if pattern.Name == "" {
|
||||
t.Fatalf("pattern %d has an empty name", i)
|
||||
}
|
||||
if pattern.Description == "" {
|
||||
t.Fatalf("pattern %q has an empty description", pattern.Name)
|
||||
}
|
||||
if !HasPattern(pattern.Name) {
|
||||
t.Fatalf("Patterns returned %q, but HasPattern rejected it", pattern.Name)
|
||||
}
|
||||
if _, exists := seen[pattern.Name]; exists {
|
||||
t.Fatalf("duplicate pattern name %q", pattern.Name)
|
||||
}
|
||||
seen[pattern.Name] = struct{}{}
|
||||
if i > 0 && got[i-1].Name >= pattern.Name {
|
||||
t.Fatalf("patterns are not sorted: %q appears before %q", got[i-1].Name, pattern.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasPatternRejectsUnknownName(t *testing.T) {
|
||||
if HasPattern("not-a-pattern") {
|
||||
t.Fatal("HasPattern accepted an unknown pattern")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPatternRegistryKeysMatchNames(t *testing.T) {
|
||||
for name, pattern := range patterns {
|
||||
if pattern.Name != name {
|
||||
t.Errorf("pattern map key %q does not match pattern name %q", name, pattern.Name)
|
||||
}
|
||||
if pattern.kernelPath == "" {
|
||||
t.Errorf("pattern %q has an empty kernel path", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user