Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ func InitTag(key, value string) *common.Tag {

// AddTag
func AddTag(key, value string, tags *common.Tags) {
if tags == nil {
return
}
tags.Tags = append(tags.GetTags(), InitTag(key, value))
}

// DeleteTag
func DeleteTag(key string, tags *common.Tags) {
if tags == nil {
return
}
index := -1
tagsList := tags.GetTags()
for idx, tag := range tagsList {
Expand Down Expand Up @@ -49,6 +55,9 @@ func GetTagValue(key string, tags *common.Tags) (string, error) {

// AddTagValue
func AddTagValue(key, value string, tags *common.Tags) {
if tags == nil {
return
}
for _, tag := range tags.GetTags() {
if tag.GetKey() == key {
tag.Value = value
Expand Down
26 changes: 26 additions & 0 deletions pkg/tags/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ func TestAddTagValue(t *testing.T) {
t.Logf("%s", value)
}

func TestAddTagNilTags(t *testing.T) {
// Verify AddTag does not panic when tags is nil
AddTag("testkey", "testvalue", nil)
}

func TestAddTagValueNilTags(t *testing.T) {
// Verify AddTagValue does not panic when tags is nil
AddTagValue("testkey", "testvalue", nil)
}

func TestDeleteTagNilTags(t *testing.T) {
// Verify DeleteTag does not panic when tags is nil
DeleteTag("testkey", nil)
}

func TestGetTagValueNilTags(t *testing.T) {
// GetTagValue should return NotFound for nil tags
_, err := GetTagValue("testkey", nil)
if err == nil {
t.Errorf("Expected error for nil tags")
}
if !errors.IsNotFound(err) {
t.Errorf("Expected NotFound error for nil tags")
}
}

func TestProtoToMap(t *testing.T) {
tags := &common.Tags{}
AddTagValue("testkey", "testvalue", tags)
Expand Down
Loading