Skip to content

Commit

Permalink
fix: Add name flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaansehgal99 committed Mar 20, 2024
1 parent b2e2b26 commit 6c347c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 7 additions & 2 deletions api/v1alpha1/workspace_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (w *Workspace) Validate(ctx context.Context) (errs *apis.FieldError) {
w.Resource.validateCreate(*w.Inference).ViaField("resource"),
)
if w.Inference != nil {
// TODO: Add Adapter Spec Validation - Including DataSource Validation for Adapter
errs = errs.Also(w.Inference.validateCreate().ViaField("inference"))
}
if w.Tuning != nil {
Expand All @@ -54,6 +55,7 @@ func (w *Workspace) Validate(ctx context.Context) (errs *apis.FieldError) {
w.Resource.validateUpdate(&old.Resource).ViaField("resource"),
)
if w.Inference != nil {
// TODO: Add Adapter Spec Validation - Including DataSource Validation for Adapter
errs = errs.Also(w.Inference.validateUpdate(old.Inference).ViaField("inference"))
}
if w.Tuning != nil {
Expand Down Expand Up @@ -112,7 +114,7 @@ func (r *TuningSpec) validateUpdate(old *TuningSpec) (errs *apis.FieldError) {
if r.Input == nil {
errs = errs.Also(apis.ErrMissingField("Input"))
} else {
errs = errs.Also(r.Input.validateUpdate(old.Input).ViaField("Input"))
errs = errs.Also(r.Input.validateUpdate(old.Input, true).ViaField("Input"))
}
if r.Output == nil {
errs = errs.Also(apis.ErrMissingField("Output"))
Expand Down Expand Up @@ -150,7 +152,10 @@ func (r *DataSource) validateCreate() (errs *apis.FieldError) {
return errs
}

func (r *DataSource) validateUpdate(old *DataSource) (errs *apis.FieldError) {
func (r *DataSource) validateUpdate(old *DataSource, isTuning bool) (errs *apis.FieldError) {
if isTuning && !reflect.DeepEqual(old.Name, r.Name) {
errs = errs.Also(apis.ErrInvalidValue("During tuning Name field cannot be changed once set", "Name"))
}
oldURLs := make([]string, len(old.URLs))
copy(oldURLs, old.URLs)
sort.Strings(oldURLs)
Expand Down
13 changes: 12 additions & 1 deletion api/v1alpha1/workspace_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,17 @@ func TestDataSourceValidateUpdate(t *testing.T) {
},
wantErr: false,
},
{
name: "Name changed",
oldSource: &DataSource{
Name: "original-dataset",
},
newSource: &DataSource{
Name: "new-dataset",
},
wantErr: true,
errFields: []string{"Name"},
},
{
name: "URLs changed",
oldSource: &DataSource{
Expand Down Expand Up @@ -946,7 +957,7 @@ func TestDataSourceValidateUpdate(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
errs := tt.newSource.validateUpdate(tt.oldSource)
errs := tt.newSource.validateUpdate(tt.oldSource, true)
hasErrs := errs != nil

if hasErrs != tt.wantErr {
Expand Down

0 comments on commit 6c347c9

Please sign in to comment.