parent
f3a1a4c83f
commit
437841c8dd
@ -1,5 +1,17 @@
|
||||
module repos.digitalenergy.online/BASIS/decort-golang-sdk
|
||||
module repository.basistech.ru/BASIS/decort-golang-sdk
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/google/go-querystring v1.1.0
|
||||
require (
|
||||
github.com/go-playground/validator/v10 v10.11.2
|
||||
github.com/google/go-querystring v1.1.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
golang.org/x/crypto v0.5.0 // indirect
|
||||
golang.org/x/sys v0.4.0 // indirect
|
||||
golang.org/x/text v0.6.0 // indirect
|
||||
)
|
||||
|
@ -1,5 +1,30 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
|
||||
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
||||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
|
||||
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
|
||||
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
|
||||
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
|
||||
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
@ -0,0 +1,110 @@
|
||||
package validators
|
||||
|
||||
import "github.com/go-playground/validator/v10"
|
||||
|
||||
// accountCUTypeValidator is used to validate CUType field.
|
||||
func accountCUTypeValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, accountCUTypeValues)
|
||||
}
|
||||
|
||||
// accountAccessTypeValidator is used to validate AccessType field.
|
||||
func accountAccessTypeValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, accountAccessTypeValues)
|
||||
}
|
||||
|
||||
// bserviceDriverValidator is used to validate Driver field.
|
||||
func bserviceDriverValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, bserviceDriverValues)
|
||||
}
|
||||
|
||||
// bserviceModeValidator is used to validate Mode field.
|
||||
func bserviceModeValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, bserviceModeValues)
|
||||
}
|
||||
|
||||
// computeTopologyValidator is used to validate Topology field.
|
||||
func computeTopologyValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, computeTopologyValues)
|
||||
}
|
||||
|
||||
// computePolicyValidator is used to validate Policy field.
|
||||
func computePolicyValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, computePolicyValues)
|
||||
}
|
||||
|
||||
// computeModeValidator is used to validate Mode field.
|
||||
func computeModeValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, computeModeValues)
|
||||
}
|
||||
|
||||
// computeDiskTypeValidator is used to validate DiskType field.
|
||||
func computeDiskTypeValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, computeDiskTypeValues)
|
||||
}
|
||||
|
||||
// computeNetTypeValidator is used to validate NetType field.
|
||||
func computeNetTypeValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, computeNetTypeValues)
|
||||
}
|
||||
|
||||
// computeProtoValidator is used to validate Proto field.
|
||||
func computeProtoValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, computeProtoValues)
|
||||
}
|
||||
|
||||
// imageBootTypeValidator is used to validate BootType field.
|
||||
func imageBootTypeValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, imageBootTypeValues)
|
||||
}
|
||||
|
||||
// imageTypeValidator is used to validate ImageType field.
|
||||
func imageTypeValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, imageTypeValues)
|
||||
}
|
||||
|
||||
// imageDriversValidator is used to validate Drivers field.
|
||||
func imageDriversValidator(fe validator.FieldLevel) bool {
|
||||
fieldSlice, ok := fe.Field().Interface().([]string)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, item := range fieldSlice {
|
||||
if !StringInSlice(item, imageDriversValues) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// imageArchitectureValidator is used to validate Architecture field.
|
||||
func imageArchitectureValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
|
||||
return StringInSlice(fieldValue, imageArchitectureValues)
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package validators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
func errorMessage(fe validator.FieldError) string {
|
||||
prefix := "validation-error:"
|
||||
|
||||
switch fe.Tag() {
|
||||
|
||||
// Default Validators
|
||||
case "required":
|
||||
return fmt.Sprintf("%s %s is required", prefix, fe.Field())
|
||||
case "gt":
|
||||
return fmt.Sprintf("%s %s can't be less or equal to zero", prefix, fe.Field())
|
||||
case "min":
|
||||
return fmt.Sprintf("%s %s: not enough elements", prefix, fe.Field())
|
||||
case "max":
|
||||
return fmt.Sprintf("%s %s: too many elements", prefix, fe.Field())
|
||||
case "url":
|
||||
return fmt.Sprintf("%s %s: unexpected URL format", prefix, fe.Field())
|
||||
case "email":
|
||||
return fmt.Sprintf("%s %s: unexpected E-Mail format", prefix, fe.Field())
|
||||
|
||||
// Account Validators
|
||||
case "accountAccessType":
|
||||
return fmt.Sprintf("%s %s must be one of the followng: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(accountAccessTypeValues))
|
||||
|
||||
case "accountCUType":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(accountCUTypeValues))
|
||||
|
||||
// BService Validators
|
||||
case "bserviceDriver":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(bserviceDriverValues))
|
||||
|
||||
case "bserviceMode":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(bserviceModeValues))
|
||||
|
||||
// Compute Validators
|
||||
case "computeTopology":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(computeTopologyValues))
|
||||
|
||||
case "computePolicy":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(computePolicyValues))
|
||||
|
||||
case "computeMode":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(computeModeValues))
|
||||
|
||||
case "computeDiskType":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(computeDiskTypeValues))
|
||||
|
||||
case "computeNetType":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(computeNetTypeValues))
|
||||
|
||||
case "computeProto":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(computeProtoValues))
|
||||
|
||||
// Image Validators
|
||||
case "bootType":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(imageBootTypeValues))
|
||||
|
||||
case "imageType":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(imageTypeValues))
|
||||
|
||||
case "imageDrivers":
|
||||
return fmt.Sprintf("%s %s must contain only the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(imageDriversValues))
|
||||
|
||||
case "imageArchitecture":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
prefix,
|
||||
fe.Field(),
|
||||
joinValues(imageArchitectureValues))
|
||||
|
||||
}
|
||||
|
||||
return fe.Error()
|
||||
}
|
||||
|
||||
func joinValues(values []string) string {
|
||||
return strings.Join(values, ", ")
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package validators
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
instance *DecortValidator
|
||||
)
|
||||
|
||||
type DecortValidator struct {
|
||||
decortValidator *validator.Validate
|
||||
}
|
||||
|
||||
// getDecortValidator returns singleton instance of DecortValidator.
|
||||
func getDecortValidator() *validator.Validate {
|
||||
if instance == nil {
|
||||
once.Do(func() {
|
||||
instance = new(DecortValidator)
|
||||
instance.decortValidator = validator.New()
|
||||
|
||||
err := registerAllValidators(instance.decortValidator)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return instance.decortValidator
|
||||
}
|
||||
|
||||
// registerAllValidators registers all custom validators in DecortValidator.
|
||||
func registerAllValidators(validate *validator.Validate) error {
|
||||
err := validate.RegisterValidation("bootType", imageBootTypeValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("imageType", imageTypeValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("imageDrivers", imageDriversValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("imageArchitecture", imageArchitectureValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("accountAccessType", accountAccessTypeValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("accountCUType", accountCUTypeValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("bserviceDriver", bserviceDriverValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("bserviceMode", bserviceModeValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("computeTopology", computeTopologyValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("computePolicy", computePolicyValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("computeMode", computeModeValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("computeDiskType", computeDiskTypeValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("computeNetType", computeNetTypeValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("computeProto", computeProtoValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package validators
|
||||
|
||||
var (
|
||||
accountAccessTypeValues = []string{"R", "RCX", "ARCXDU"}
|
||||
accountCUTypeValues = []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"}
|
||||
|
||||
bserviceDriverValues = []string{"KVM_X86, KVM_PPC"}
|
||||
bserviceModeValues = []string{"ABSOLUTE", "RELATIVE"}
|
||||
|
||||
computeTopologyValues = []string{"compute", "node"}
|
||||
computePolicyValues = []string{"RECOMMENDED", "REQUIRED"}
|
||||
computeModeValues = []string{"EQ", "EN", "ANY"}
|
||||
computeDiskTypeValues = []string{"D", "B"}
|
||||
computeNetTypeValues = []string{"EXTNET", "VINS"}
|
||||
computeProtoValues = []string{"tcp", "udp"}
|
||||
|
||||
imageBootTypeValues = []string{"uefi", "bios"}
|
||||
imageTypeValues = []string{"windows", "linux", "other"}
|
||||
imageDriversValues = []string{"KVM_X86"}
|
||||
imageArchitectureValues = []string{"X86_64", "PPC64_LE"}
|
||||
)
|
@ -0,0 +1,152 @@
|
||||
package bservice
|
||||
|
||||
import "testing"
|
||||
|
||||
var bservices = ListBasicServices{
|
||||
{
|
||||
AccountID: 1,
|
||||
AccountName: "std_1",
|
||||
BaseDomain: "",
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1677743675,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
GID: 212,
|
||||
Groups: []uint64{},
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
Name: "bservice_1",
|
||||
ParentSrvID: 0,
|
||||
ParentSrvType: "",
|
||||
RGID: 7971,
|
||||
RGName: "rg_1",
|
||||
SSHUser: "",
|
||||
Status: "CREATED",
|
||||
TechStatus: "STOPPED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
UserManaged: true,
|
||||
},
|
||||
{
|
||||
AccountID: 2,
|
||||
AccountName: "std_2",
|
||||
BaseDomain: "",
|
||||
CreatedBy: "sample_user_1@decs3o",
|
||||
CreatedTime: 1677743736,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
GID: 212,
|
||||
Groups: []uint64{},
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
Name: "bservice_2",
|
||||
ParentSrvID: 0,
|
||||
ParentSrvType: "",
|
||||
RGID: 7972,
|
||||
RGName: "rg_2",
|
||||
SSHUser: "",
|
||||
Status: "CREATED",
|
||||
TechStatus: "STOPPED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
UserManaged: true,
|
||||
},
|
||||
{
|
||||
AccountID: 3,
|
||||
AccountName: "std_3",
|
||||
BaseDomain: "",
|
||||
CreatedBy: "sample_user_2@decs3o",
|
||||
CreatedTime: 1677743830,
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
GID: 212,
|
||||
Groups: []uint64{},
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
Name: "bservice_3",
|
||||
ParentSrvID: 0,
|
||||
ParentSrvType: "",
|
||||
RGID: 7973,
|
||||
RGName: "rg_3",
|
||||
SSHUser: "",
|
||||
Status: "ENABLED",
|
||||
TechStatus: "STARTED",
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 0,
|
||||
UserManaged: true,
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := bservices.FilterByID(1).FindOne()
|
||||
|
||||
if actual.ID != 1 {
|
||||
t.Fatal("expected ID 1, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := bservices.FilterByName("bservice_3").FindOne()
|
||||
|
||||
if actual.Name != "bservice_3" {
|
||||
t.Fatal("expected Name 'bservice_3', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByRGID(t *testing.T) {
|
||||
actual := bservices.FilterByRGID(7971).FindOne()
|
||||
|
||||
if actual.RGID != 7971 {
|
||||
t.Fatal("expected RGID 7971, found: ", actual.RGID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := bservices.FilterByStatus("CREATED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Status != "CREATED" {
|
||||
t.Fatal("expected Status 'CREATED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByTechStatus(t *testing.T) {
|
||||
actual := bservices.FilterByTechStatus("STOPPED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.TechStatus != "STOPPED" {
|
||||
t.Fatal("expected TechStatus 'STOPPED', found: ", item.TechStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := bservices.FilterFunc(func(ibs ItemBasicService) bool {
|
||||
return ibs.CreatedBy == "sample_user_2@decs3o"
|
||||
})
|
||||
|
||||
if len(actual) > 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
if actual.FindOne().CreatedBy != "sample_user_2@decs3o" {
|
||||
t.Fatal("expected 'sample_user_2@decs3o', found: ", actual.FindOne().CreatedBy)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortByCreatedTime(t *testing.T) {
|
||||
actual := bservices.SortByCreatedTime(true)
|
||||
|
||||
if actual[0].CreatedTime != 1677743830 || actual[2].CreatedTime != 1677743675 {
|
||||
t.Fatal("expected descending order, found ascending")
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue