github.com/m3db/m3@v1.5.0/src/query/test/tag_utils.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package test
    22  
    23  import (
    24  	"github.com/m3db/m3/src/query/models"
    25  )
    26  
    27  // StringTagsToTags converts string tags to tags.
    28  func StringTagsToTags(s StringTags) models.Tags {
    29  	tags := models.NewTags(len(s), models.NewTagOptions())
    30  	for _, t := range s {
    31  		tags = tags.AddTag(models.Tag{Name: []byte(t.N), Value: []byte(t.V)})
    32  	}
    33  
    34  	return tags
    35  }
    36  
    37  // StringTagsSliceToTagSlice converts a slice of string tags to a slice of tags.
    38  func StringTagsSliceToTagSlice(s []StringTags) []models.Tags {
    39  	tags := make([]models.Tags, len(s))
    40  
    41  	for i, stringTags := range s {
    42  		tags[i] = StringTagsToTags(stringTags)
    43  	}
    44  
    45  	return tags
    46  }
    47  
    48  // StringTags is a slice of string tags.
    49  type StringTags []StringTag
    50  
    51  // StringTag is a tag containing string key value pairs.
    52  type StringTag struct {
    53  	N, V string
    54  }
    55  
    56  // TagSliceToTags converts a slice of tags to tags.
    57  func TagSliceToTags(s []models.Tag) models.Tags {
    58  	tags := models.EmptyTags()
    59  	for _, t := range s {
    60  		tags = tags.AddTag(t)
    61  	}
    62  
    63  	return tags
    64  }
    65  
    66  // TagSliceSliceToTagSlice converts a slice of tag slices to a slice of tags.
    67  func TagSliceSliceToTagSlice(s [][]models.Tag) []models.Tags {
    68  	tags := make([]models.Tags, len(s))
    69  
    70  	for i, t := range s {
    71  		tags[i] = TagSliceToTags(t)
    72  	}
    73  
    74  	return tags
    75  }