Move configuration reports to shared rendering
This commit is contained in:
@@ -2,10 +2,10 @@ package ckconfig
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
commandkit "go.maximumdirect.net/commandkit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
"go.yaml.in/yaml/v4"
|
||||
)
|
||||
@@ -16,11 +16,16 @@ func renderAndDecode(t *testing.T, differences []configkit.Difference) (*yaml.No
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var rendered bytes.Buffer
|
||||
if err := commandkit.RenderReport(&rendered, commandkit.Report{Value: report}, commandkit.FormatYAML); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data := rendered.Bytes()
|
||||
var document yaml.Node
|
||||
if err := yaml.Unmarshal(report, &document); err != nil {
|
||||
if err := yaml.Unmarshal(data, &document); err != nil {
|
||||
t.Fatalf("decode rendered report %q: %v", report, err)
|
||||
}
|
||||
return document.Content[0], report
|
||||
return document.Content[0], data
|
||||
}
|
||||
|
||||
func reportField(mapping *yaml.Node, key string) *yaml.Node {
|
||||
@@ -43,18 +48,12 @@ func TestRenderDiffReportClassifiesAndOrdersNativeRecords(t *testing.T) {
|
||||
if root.Kind != yaml.MappingNode || len(root.Content) != 6 {
|
||||
t.Fatalf("report root = %#v", root)
|
||||
}
|
||||
if got := []string{root.Content[0].Value, root.Content[2].Value, root.Content[4].Value}; !reflect.DeepEqual(got, []string{"additions", "changes", "deletions"}) {
|
||||
t.Fatalf("report category order = %#v", got)
|
||||
}
|
||||
additions := reportField(root, "additions")
|
||||
if additions.Kind != yaml.MappingNode || additions.Content[0].Value != "z-added" || additions.Content[2].Value != "a-added" {
|
||||
t.Fatalf("addition order/value = %#v", additions)
|
||||
if value := reportField(additions, "z-added"); value == nil || value.Tag != "!!bool" || value.Value != "false" {
|
||||
t.Fatalf("boolean addition = %#v", value)
|
||||
}
|
||||
if additions.Content[1].Kind != yaml.ScalarNode || additions.Content[1].Tag != "!!bool" || additions.Content[1].Value != "false" {
|
||||
t.Fatalf("boolean addition lost its type: %#v", additions.Content[1])
|
||||
}
|
||||
if additions.Content[3].Tag != "!!str" || additions.Content[3].Value != "123" {
|
||||
t.Fatalf("numeric-looking string lost its type: %#v", additions.Content[3])
|
||||
if value := reportField(additions, "a-added"); value == nil || value.Tag != "!!str" || value.Value != "123" {
|
||||
t.Fatalf("string addition = %#v", value)
|
||||
}
|
||||
changes := reportField(root, "changes")
|
||||
if changes.Kind != yaml.MappingNode || changes.Content[1].Tag != "!!int" || changes.Content[1].Value != "9007199254740993" {
|
||||
@@ -68,9 +67,6 @@ func TestRenderDiffReportClassifiesAndOrdersNativeRecords(t *testing.T) {
|
||||
|
||||
func TestRenderDiffReportEmitsEmptyCategoriesAndRootValue(t *testing.T) {
|
||||
root, _ := renderAndDecode(t, nil)
|
||||
if got := []string{root.Content[0].Value, root.Content[2].Value, root.Content[4].Value}; !reflect.DeepEqual(got, []string{"additions", "changes", "deletions"}) {
|
||||
t.Fatalf("empty report keys = %#v", got)
|
||||
}
|
||||
if reportField(root, "additions").Kind != yaml.MappingNode || len(reportField(root, "additions").Content) != 0 || reportField(root, "changes").Kind != yaml.MappingNode || len(reportField(root, "changes").Content) != 0 || reportField(root, "deletions").Kind != yaml.SequenceNode || len(reportField(root, "deletions").Content) != 0 {
|
||||
t.Fatalf("empty report categories = %#v", root)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user