Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Method get_string() should return a namespace leading by separator character #66

Description

@IzabellaRaulin

Method get_string() should return a namespace leading by separator to keep parity with snap-plugin-lib-go and snap-plugin-lib-py

For metric ["intel", "mock", "metric"] with "/" as a separator, executing mt.ns().get_string() returns:

Current behaviour Expected behaviour
intel/mock/metric /intel/mock/metric

Why this is important

To avoid adding leading separator in plugin, for example how it happens in pull request to rdt collector

Code in snap-plugin-lib-cpp:
No leading separator added

const std::string Namespace::get_string() const {
    std::stringstream ss;
    int i = 1;
    for (const auto& node : namespace_elements) {
        if (i < namespace_elements.size()) ss << node.get_value() << "/";
        if (i == namespace_elements.size()) ss << node.get_value();
        i++;
    }
    return ss.str();
}

Code in snap-plugin-lib-go:

func (n Namespace) String() string {
	ns := n.Strings()
	s := n.getSeparator()
	return s + strings.Join(ns, s)
}

Code in snap-plugin-lib-py:

[...]
        result = separator
        for n in self:
            result += n.value + separator
        return result[:-1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions