Files
ConfigKit/records_test.go

67 lines
2.6 KiB
Go

package configkit
import "testing"
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}
internal := toEngineSourceInfo(public)
if internal.Destination.String() != destination.String() {
t.Fatalf("engine destination = %q, want %q", internal.Destination.String(), destination.String())
}
converted := fromEngineSourceInfo(internal)
if converted.Destination.String() != destination.String() {
t.Fatalf("public destination = %q, want %q", converted.Destination.String(), destination.String())
}
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)
}
}