Skip to content

Commit

Permalink
feat(tests): improved tests coverage unit/integration (#177)
Browse files Browse the repository at this point in the history
* feat(tests): improved tests coverage unit/integration

Signed-off-by: Alessio Pragliola <seth.pro@gmail.com>

* fix(ci): missing folder in Dockerfile

Signed-off-by: Alessio Pragliola <seth.pro@gmail.com>

---------

Signed-off-by: Alessio Pragliola <seth.pro@gmail.com>
  • Loading branch information
Al-Pragliola authored Feb 5, 2025
1 parent ff22865 commit 21c0883
Show file tree
Hide file tree
Showing 19 changed files with 1,444 additions and 367 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN go mod download
# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
COPY internal/ internal/

# Copy Makefile and build command requirements
COPY config/ config/
Expand Down
64 changes: 64 additions & 0 deletions api/v1alpha1/modelregistry_annotations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package v1alpha1_test

import (
"reflect"
"testing"

"github.com/opendatahub-io/model-registry-operator/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestHandleAnnotations(t *testing.T) {
tests := []struct {
name string
annotations map[string]string
wantAnnotations map[string]string
mrRestImage string
wantMrRestImage string
}{
{
name: "no handler annotations",
annotations: map[string]string{
"modelregistry.opendatahub.io/other-annotation": "true",
},
wantAnnotations: map[string]string{
"modelregistry.opendatahub.io/other-annotation": "true",
},
mrRestImage: "test",
wantMrRestImage: "test",
},
{
name: "reset defaults",
annotations: map[string]string{
"modelregistry.opendatahub.io/reset-spec-defaults": "",
},
wantAnnotations: map[string]string{},
mrRestImage: "test",
wantMrRestImage: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mr := &v1alpha1.ModelRegistry{
ObjectMeta: metav1.ObjectMeta{
Annotations: tt.annotations,
},
Spec: v1alpha1.ModelRegistrySpec{
Rest: v1alpha1.RestSpec{
Image: tt.mrRestImage,
},
},
}
mr.HandleAnnotations()

if !reflect.DeepEqual(mr.GetAnnotations(), tt.wantAnnotations) {
t.Errorf("HandleAnnotations() = %v, want %v", mr.GetAnnotations(), tt.wantAnnotations)
}

if mr.Spec.Rest.Image != tt.wantMrRestImage {
t.Errorf("HandleAnnotations() = %v, want %v", mr.Name, tt.wantMrRestImage)
}
})
}
}
7 changes: 4 additions & 3 deletions api/v1alpha1/modelregistry_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ package v1alpha1
import (
"context"
"fmt"
"maps"
"slices"
"strings"

"github.com/opendatahub-io/model-registry-operator/internal/controller/config"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
"maps"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
"slices"
"strings"
)

// log is for logging in this package.
Expand Down
Loading

0 comments on commit 21c0883

Please sign in to comment.