Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
146 lines
3.9 KiB
Go
146 lines
3.9 KiB
Go
package automation
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestConditionsValue_Nil(t *testing.T) {
|
|
var c Conditions = nil
|
|
val, err := c.Value()
|
|
if err != nil {
|
|
t.Fatalf("expected no error for nil Conditions Value, got: %v", err)
|
|
}
|
|
// Should marshal as empty array
|
|
var result []Condition
|
|
if err := json.Unmarshal(val.([]byte), &result); err != nil {
|
|
t.Fatalf("failed to unmarshal nil Conditions value: %v", err)
|
|
}
|
|
if len(result) != 0 {
|
|
t.Fatalf("expected empty array for nil Conditions, got %d items", len(result))
|
|
}
|
|
}
|
|
|
|
func TestConditionsValue_NonNil(t *testing.T) {
|
|
c := Conditions{
|
|
{Attribute: "status", FilterOperator: "equal", Values: []string{"open"}, QueryOperator: "and"},
|
|
}
|
|
val, err := c.Value()
|
|
if err != nil {
|
|
t.Fatalf("expected no error for Conditions Value, got: %v", err)
|
|
}
|
|
var result Conditions
|
|
if err := json.Unmarshal(val.([]byte), &result); err != nil {
|
|
t.Fatalf("failed to unmarshal Conditions value: %v", err)
|
|
}
|
|
if len(result) != 1 {
|
|
t.Fatalf("expected 1 condition, got %d", len(result))
|
|
}
|
|
if result[0].Attribute != "status" {
|
|
t.Fatalf("expected attribute 'status', got %q", result[0].Attribute)
|
|
}
|
|
}
|
|
|
|
func TestConditionsScan_Nil(t *testing.T) {
|
|
var c Conditions
|
|
err := c.Scan(nil)
|
|
if err != nil {
|
|
t.Fatalf("expected no error for nil Scan, got: %v", err)
|
|
}
|
|
if len(c) != 0 {
|
|
t.Fatalf("expected empty Conditions after nil Scan, got %d items", len(c))
|
|
}
|
|
}
|
|
|
|
func TestConditionsScan_ValidJSON(t *testing.T) {
|
|
raw := `[{"attribute":"status","filter_operator":"equal","values":["open"],"query_operator":"and"}]`
|
|
var c Conditions
|
|
err := c.Scan([]byte(raw))
|
|
if err != nil {
|
|
t.Fatalf("expected no error for valid JSON Scan, got: %v", err)
|
|
}
|
|
if len(c) != 1 {
|
|
t.Fatalf("expected 1 condition, got %d", len(c))
|
|
}
|
|
if c[0].Attribute != "status" {
|
|
t.Fatalf("expected attribute 'status', got %q", c[0].Attribute)
|
|
}
|
|
}
|
|
|
|
func TestConditionsScan_InvalidType(t *testing.T) {
|
|
var c Conditions
|
|
err := c.Scan("not bytes")
|
|
if err == nil {
|
|
t.Fatal("expected error for non-byte Scan, got nil")
|
|
}
|
|
}
|
|
|
|
func TestActionsValue_Nil(t *testing.T) {
|
|
var a Actions = nil
|
|
val, err := a.Value()
|
|
if err != nil {
|
|
t.Fatalf("expected no error for nil Actions Value, got: %v", err)
|
|
}
|
|
var result []Action
|
|
if err := json.Unmarshal(val.([]byte), &result); err != nil {
|
|
t.Fatalf("failed to unmarshal nil Actions value: %v", err)
|
|
}
|
|
if len(result) != 0 {
|
|
t.Fatalf("expected empty array for nil Actions, got %d items", len(result))
|
|
}
|
|
}
|
|
|
|
func TestActionsValue_NonNil(t *testing.T) {
|
|
a := Actions{
|
|
{ActionName: "send_message", ActionParams: map[string]interface{}{"content": "hello"}},
|
|
}
|
|
val, err := a.Value()
|
|
if err != nil {
|
|
t.Fatalf("expected no error for Actions Value, got: %v", err)
|
|
}
|
|
var result Actions
|
|
if err := json.Unmarshal(val.([]byte), &result); err != nil {
|
|
t.Fatalf("failed to unmarshal Actions value: %v", err)
|
|
}
|
|
if len(result) != 1 {
|
|
t.Fatalf("expected 1 action, got %d", len(result))
|
|
}
|
|
if result[0].ActionName != "send_message" {
|
|
t.Fatalf("expected action_name 'send_message', got %q", result[0].ActionName)
|
|
}
|
|
}
|
|
|
|
func TestActionsScan_Nil(t *testing.T) {
|
|
var a Actions
|
|
err := a.Scan(nil)
|
|
if err != nil {
|
|
t.Fatalf("expected no error for nil Scan, got: %v", err)
|
|
}
|
|
if len(a) != 0 {
|
|
t.Fatalf("expected empty Actions after nil Scan, got %d items", len(a))
|
|
}
|
|
}
|
|
|
|
func TestActionsScan_ValidJSON(t *testing.T) {
|
|
raw := `[{"action_name":"send_message","action_params":{"content":"hello"}}]`
|
|
var a Actions
|
|
err := a.Scan([]byte(raw))
|
|
if err != nil {
|
|
t.Fatalf("expected no error for valid JSON Scan, got: %v", err)
|
|
}
|
|
if len(a) != 1 {
|
|
t.Fatalf("expected 1 action, got %d", len(a))
|
|
}
|
|
if a[0].ActionName != "send_message" {
|
|
t.Fatalf("expected action_name 'send_message', got %q", a[0].ActionName)
|
|
}
|
|
}
|
|
|
|
func TestActionsScan_InvalidType(t *testing.T) {
|
|
var a Actions
|
|
err := a.Scan("not bytes")
|
|
if err == nil {
|
|
t.Fatal("expected error for non-byte Scan, got nil")
|
|
}
|
|
}
|