Files
worker/app/models/check_settings_test.go
Gleb Tv 2c7a0236da feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
2026-07-13 17:55:14 +03:00

61 строка
1.5 KiB
Go

package models
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCheckSettingsDistributed_Default(t *testing.T) {
s := CheckSettings{}
assert.False(t, s.Distributed, "new CheckSettings should default to Distributed=false")
}
func TestCheckSettingsDistributed_JSON(t *testing.T) {
original := CheckSettings{
HTTPUsername: "user",
HTTPPassword: "pass",
ExpectedAnswer: "default",
Timeout: 30,
Distributed: true,
}
data, err := json.Marshal(original)
assert.NoError(t, err)
assert.Contains(t, string(data), `"distributed":true`)
var decoded CheckSettings
err = json.Unmarshal(data, &decoded)
assert.NoError(t, err)
assert.Equal(t, original, decoded)
assert.True(t, decoded.Distributed)
}
func TestCheckSettingsDistributed_OmitFalse(t *testing.T) {
s := CheckSettings{HTTPUsername: "user"}
data, err := json.Marshal(s)
assert.NoError(t, err)
assert.Contains(t, string(data), `"distributed":false`)
}
func TestCheckSettingsDistributed_CheckUnmarshal(t *testing.T) {
c := &Check{
Settings: []byte(`{"distributed": true, "timeout": 60}`),
}
got := c.GetSettings()
assert.True(t, got.Distributed)
assert.Equal(t, 60, got.Timeout)
}
func TestPlanAllowsDistributed(t *testing.T) {
var nilPlan *Plan
assert.False(t, nilPlan.AllowsDistributed(), "nil plan must not allow distributed")
free := &Plan{Price: 0}
assert.False(t, free.AllowsDistributed(), "free plan must not allow distributed")
paid := &Plan{Price: 100}
assert.True(t, paid.AllowsDistributed(), "paid plan must allow distributed")
}