Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run unit tests for shared and ml packages #1524

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,12 @@ manifest-verify-helm-ee: manifests-verify-env-reset
.PHONY: run-unit-tests
run-unit-tests: $(SOURCES)
go test --count=1 --tags "$(GOBUILDTAGS)" $(TESTVERBOSEOPTIONS) \
$(REPOPATH)/pkg/apis/shared/... \
$(REPOPATH)/pkg/apis/backup/... \
$(REPOPATH)/pkg/apis/deployment/... \
$(REPOPATH)/pkg/apis/replication/... \
$(REPOPATH)/pkg/apis/storage/... \
$(REPOPATH)/pkg/apis/ml/... \
$(REPOPATH)/pkg/deployment/... \
$(REPOPATH)/pkg/storage/... \
$(REPOPATH)/pkg/crd/... \
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/ml/v1alpha1/storage_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ func (s *ArangoMLStorageSpec) GetBucketPath() string {

func (s *ArangoMLStorageSpec) GetMode() *ArangoMLStorageSpecMode {
if s == nil || s.Mode == nil {
return &ArangoMLStorageSpecMode{}
return nil
}
return s.Mode
}

func (s *ArangoMLStorageSpec) GetBackend() *ArangoMLStorageSpecBackend {
if s == nil || s.Backend == nil {
return &ArangoMLStorageSpecBackend{}
return nil
}
return s.Backend
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/ml/v1alpha1/storage_spec_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ArangoMLStorageSpecMode struct {

func (s *ArangoMLStorageSpecMode) GetSidecar() *ArangoMLStorageSpecModeSidecar {
if s == nil || s.Sidecar == nil {
return &ArangoMLStorageSpecModeSidecar{}
return nil
}
return s.Sidecar
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/apis/ml/v1alpha1/storage_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ import (

func Test_ArangoMLStorageSpec(t *testing.T) {
s := ArangoMLStorageSpec{}
require.Nil(t, s.GetMode())
require.Nil(t, s.GetBackend())
require.Error(t, s.Validate())
require.NotNil(t, s.GetMode())
require.NotNil(t, s.GetBackend())

require.NotNil(t, s.Mode.GetSidecar())
s.Mode = &ArangoMLStorageSpecMode{}
require.Nil(t, s.Mode.GetSidecar())

require.NotNil(t, s.Backend.GetS3())
s.Backend = &ArangoMLStorageSpecBackend{}
require.Nil(t, s.Backend.GetS3())
require.Error(t, s.Validate())

require.NotNil(t, s.Mode.Sidecar.GetListenPort())
require.NotNil(t, s.Mode.Sidecar.GetResources())
s.Mode.Sidecar = &ArangoMLStorageSpecModeSidecar{}
require.Nil(t, s.Mode.Sidecar.GetResources())
require.NotNil(t, s.Mode.Sidecar.GetListenPort())

require.Error(t, s.Backend.S3.Validate())
s.Backend.S3 = &ArangoMLStorageSpecBackendS3{
Expand All @@ -62,17 +62,17 @@ func Test_ArangoMLStorageSpec(t *testing.T) {
t.Run("default requests and limits assigned", func(t *testing.T) {
assignedRequirements := core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse("200m"),
core.ResourceMemory: resource.MustParse("200Mi"),
core.ResourceCPU: resource.MustParse("100m"),
core.ResourceMemory: resource.MustParse("128Mi"),
},
}
s.Mode.Sidecar.Resources = &sharedApi.Resources{Resources: &assignedRequirements}

expectedRequirements := core.ResourceRequirements{
Requests: assignedRequirements.Requests,
Limits: core.ResourceList{
core.ResourceCPU: resource.MustParse("200m"),
core.ResourceMemory: resource.MustParse("200Mi"),
core.ResourceCPU: resource.MustParse("100m"),
core.ResourceMemory: resource.MustParse("128Mi"),
},
}

Expand Down
16 changes: 3 additions & 13 deletions pkg/apis/shared/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"fmt"
"regexp"

"github.com/google/uuid"
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/strings"
)

var (
Expand Down Expand Up @@ -62,18 +62,8 @@ func ValidateOptionalResourceName(name string) error {

// ValidateUID validates if it is valid Kubernetes UID
func ValidateUID(uid types.UID) error {
v := strings.Split(string(uid), "-")

if len(v) != 0 &&
len(v[0]) != 6 &&
len(v[1]) != 4 &&
len(v[2]) != 4 &&
len(v[3]) != 4 &&
len(v[4]) != 6 {
return errors.Newf("Invalid UID: %s", uid)
}

return nil
_, err := uuid.Parse(string(uid))
return err
}

// ValidatePullPolicy Validates core.PullPolicy
Expand Down