@@ -2788,78 +2788,65 @@ func (s *BlockBlobUnrecordedTestsSuite) TestListBlobReturnsTags() {
2788
2788
}
2789
2789
}
2790
2790
2791
- // func (s *BlockBlobUnrecordedTestsSuite) TestFindBlobsByTags() {
2792
- // _require := require.New(s.T())
2793
- // testName := s.T().Name()
2794
- // _context := getTestContext(testName)
2795
- // ignoreHeaders(_context.recording, []string{"x-ms-tags", "X-Ms-Tags"})
2796
- // svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
2797
- // if err != nil {
2798
- // s.Fail("Unable to fetch service client because " + err.Error())
2799
- // }
2800
- //
2801
- // containerClient1 := testcommon.CreateNewContainer(context.Background(), _require, testcommon.GenerateContainerName(testName) + "1", svcClient)
2802
- // defer testcommon.DeleteContainer(context.Background(), _require, containerClient1)
2803
- //
2804
- // containerClient2 := testcommon.CreateNewContainer(context.Background(), _require, testcommon.GenerateContainerName(testName) + "2", svcClient)
2805
- // defer testcommon.DeleteContainer(context.Background(), _require, containerClient2)
2806
- //
2807
- // containerClient3 := testcommon.CreateNewContainer(context.Background(), _require, testcommon.GenerateContainerName(testName) + "3", svcClient)
2808
- // defer testcommon.DeleteContainer(context.Background(), _require, containerClient3)
2809
- //
2810
- // blobTagsMap1 := map[string]string{
2811
- // "tag2": "tagsecond",
2812
- // "tag3": "tagthird",
2813
- // }
2814
- // blobTagsMap2 := map[string]string{
2815
- // "tag1": "firsttag",
2816
- // "tag2": "secondtag",
2817
- // "tag3": "thirdtag",
2818
- // }
2819
- //
2820
- // blobURL11 := testcommon.GetBlockBlobClient(testcommon.GenerateBlobName(testName) + "11", containerClient1)
2821
- // _, err = blobURL11.Upload(context.Background(), bytes.NewReader([]byte("random data")), &blockblob.UploadOptions{
2822
- // Metadata: testcommon.BasicMetadata,
2823
- // Tags: blobTagsMap1,
2824
- // })
2825
- // _require.Nil(err)
2826
- //
2827
- // blobURL12 := testcommon.GetBlockBlobClient(testcommon.GenerateBlobName(testName) + "12", containerClient1)
2828
- // _, err = blobURL12.Upload(context.Background(), bytes.NewReader([]byte("another random data")), &blockblob.UploadOptions{
2829
- // Metadata: testcommon.BasicMetadata,
2830
- // Tags: blobTagsMap2,
2831
- // })
2832
- // _require.Nil(err)
2833
- //
2834
- // blobURL21 := testcommon.GetBlockBlobClient(testcommon.GenerateBlobName(testName) + "21", containerClient2)
2835
- // _, err = blobURL21.Upload(context.Background(), bytes.NewReader([]byte("random data")), HTTPHeaders{}, testcommon.BasicMetadata, LeaseAccessConditions{}, DefaultAccessTier, nil, ClientProvidedKeyOptions{})
2836
- // _require.Nil(err)
2837
- //
2838
- // blobURL22 := testcommon.GetBlockBlobClient(testcommon.GenerateBlobName(testName) + "22", containerClient2)
2839
- // _, err = blobURL22.Upload(context.Background(), bytes.NewReader([]byte("another random data")), HTTPHeaders{}, testcommon.BasicMetadata, LeaseAccessConditions{}, DefaultAccessTier, blobTagsMap2, ClientProvidedKeyOptions{})
2840
- // _require.Nil(err)
2841
- //
2842
- // blobURL31 := testcommon.GetBlockBlobClient(testcommon.GenerateBlobName(testName) + "31", containerClient3)
2843
- // _, err = blobURL31.Upload(context.Background(), bytes.NewReader([]byte("random data")), HTTPHeaders{}, testcommon.BasicMetadata, LeaseAccessConditions{}, DefaultAccessTier, nil, ClientProvidedKeyOptions{})
2844
- // _require.Nil(err)
2845
- //
2846
- // where := "\"tag4\"='fourthtag'"
2847
- // lResp, err := svcClient.FindBlobByTags(context.Background(), nil, nil, &where, Marker{}, nil)
2848
- // _require.Nil(err)
2849
- // _assert(lResp.Blobs, chk.HasLen, 0)
2850
- //
2851
- // //where = "\"tag1\"='firsttag'AND\"tag2\"='secondtag'AND\"@container\"='"+ containerName1 + "'"
2852
- // //TODO: Figure out how to do a composite query based on container.
2853
- // where = "\"tag1\"='firsttag'AND\"tag2\"='secondtag'"
2854
- //
2855
- // lResp, err = svcClient.FindBlobsByTags(context.Background(), nil, nil, &where, Marker{}, nil)
2856
- // _require.Nil(err)
2857
- //
2858
- // for _, blob := range lResp.Blobs {
2859
- // _assert(blob.TagValue, chk.Equals, "firsttag")
2860
- // }
2861
- // }
2862
- //
2791
+ func (s * BlockBlobUnrecordedTestsSuite ) TestFilterBlobsWithTags () {
2792
+ _require := require .New (s .T ())
2793
+ testName := s .T ().Name ()
2794
+ svcClient , err := testcommon .GetServiceClient (s .T (), testcommon .TestAccountDefault , nil )
2795
+ _require .NoError (err )
2796
+
2797
+ containerClient := testcommon .CreateNewContainer (context .Background (), _require , testcommon .GenerateContainerName (testName )+ "1" , svcClient )
2798
+ defer testcommon .DeleteContainer (context .Background (), _require , containerClient )
2799
+
2800
+ blobTagsMap1 := map [string ]string {
2801
+ "tag2" : "tagsecond" ,
2802
+ "tag3" : "tagthird" ,
2803
+ }
2804
+ blobTagsMap2 := map [string ]string {
2805
+ "tag1" : "firsttag" ,
2806
+ "tag2" : "secondtag" ,
2807
+ "tag3" : "thirdtag" ,
2808
+ "tag key" : "tag value" , // tags with spaces
2809
+ }
2810
+
2811
+ blobName1 := testcommon .GenerateBlobName (testName ) + "1"
2812
+ blobClient1 := testcommon .CreateNewBlockBlob (context .Background (), _require , blobName1 , containerClient )
2813
+ _ , err = blobClient1 .SetTags (context .Background (), blobTagsMap1 , nil )
2814
+ _require .Nil (err )
2815
+
2816
+ blobName2 := testcommon .GenerateBlobName (testName ) + "2"
2817
+ blobClient2 := testcommon .CreateNewBlockBlob (context .Background (), _require , blobName2 , containerClient )
2818
+ _ , err = blobClient2 .SetTags (context .Background (), blobTagsMap2 , nil )
2819
+ _require .Nil (err )
2820
+ time .Sleep (10 * time .Second )
2821
+
2822
+ blobTagsResp , err := blobClient2 .GetTags (context .Background (), nil )
2823
+ _require .Nil (err )
2824
+ blobTagsSet := blobTagsResp .BlobTagSet
2825
+ _require .NotNil (blobTagsSet )
2826
+
2827
+ // Test invalid tag
2828
+ where := "\" tag4\" ='fourthtag'"
2829
+ lResp , err := svcClient .FilterBlobs (context .Background (), & service.FilterBlobsOptions {Where : & where })
2830
+ _require .Nil (err )
2831
+ _require .Equal (len (lResp .Blobs ), 0 )
2832
+
2833
+ // Test multiple valid tags
2834
+ where = "\" tag1\" ='firsttag'AND\" tag2\" ='secondtag'"
2835
+ // where := "foo=\"value 1\""
2836
+ lResp , err = svcClient .FilterBlobs (context .Background (), & service.FilterBlobsOptions {Where : & where })
2837
+ _require .Nil (err )
2838
+ _require .Len (lResp .FilterBlobSegment .Blobs [0 ].Tags .BlobTagSet , 2 )
2839
+ _require .Equal (lResp .FilterBlobSegment .Blobs [0 ].Tags .BlobTagSet [0 ], blobTagsSet [1 ])
2840
+ _require .Equal (lResp .FilterBlobSegment .Blobs [0 ].Tags .BlobTagSet [1 ], blobTagsSet [2 ])
2841
+
2842
+ // Test tags with spaces
2843
+ where = "\" tag key\" ='tag value'"
2844
+ lResp , err = svcClient .FilterBlobs (context .Background (), & service.FilterBlobsOptions {Where : & where })
2845
+ _require .Nil (err )
2846
+ _require .Len (lResp .FilterBlobSegment .Blobs [0 ].Tags .BlobTagSet , 1 )
2847
+ _require .Equal (lResp .FilterBlobSegment .Blobs [0 ].Tags .BlobTagSet [0 ], blobTagsSet [0 ])
2848
+
2849
+ }
2863
2850
2864
2851
// func (s *BlockBlobUnrecordedTestsSuite) TestFilterBlobsUsingAccountSAS() {
2865
2852
// accountName, accountKey := accountInfo()
0 commit comments