github.com/weaviate/weaviate@v1.24.6/adapters/repos/classifications/repo_integration_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  //go:build integrationTest
    13  // +build integrationTest
    14  
    15  package classifications
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	"github.com/sirupsen/logrus/hooks/test"
    22  	"github.com/stretchr/testify/assert"
    23  	"github.com/stretchr/testify/require"
    24  	"github.com/weaviate/weaviate/entities/models"
    25  )
    26  
    27  func Test_ClassificationsRepo(t *testing.T) {
    28  	dirName := t.TempDir()
    29  
    30  	logger, _ := test.NewNullLogger()
    31  
    32  	r, err := NewRepo(dirName, logger)
    33  	require.Nil(t, err)
    34  	_ = r
    35  
    36  	t.Run("asking for a non-existing classification", func(t *testing.T) {
    37  		res, err := r.Get(context.Background(), "wrong-id")
    38  		require.Nil(t, err)
    39  		assert.Nil(t, res)
    40  	})
    41  
    42  	t.Run("storing classifications", func(t *testing.T) {
    43  		err := r.Put(context.Background(), exampleOne())
    44  		require.Nil(t, err)
    45  
    46  		err = r.Put(context.Background(), exampleTwo())
    47  		require.Nil(t, err)
    48  	})
    49  
    50  	t.Run("retrieving stored classifications", func(t *testing.T) {
    51  		expectedOne := exampleOne()
    52  		expectedTwo := exampleTwo()
    53  
    54  		res, err := r.Get(context.Background(), expectedOne.ID)
    55  		require.Nil(t, err)
    56  		assert.Equal(t, &expectedOne, res)
    57  
    58  		res, err = r.Get(context.Background(), expectedTwo.ID)
    59  		require.Nil(t, err)
    60  		assert.Equal(t, &expectedTwo, res)
    61  	})
    62  }
    63  
    64  func exampleOne() models.Classification {
    65  	return models.Classification{
    66  		ID:                "01ed111a-919c-4dd5-ab9e-7b247b11e18c",
    67  		Class:             "ExampleClassOne",
    68  		BasedOnProperties: []string{"prop1"},
    69  	}
    70  }
    71  
    72  func exampleTwo() models.Classification {
    73  	return models.Classification{
    74  		ID:                "4fbaebf3-41a9-414b-ac1d-433d74d4ef2c",
    75  		Class:             "ExampleClassTwo",
    76  		BasedOnProperties: []string{"prop2"},
    77  	}
    78  }