Files
NageshbansalandGitHub e8b1b4f653 feat: introduce casting kind (#116)
### Summary                            

- Introduce a `kind` discriminator for Casting. Existing Casting without
a kind field keep working, empty kind defaults to `Installation`
- New `api/v1alpha1/installation/` subpackage with the Installation
Casting, Spec types and holds its own JSON schema from its Go type:
`installation/casting.schema.json`
- New Machinery interface in `api/v1alpha1/machinery.go` exposes
`Kind()` and `TrackableProperties()` so Dispatcher(Getv1alpha1 and
Forge/Cast/Gauge) work across any kind without knowing its concrete
type.
- A root casting.schema.json lists every per-Kind schema to supports
IDEs completion from one schema URL
- cmd/foundryctl gen schemas reads a list of types from schemaTargets.
Adding a kind means adding one entry.
  
Related: https://github.com/SigNoz/platform-pod/issues/1970
2026-05-16 17:40:03 +05:30

67 lines
2.3 KiB
Go

package ecsterraformcasting
import (
"bytes"
"testing"
"github.com/signoz/foundry/api/v1alpha1"
"github.com/signoz/foundry/api/v1alpha1/installation"
"github.com/signoz/foundry/internal/domain"
"github.com/stretchr/testify/assert"
)
func TestNotEmptyAndValid(t *testing.T) {
templates := map[string]*domain.Template{
"mainTF": mainTF,
"variablesTF": variablesTF,
"moduleMainTF": moduleMainTF,
"moduleVariablesTF": moduleVariablesTF,
"moduleOutputsTF": moduleOutputsTF,
"moduleTelemetryKeeperTF": moduleTelemetryKeeperTF,
"moduleTelemetryStoreTF": moduleTelemetryStoreTF,
"moduleMigratorTF": moduleMigratorTF,
"moduleMetaStoreTF": moduleMetaStoreTF,
"moduleSignozTF": moduleSignozTF,
"moduleIngesterTF": moduleIngesterTF,
}
for name, tmpl := range templates {
assert.NotEmpty(t, tmpl, "%s should not be empty", name)
buf := bytes.NewBuffer(nil)
err := tmpl.Execute(buf, nil)
assert.NoError(t, err, "error executing %s", name)
assert.NotEmpty(t, buf.String(), "%s output should not be empty", name)
}
}
func TestTfvarsTemplateWithAnnotations(t *testing.T) {
assert.NotEmpty(t, tfarsTF)
casting := &installation.Casting{
CastingMeta: v1alpha1.CastingMeta{
Metadata: v1alpha1.TypeMetadata{
Name: "signoz",
Annotations: map[string]string{
"foundry.signoz.io/ecs/region": "us-east-1",
"foundry.signoz.io/ecs/cluster-id": "arn:aws:ecs:us-east-1:123456789012:cluster/test",
"foundry.signoz.io/ecs/subnet-ids": "subnet-abc123,subnet-def456",
"foundry.signoz.io/ecs/security-group-ids": "sg-abc123",
"foundry.signoz.io/ecs/vpc-id": "vpc-abc123",
"foundry.signoz.io/ecs/config-bucket": "test-configs",
"foundry.signoz.io/ecs/task-role-arn": "arn:aws:iam::123456789012:role/task",
"foundry.signoz.io/ecs/task-execution-role-arn": "arn:aws:iam::123456789012:role/exec",
"foundry.signoz.io/ecs/capacity-provider": "test-provider",
},
},
},
}
buf := bytes.NewBuffer(nil)
err := tfarsTF.Execute(buf, casting)
assert.NoError(t, err)
assert.NotEmpty(t, buf.String())
assert.Contains(t, buf.String(), "us-east-1")
assert.Contains(t, buf.String(), "subnet-abc123")
assert.Contains(t, buf.String(), "subnet-def456")
}