25 lines
819 B
Go
25 lines
819 B
Go
package vendor
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestRenameLabelEntriesKeepsLabels(t *testing.T) {
|
||
|
|
dir := t.TempDir()
|
||
|
|
p := filepath.Join(dir, "agent-lib.labels.json")
|
||
|
|
os.WriteFile(p, []byte(`{"version":1,"labels":{"sales":["old-name","other"],"dev":["old-name"]}}`), 0o644)
|
||
|
|
n, err := renameLabelEntries(dir, map[string]string{"old-name": "new-name"})
|
||
|
|
if err != nil || n != 2 {
|
||
|
|
t.Fatalf("want 2 entries renamed, got %d, %v", n, err)
|
||
|
|
}
|
||
|
|
data, _ := os.ReadFile(p)
|
||
|
|
if strings.Contains(string(data), "old-name") || strings.Count(string(data), "new-name") != 2 {
|
||
|
|
t.Errorf("entries not rewritten:\n%s", data)
|
||
|
|
}
|
||
|
|
if n, err := renameLabelEntries(t.TempDir(), map[string]string{"a": "b"}); err != nil || n != 0 {
|
||
|
|
t.Errorf("missing labels file must be a no-op, got %d, %v", n, err)
|
||
|
|
}
|
||
|
|
}
|