mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-12 00:45:22 +00:00
feat(adapter): registry with detect filtering and duplicate guard
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// Package render holds deterministic format marshallers.
|
||||
package render
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func JSON(v any) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
enc := json.NewEncoder(&buf)
|
||||
enc.SetIndent("", " ")
|
||||
enc.SetEscapeHTML(false)
|
||||
if err := enc.Encode(v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package render
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestJSONIndent(t *testing.T) {
|
||||
b, err := JSON(map[string]any{"a": 1, "b": "x"})
|
||||
require.NoError(t, err)
|
||||
s := string(b)
|
||||
assert.Contains(t, s, "\"a\": 1")
|
||||
assert.True(t, s[len(s)-1] == '\n', "trailing newline required")
|
||||
}
|
||||
|
||||
func TestYAML(t *testing.T) {
|
||||
b, err := YAML(map[string]any{"a": 1})
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(b), "a: 1")
|
||||
}
|
||||
|
||||
func TestTOML(t *testing.T) {
|
||||
b, err := TOML(map[string]any{"a": 1})
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(b), "a = 1")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package render
|
||||
|
||||
import "github.com/pelletier/go-toml/v2"
|
||||
|
||||
func TOML(v any) ([]byte, error) {
|
||||
return toml.Marshal(v)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package render
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
func YAML(v any) ([]byte, error) {
|
||||
return yaml.Marshal(v)
|
||||
}
|
||||
Reference in New Issue
Block a user