Skip to content

Commit

Permalink
syntax/encoding: rename riverjson package to alloyjson
Browse files Browse the repository at this point in the history
  • Loading branch information
rfratto committed Mar 25, 2024
1 parent e1aab19 commit b13c9b3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions internal/component/component_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/grafana/alloy/syntax/encoding/riverjson"
"github.com/grafana/alloy/syntax/encoding/alloyjson"
)

var (
Expand Down Expand Up @@ -170,15 +170,15 @@ func (info *Info) MarshalJSON() ([]byte, error) {
referencedBy = []string{}
}

arguments, err = riverjson.MarshalBody(info.Arguments)
arguments, err = alloyjson.MarshalBody(info.Arguments)
if err != nil {
return nil, err
}
exports, err = riverjson.MarshalBody(info.Exports)
exports, err = alloyjson.MarshalBody(info.Exports)
if err != nil {
return nil, err
}
debugInfo, err = riverjson.MarshalBody(info.DebugInfo)
debugInfo, err = alloyjson.MarshalBody(info.DebugInfo)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package riverjson encodes River as JSON.
package riverjson
// Package alloyjson encodes Alloy configuration syntax as JSON.
package alloyjson

import (
"encoding/json"
Expand Down Expand Up @@ -61,7 +61,7 @@ func encodeStructAsBody(rv reflect.Value) jsonBody {

case reflect.Map:
if rv.Type().Key().Kind() != reflect.String {
panic("syntax/encoding/riverjson: unsupported map type; expected map[string]T, got " + rv.Type().String())
panic("syntax/encoding/alloyjson: unsupported map type; expected map[string]T, got " + rv.Type().String())
}

iter := rv.MapRange()
Expand All @@ -76,7 +76,7 @@ func encodeStructAsBody(rv reflect.Value) jsonBody {
}

default:
panic(fmt.Sprintf("syntax/encoding/riverjson: can only encode struct or map[string]T values to bodies, got %s", rv.Kind()))
panic(fmt.Sprintf("syntax/encoding/alloyjson: can only encode struct or map[string]T values to bodies, got %s", rv.Kind()))
}

return body
Expand Down Expand Up @@ -111,7 +111,7 @@ func encodeFieldAsStatements(prefix []string, field syntaxtags.Field, fieldValue
// Iterate over the map and add each element as an attribute into it.

if fieldValue.Type().Key().Kind() != reflect.String {
panic("syntax/encoding/riverjson: unsupported map type for block; expected map[string]T, got " + fieldValue.Type().String())
panic("syntax/encoding/alloyjson: unsupported map type for block; expected map[string]T, got " + fieldValue.Type().String())
}

statements := []jsonStatement{}
Expand Down Expand Up @@ -182,7 +182,7 @@ func encodeFieldAsStatements(prefix []string, field syntaxtags.Field, fieldValue
return statements

default:
panic(fmt.Sprintf("syntax/encoding/riverjson: unrecognized enum kind %s", fieldValue.Kind()))
panic(fmt.Sprintf("syntax/encoding/alloyjson: unrecognized enum kind %s", fieldValue.Kind()))
}
}

Expand Down Expand Up @@ -308,6 +308,6 @@ func buildJSONValue(v value.Value) jsonValue {
return jsonValue{Type: "capsule", Value: v.Describe()}

default:
panic(fmt.Sprintf("syntax/encoding/riverjson: unrecognized value type %q", v.Type()))
panic(fmt.Sprintf("syntax/encoding/alloyjson: unrecognized value type %q", v.Type()))
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package riverjson_test
package alloyjson_test

import (
"testing"

"github.com/grafana/alloy/syntax"
"github.com/grafana/alloy/syntax/alloytypes"
"github.com/grafana/alloy/syntax/encoding/riverjson"
"github.com/grafana/alloy/syntax/encoding/alloyjson"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -107,7 +107,7 @@ func TestValues(t *testing.T) {

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
actual, err := riverjson.MarshalValue(tc.input)
actual, err := alloyjson.MarshalValue(tc.input)
require.NoError(t, err)
require.JSONEq(t, tc.expectJSON, string(actual))
})
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestBlock(t *testing.T) {
}
]`

actual, err := riverjson.MarshalBody(val)
actual, err := alloyjson.MarshalBody(val)
require.NoError(t, err)
require.JSONEq(t, expect, string(actual))
}
Expand All @@ -216,7 +216,7 @@ func TestBlock_Empty_Required_Block_Slice(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
expect := `[]`

actual, err := riverjson.MarshalBody(tc.val)
actual, err := alloyjson.MarshalBody(tc.val)
require.NoError(t, err)
require.JSONEq(t, expect, string(actual))
})
Expand All @@ -240,15 +240,15 @@ type labeledBlock struct {
}

func TestNilBody(t *testing.T) {
actual, err := riverjson.MarshalBody(nil)
actual, err := alloyjson.MarshalBody(nil)
require.NoError(t, err)
require.JSONEq(t, `[]`, string(actual))
}

func TestEmptyBody(t *testing.T) {
type block struct{}

actual, err := riverjson.MarshalBody(block{})
actual, err := alloyjson.MarshalBody(block{})
require.NoError(t, err)
require.JSONEq(t, `[]`, string(actual))
}
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestHideDefaults(t *testing.T) {

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
actual, err := riverjson.MarshalBody(tc.val)
actual, err := alloyjson.MarshalBody(tc.val)
require.NoError(t, err)
require.JSONEq(t, tc.expectJSON, string(actual))
})
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestMapBlocks(t *testing.T) {
}]
}]`

bb, err := riverjson.MarshalBody(val)
bb, err := alloyjson.MarshalBody(val)
require.NoError(t, err)
require.JSONEq(t, expect, string(bb))
}
Expand All @@ -343,7 +343,7 @@ func TestRawMap(t *testing.T) {
"value": { "type": "string", "value": "value" }
}]`

bb, err := riverjson.MarshalBody(val)
bb, err := alloyjson.MarshalBody(val)
require.NoError(t, err)
require.JSONEq(t, expect, string(bb))
}
Expand All @@ -357,7 +357,7 @@ func TestRawMap_Capsule(t *testing.T) {
"value": { "type": "capsule", "value": "(secret)" }
}]`

bb, err := riverjson.MarshalBody(val)
bb, err := alloyjson.MarshalBody(val)
require.NoError(t, err)
require.JSONEq(t, expect, string(bb))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package riverjson
package alloyjson

// Various concrete types used to marshal River values.
type (
Expand Down

0 comments on commit b13c9b3

Please sign in to comment.