-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a99a1e
commit 18cdb09
Showing
9 changed files
with
85 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package metric | ||
|
||
import "strings" | ||
|
||
func AppendNamespace(prefix, suffix string) string { | ||
switch { | ||
case len(prefix) == 0: | ||
return suffix | ||
case len(suffix) == 0: | ||
return prefix | ||
default: | ||
return strings.Join([]string{prefix, suffix}, "_") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package metric | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAppendNamespace(t *testing.T) { | ||
tests := []struct { | ||
prefix string | ||
suffix string | ||
expected string | ||
}{ | ||
{ | ||
prefix: "avalanchego", | ||
suffix: "isgreat", | ||
expected: "avalanchego_isgreat", | ||
}, | ||
{ | ||
prefix: "", | ||
suffix: "sucks", | ||
expected: "sucks", | ||
}, | ||
{ | ||
prefix: "sucks", | ||
suffix: "", | ||
expected: "sucks", | ||
}, | ||
{ | ||
prefix: "", | ||
suffix: "", | ||
expected: "", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(strings.Join([]string{test.prefix, test.suffix}, "_"), func(t *testing.T) { | ||
namespace := AppendNamespace(test.prefix, test.suffix) | ||
require.Equal(t, test.expected, namespace) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters