Files

44 lines
1.6 KiB
Go

package controlplanestore
import (
"context"
"testing"
"time"
"github.com/samcharles93/archie-core/internal/config"
)
// onlyScheduling serves one scheduling-policy document and nothing else.
type onlyScheduling string
func (r onlyScheduling) Query(_ context.Context, kind string, decode func([]byte) error) (int64, bool, error) {
if kind != SchedulingPolicyKind {
return 0, false, nil
}
return 1, true, decode([]byte(r))
}
func TestRuntimeConfigLayersSchedulingFromAnyOrgsDocument(t *testing.T) {
base := config.Config{PollInterval: config.Duration(time.Minute), MaxRetries: 3, Label: "archie", Dispatch: config.Dispatch{Trigger: "assignee", AckReaction: "eyes"}}
tests := []struct {
name, doc string
poll time.Duration
retries int
trigger string
}{
{"system org document replaces the instance values", `{"poll_interval":"30s","max_retries":5,"dispatch":{"trigger":"label"},"label":"go"}`, 30 * time.Second, 5, "label"},
{"another org's unset document keeps the instance values", orgEmptyDocuments[SchedulingPolicyKind], time.Minute, 3, "assignee"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, _, err := runtimeConfigFrom(t.Context(), onlyScheduling(tt.doc), base)
if err != nil {
t.Fatalf("runtimeConfigFrom() error = %v", err)
}
if got.PollInterval.Std() != tt.poll || got.MaxRetries != tt.retries || got.Dispatch.Trigger != tt.trigger {
t.Fatalf("got poll %v retries %d trigger %q, want %v %d %q", got.PollInterval.Std(), got.MaxRetries, got.Dispatch.Trigger, tt.poll, tt.retries, tt.trigger)
}
})
}
}