package compose

import (
	"encoding/json"
	"testing"
)

const validComposeYAML = "services:\n  web:\n    image: nginx:alpine\n    ports:\n      - \"80\"\n"

func composeCfg(strategy string) json.RawMessage {
	m := map[string]any{"compose_yaml": validComposeYAML}
	if strategy != "" {
		m["deploy_strategy"] = strategy
	}
	b, _ := json.Marshal(m)
	return b
}

func TestValidate_Strategy_RejectsBlueGreen(t *testing.T) {
	cases := []struct {
		strategy string
		wantErr  bool
	}{
		{"", false},          // backward-compat
		{"recreate", false},  // the only thing compose can do
		{"blue-green", true}, // not supported for a whole stack
		{"rolling", true},
	}
	for _, c := range cases {
		t.Run("strategy="+c.strategy, func(t *testing.T) {
			err := (&source{}).Validate(composeCfg(c.strategy))
			if (err != nil) != c.wantErr {
				t.Fatalf("Validate(strategy=%q) err=%v, wantErr=%v", c.strategy, err, c.wantErr)
			}
		})
	}
}
