Files
NageshbansalandGitHub bdc48aaf9f feat: introduce spec.patches, and remove config.knobs, patch (#73)
### Summary

- Replace the three-tier model (`spec` + `config.knobs` + top-level
`patches`) with a two-tier model (`spec` + `spec.patches`)
- `spec` is the application domain (Foundry understands it),
`spec.patches` is the platform domain (Foundry applies it as-is)
- Add JSON Patch (RFC 6902) as the default patch driver with a driver
architecture for future extensibility


  ### Features

- Introduce `spec.patches` for applying JSON Patch (RFC 6902) operations
to generated materials during forge
- Add `PatchEntry` and `PatchOperation` API types with schema tags
(`default`, `example`, `examples`)
- Add `internal/patch/` package with driver interface and
`internal/patch/jsonpatch/` implementation
- Add `Patchers map[string]patch.Patch` driver registry on Foundry
struct with per-entry dispatch in forge
- Add `Material.WithContents()` for creating patched materials
preserving path and format
  - Support target matching by exact path and glob pattern


Related: https://github.com/SigNoz/platform-pod/issues/1778
2026-03-17 18:29:05 +05:30

35 lines
949 B
Go

package patch
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMatchTarget(t *testing.T) {
tests := []struct {
name string
pattern string
path string
want bool
}{
{"exact match", "test.yaml", "test.yaml", true},
{"full path match", "deployment/compose.yaml", "deployment/compose.yaml", true},
{"basename does not match full path", "compose.yaml", "deployment/compose.yaml", false},
{"glob match", "*.yaml", "test.yaml", true},
{"glob no match", "*.json", "test.yaml", false},
{"prefix glob", "clickhouse-*.yaml", "clickhouse-shard-0.yaml", true},
{"path glob", "deployment/*.yaml", "deployment/compose.yaml", true},
{"no match", "other.yaml", "test.yaml", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := MatchTarget(tt.pattern, tt.path)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
}