@@ -26,7 +26,9 @@ func Test_chroma_client(t *testing.T) {
26
26
if chromaURL == "" {
27
27
chromaURL = "http://localhost:8000"
28
28
}
29
- client := chroma .NewClient (chromaURL )
29
+
30
+ clientConfig := chroma .NewClientConfig (chromaURL , nil , nil )
31
+ client := chroma .NewClient (clientConfig )
30
32
31
33
t .Run ("Test Heartbeat" , func (t * testing.T ) {
32
34
resp , err := client .Heartbeat ()
@@ -746,3 +748,106 @@ func Test_chroma_client(t *testing.T) {
746
748
require .Nil (t , addError )
747
749
})
748
750
}
751
+
752
+ func Test_chroma_client_with_basic (t * testing.T ) {
753
+ chromaURL := os .Getenv ("CHROMA_URL" )
754
+ if chromaURL == "" {
755
+ chromaURL = "http://localhost:8003"
756
+ }
757
+ clientAuth := chroma .NewBasicAuth ("test" , "test" )
758
+
759
+ clientConfig := chroma .NewClientConfig (chromaURL , nil , & clientAuth )
760
+ client := chroma .NewClient (clientConfig )
761
+
762
+ t .Run ("Test Heartbeat" , func (t * testing.T ) {
763
+ resp , err := client .Heartbeat ()
764
+
765
+ require .Nil (t , err )
766
+ require .NotNil (t , resp )
767
+ assert .Truef (t , resp ["nanosecond heartbeat" ] > 0 , "Heartbeat should be greater than 0" )
768
+ })
769
+ }
770
+
771
+ func Test_chroma_client_with_authorization_token (t * testing.T ) {
772
+ chromaURL := os .Getenv ("CHROMA_URL" )
773
+ if chromaURL == "" {
774
+ chromaURL = "http://localhost:8001"
775
+ }
776
+ clientAuth := chroma .NewTokenAuth ("test" , chroma .TokenAuthorization )
777
+
778
+ clientConfig := chroma .NewClientConfig (chromaURL , nil , & clientAuth )
779
+ client := chroma .NewClient (clientConfig )
780
+
781
+ t .Run ("Test List Collections" , func (t * testing.T ) {
782
+ collectionName1 := "test-collection1"
783
+ collectionName2 := "test-collection2"
784
+ metadata := map [string ]string {}
785
+ apiKey := os .Getenv ("OPENAI_API_KEY" )
786
+ if apiKey == "" {
787
+ err := godotenv .Load ("../.env" )
788
+ if err != nil {
789
+ assert .Failf (t , "Error loading .env file" , "%s" , err )
790
+ }
791
+ apiKey = os .Getenv ("OPENAI_API_KEY" )
792
+ }
793
+ embeddingFunction := openai .NewOpenAIEmbeddingFunction (apiKey )
794
+ distanceFunction := chroma .L2
795
+ _ , errRest := client .Reset ()
796
+ if errRest != nil {
797
+ assert .Fail (t , fmt .Sprintf ("Error resetting database: %s" , errRest ))
798
+ }
799
+ _ , _ = client .CreateCollection (collectionName1 , chroma .MapToAPI (metadata ), true , embeddingFunction , distanceFunction )
800
+ _ , _ = client .CreateCollection (collectionName2 , chroma .MapToAPI (metadata ), true , embeddingFunction , distanceFunction )
801
+ collections , gcerr := client .ListCollections ()
802
+ require .Nil (t , gcerr )
803
+ assert .Equal (t , 2 , len (collections ))
804
+ names := make ([]string , len (collections ))
805
+ for i , person := range collections {
806
+ names [i ] = person .Name
807
+ }
808
+ assert .Contains (t , names , collectionName1 )
809
+ assert .Contains (t , names , collectionName2 )
810
+ })
811
+ }
812
+
813
+ func Test_chroma_client_with_x_token (t * testing.T ) {
814
+ chromaURL := os .Getenv ("CHROMA_URL" )
815
+ if chromaURL == "" {
816
+ chromaURL = "http://localhost:8002"
817
+ }
818
+ clientAuth := chroma .NewTokenAuth ("test" , chroma .TokenXChromaToken )
819
+
820
+ clientConfig := chroma .NewClientConfig (chromaURL , nil , & clientAuth )
821
+ client := chroma .NewClient (clientConfig )
822
+
823
+ t .Run ("Test List Collections" , func (t * testing.T ) {
824
+ collectionName1 := "test-collection1"
825
+ collectionName2 := "test-collection2"
826
+ metadata := map [string ]string {}
827
+ apiKey := os .Getenv ("OPENAI_API_KEY" )
828
+ if apiKey == "" {
829
+ err := godotenv .Load ("../.env" )
830
+ if err != nil {
831
+ assert .Failf (t , "Error loading .env file" , "%s" , err )
832
+ }
833
+ apiKey = os .Getenv ("OPENAI_API_KEY" )
834
+ }
835
+ embeddingFunction := openai .NewOpenAIEmbeddingFunction (apiKey )
836
+ distanceFunction := chroma .L2
837
+ _ , errRest := client .Reset ()
838
+ if errRest != nil {
839
+ assert .Fail (t , fmt .Sprintf ("Error resetting database: %s" , errRest ))
840
+ }
841
+ _ , _ = client .CreateCollection (collectionName1 , chroma .MapToAPI (metadata ), true , embeddingFunction , distanceFunction )
842
+ _ , _ = client .CreateCollection (collectionName2 , chroma .MapToAPI (metadata ), true , embeddingFunction , distanceFunction )
843
+ collections , gcerr := client .ListCollections ()
844
+ require .Nil (t , gcerr )
845
+ assert .Equal (t , 2 , len (collections ))
846
+ names := make ([]string , len (collections ))
847
+ for i , person := range collections {
848
+ names [i ] = person .Name
849
+ }
850
+ assert .Contains (t , names , collectionName1 )
851
+ assert .Contains (t , names , collectionName2 )
852
+ })
853
+ }
0 commit comments