/
validators.go
40 lines (35 loc) · 948 Bytes
/
validators.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package models
import (
"net/url"
"time"
SMP "github.com/khulnasoft/service-mesh-performance/spec"
)
// SMPPerformanceTestConfigValidator performs validations on the given PerformanceTestConfig object
func SMPPerformanceTestConfigValidator(perfTest *SMP.PerformanceTestConfig) error {
if perfTest.Name == "" {
return ErrField
}
if _, err := time.ParseDuration(perfTest.Duration); err != nil {
return ErrParsingTest
}
if len(perfTest.Clients) < 1 {
return ErrTestClient
}
for _, testClient := range perfTest.Clients {
if testClient.Protocol.String() == "" {
return ErrProtocol
}
if !(testClient.LoadGenerator == Wrk2LG.Name() || testClient.LoadGenerator == FortioLG.Name()) {
return ErrLoadgenerator
}
if len(testClient.EndpointUrls) < 1 {
return ErrTestEndpoint
}
for _, URL := range testClient.EndpointUrls {
if _, err := url.Parse(URL); err != nil {
return ErrValidURL
}
}
}
return nil
}