github.com/weaviate/weaviate@v1.24.6/usecases/config/auto_schema_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 config
    13  
    14  import (
    15  	"fmt"
    16  	"testing"
    17  
    18  	"github.com/stretchr/testify/assert"
    19  	"github.com/weaviate/weaviate/entities/schema"
    20  )
    21  
    22  func TestConfig_AutoSchema(t *testing.T) {
    23  	t.Run("invalid DefaultNumber", func(t *testing.T) {
    24  		auth := AutoSchema{
    25  			DefaultNumber: "float",
    26  			DefaultString: schema.DataTypeText.String(),
    27  			DefaultDate:   "date",
    28  		}
    29  		expected := fmt.Errorf("autoSchema.defaultNumber must be either 'int' or 'number")
    30  		err := auth.Validate()
    31  		assert.Equal(t, expected, err)
    32  	})
    33  
    34  	t.Run("invalid DefaultString", func(t *testing.T) {
    35  		auth := AutoSchema{
    36  			DefaultNumber: "int",
    37  			DefaultString: "body",
    38  			DefaultDate:   "date",
    39  		}
    40  		expected := fmt.Errorf("autoSchema.defaultString must be either 'string' or 'text")
    41  		err := auth.Validate()
    42  		assert.Equal(t, expected, err)
    43  	})
    44  
    45  	t.Run("invalid DefaultDate", func(t *testing.T) {
    46  		auth := AutoSchema{
    47  			DefaultNumber: "int",
    48  			DefaultString: schema.DataTypeText.String(),
    49  			DefaultDate:   "int",
    50  		}
    51  		expected := fmt.Errorf("autoSchema.defaultDate must be either 'date' or 'string' or 'text")
    52  		err := auth.Validate()
    53  		assert.Equal(t, expected, err)
    54  	})
    55  
    56  	t.Run("all valid AutoSchema configurations", func(t *testing.T) {
    57  		auth := AutoSchema{
    58  			DefaultNumber: "int",
    59  			DefaultString: schema.DataTypeText.String(),
    60  			DefaultDate:   "date",
    61  		}
    62  		err := auth.Validate()
    63  		assert.Nil(t, err, "should not error")
    64  	})
    65  }