Initial commit
This commit is contained in:
commit
53626dd36a
29 changed files with 3940 additions and 0 deletions
73
checker/provider_test.go
Normal file
73
checker/provider_test.go
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package checker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
func TestProvider_DelegatesCollect(t *testing.T) {
|
||||
called := false
|
||||
want := errors.New("sentinel")
|
||||
p := Provider(func(ctx context.Context, opts sdk.CheckerOptions) (any, error) {
|
||||
called = true
|
||||
return "value", want
|
||||
})
|
||||
got, err := p.Collect(context.Background(), sdk.CheckerOptions{})
|
||||
if !called {
|
||||
t.Fatal("collect fn not called")
|
||||
}
|
||||
if got != "value" || err != want {
|
||||
t.Errorf("unexpected return: %v, %v", got, err)
|
||||
}
|
||||
if p.Key() != ObservationKeyDNSViz {
|
||||
t.Errorf("Key=%q, want %q", p.Key(), ObservationKeyDNSViz)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefinition(t *testing.T) {
|
||||
p := Provider(func(_ context.Context, _ sdk.CheckerOptions) (any, error) { return nil, nil })
|
||||
dp, ok := p.(sdk.CheckerDefinitionProvider)
|
||||
if !ok {
|
||||
t.Fatal("provider does not implement CheckerDefinitionProvider")
|
||||
}
|
||||
def := dp.Definition()
|
||||
if def.ID != "dnsviz" {
|
||||
t.Errorf("ID=%q", def.ID)
|
||||
}
|
||||
if !def.HasHTMLReport || !def.HasMetrics {
|
||||
t.Error("expected HasHTMLReport and HasMetrics to be true")
|
||||
}
|
||||
if !def.Availability.ApplyToDomain {
|
||||
t.Error("expected ApplyToDomain")
|
||||
}
|
||||
if def.Interval == nil || def.Interval.Default <= 0 {
|
||||
t.Errorf("interval not set: %+v", def.Interval)
|
||||
}
|
||||
if len(def.Rules) == 0 || len(def.RulesInfo) != len(def.Rules) {
|
||||
t.Errorf("rules vs rulesInfo: %d / %d", len(def.Rules), len(def.RulesInfo))
|
||||
}
|
||||
// At least one rule per published name.
|
||||
for _, ri := range def.RulesInfo {
|
||||
if ri.Name == "" || ri.Description == "" {
|
||||
t.Errorf("missing name/description in RulesInfo: %+v", ri)
|
||||
}
|
||||
}
|
||||
if len(def.ObservationKeys) == 0 || def.ObservationKeys[0] != ObservationKeyDNSViz {
|
||||
t.Errorf("observation keys: %v", def.ObservationKeys)
|
||||
}
|
||||
// Sanity: the domain-level option declares the auto-fill we rely on.
|
||||
hasDomain := false
|
||||
for _, o := range def.Options.DomainOpts {
|
||||
if o.Id == "domain_name" && o.AutoFill == sdk.AutoFillDomainName {
|
||||
hasDomain = true
|
||||
}
|
||||
}
|
||||
if !hasDomain {
|
||||
t.Error("expected domain_name option with AutoFillDomainName")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue