74 lines
2.9 KiB
Go
74 lines
2.9 KiB
Go
package configkit
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/ConfigKit/internal/engine"
|
|
)
|
|
|
|
func TestOverlayPublicValues(t *testing.T) {
|
|
if LayerOverlay != "overlay" {
|
|
t.Fatalf("LayerOverlay = %q", LayerOverlay)
|
|
}
|
|
for code, value := range map[Code]string{
|
|
CodeOverlayInvalid: "overlay.invalid",
|
|
CodeOverlayMissing: "overlay.missing",
|
|
CodeOverlayOutsideRoot: "overlay.outside_root",
|
|
CodeOverlayRepeated: "overlay.repeated",
|
|
CodeOverlayDirective: "overlay.directive",
|
|
CodeOverlayVersion: "overlay.version",
|
|
CodeOverlayLimitExceeded: "overlay.limit_exceeded",
|
|
} {
|
|
if string(code) != value {
|
|
t.Errorf("code = %q, want %q", code, value)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSourceInfoDestinationConversionsAndCopies(t *testing.T) {
|
|
destination := Keys("collections", "a/b", "0")
|
|
public := SourceInfo{
|
|
ID: "source-1", Destination: destination,
|
|
PlacementMode: PlacementModeSequenceItem, DestinationUnresolved: true,
|
|
}
|
|
internal := toEngineSourceInfo(public)
|
|
if internal.Destination.String() != destination.String() || engine.SourceInfoPlacementModeForFacade(internal) != uint8(PlacementModeSequenceItem) || !engine.SourceInfoDestinationUnresolvedForFacade(internal) {
|
|
t.Fatalf("engine source evidence = %#v", internal)
|
|
}
|
|
converted := fromEngineSourceInfo(internal)
|
|
if converted.Destination.String() != destination.String() || converted.PlacementMode != PlacementModeSequenceItem || !converted.DestinationUnresolved {
|
|
t.Fatalf("public source evidence = %#v", converted)
|
|
}
|
|
copy := cloneSourceInfo(converted)
|
|
copy.Destination = Path{}
|
|
if converted.Destination.String() != destination.String() {
|
|
t.Fatalf("source record destination changed through clone: %q", converted.Destination.String())
|
|
}
|
|
}
|
|
|
|
func TestSourceVersionCheckConversionsAndCopies(t *testing.T) {
|
|
path := Keys("records").Index(2).Key("version")
|
|
source := SourceInfo{
|
|
ID: "source-1",
|
|
VersionCheck: &SourceVersionCheck{
|
|
Path: path, Version: Version{Present: true, Text: "123"},
|
|
Location: &Location{SourceID: "source-1", Line: 4, Column: 8},
|
|
},
|
|
}
|
|
internal := toEngineSourceInfo(source)
|
|
if internal.VersionCheck == nil || internal.VersionCheck.Path.String() != path.String() ||
|
|
internal.VersionCheck.Version.Text != "123" || internal.VersionCheck.Location == nil || internal.VersionCheck.Location.Line != 4 {
|
|
t.Fatalf("engine source version check = %#v", internal.VersionCheck)
|
|
}
|
|
converted := fromEngineSourceInfo(internal)
|
|
copy := cloneSourceInfo(converted)
|
|
copy.VersionCheck.Path = Keys("changed")
|
|
copy.VersionCheck.Version.Text = "changed"
|
|
copy.VersionCheck.Location.Line = 99
|
|
copy.VersionCheck.Redacted = true
|
|
if converted.VersionCheck.Path.String() != path.String() || converted.VersionCheck.Version.Text != "123" ||
|
|
converted.VersionCheck.Location.Line != 4 || converted.VersionCheck.Redacted {
|
|
t.Fatalf("source version check changed through a detached copy: %#v", converted.VersionCheck)
|
|
}
|
|
}
|