/
t3
/
cli
Обзор
Документация
Войти
/
t3
/
cli
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
internal/config/validate.go
65 строк
2 KB
Ivan Shibkikh
thinktime / pacing
04 июл 2026, 17:00
04 июл 2026, 17:00
5f2e4c7
Код
Авторство
О чём код?
package config import ( "fmt" "time" ) func (cfg Config) Validate() error { if cfg.Version != "t3-v1.0" { return fmt.Errorf("unsupported version") } if cfg.ThinkTime == nil || !cfg.ThinkTime.IsSet() { return fmt.Errorf("`think_time` is required: use a duration string (e.g. \"1s\") for static think time or { pacing: \"1s\" } for pacing") } if cfg.ThinkTime.Static < 0 || cfg.ThinkTime.Pacing < 0 { return fmt.Errorf("`think_time` must be a positive duration") } if cfg.ThinkTime.Static > 0 && cfg.ThinkTime.Pacing > 0 { return fmt.Errorf("`think_time` cannot have both static and pacing values simultaneously") } if cfg.ThinkTime.Static > 0 && cfg.ThinkTime.Static < time.Millisecond { return fmt.Errorf("`think_time` minimum value is 1ms") } if cfg.ThinkTime.Pacing > 0 && cfg.ThinkTime.Pacing < time.Millisecond { return fmt.Errorf("`think_time` pacing minimum value is 1ms") } if cfg.Name == "" { return fmt.Errorf("name not defined") } if cfg.Script == "" { return fmt.Errorf("script not defined") } if cfg.Output == "" { return fmt.Errorf("output not defined") } if len(cfg.Steps) == 0 { return fmt.Errorf("`steps` not defined") } for i, step := range cfg.Steps { if step.Stage == "" { return fmt.Errorf("steps->step[%d]: `stage` not defined", i) } if step.Duration < time.Second { return fmt.Errorf("steps->step[%d]: min `duration` is 1s", i) } if i == 0 && step.Users == 0 { return fmt.Errorf("steps->step[%d]: `users` is required for the first step", i) } if i == len(cfg.Steps)-1 && step.Users > 0 { return fmt.Errorf("steps->step[%d]: `users` should be zero for the last step", i) } } if len(cfg.Agents) == 0 { return fmt.Errorf("`agents` not defined") } for i, agent := range cfg.Agents { if agent.Address == "" { return fmt.Errorf("agents->agent[%d]: `address` not defined", i) } if agent.Weight <= 0 && len(cfg.Agents) > 1 { return fmt.Errorf("agents->agent[%d]: `weight` is required for multi-agent workload", i) } } return nil }