github.com/weaviate/weaviate@v1.24.6/usecases/objects/validation/model_validation_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package validation
    13  
    14  import (
    15  	"context"
    16  	"strings"
    17  	"testing"
    18  
    19  	"github.com/go-openapi/strfmt"
    20  
    21  	"github.com/stretchr/testify/require"
    22  	"github.com/weaviate/weaviate/entities/models"
    23  	"github.com/weaviate/weaviate/usecases/config"
    24  )
    25  
    26  const BEACON = "weaviate://localhost/"
    27  
    28  var (
    29  	UuidUpper = "4E5CD755-4F43-44C5-B23C-0C7D6F6C21E6"
    30  	UuidLower = strings.ToLower(UuidUpper)
    31  )
    32  
    33  func TestValidationReferencesInObject(t *testing.T) {
    34  	validator := New(fakeExists, &config.WeaviateConfig{}, nil)
    35  
    36  	class := &models.Class{
    37  		Class: "From",
    38  		Properties: []*models.Property{
    39  			{Name: "ref", DataType: []string{"To"}},
    40  		},
    41  	}
    42  
    43  	obj := &models.Object{
    44  		Class: "From",
    45  		Properties: map[string]interface{}{
    46  			"ref": []interface{}{
    47  				map[string]interface{}{"beacon": BEACON + "To/" + UuidUpper},
    48  			},
    49  		},
    50  	}
    51  
    52  	err := validator.properties(context.Background(), class, obj, nil)
    53  	require.Nil(t, err)
    54  	require.Equal(t, obj.Properties.(map[string]interface{})["ref"].(models.MultipleRef)[0].Beacon.String(), BEACON+"To/"+UuidLower)
    55  }
    56  
    57  func TestValidationReference(t *testing.T) {
    58  	validator := New(fakeExists, &config.WeaviateConfig{}, nil)
    59  
    60  	cref := &models.SingleRef{Beacon: strfmt.URI(BEACON + "To/" + UuidUpper)}
    61  	ref, err := validator.ValidateSingleRef(cref)
    62  	require.Nil(t, err)
    63  	require.Equal(t, ref.TargetID.String(), UuidLower)
    64  }