39 lines
1007 B
Go
39 lines
1007 B
Go
|
|
package notarius
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestLaneRelativePath(t *testing.T) {
|
||
|
|
for _, test := range []struct{ id, want string }{
|
||
|
|
{"npc-registry", "lanes/npc-registry.json"},
|
||
|
|
{" a/b..c ", "lanes/a_b__c.json"},
|
||
|
|
{"._...", ""},
|
||
|
|
} {
|
||
|
|
got, err := LaneRelativePath(test.id)
|
||
|
|
if got != test.want || (err != nil) != (test.want == "") {
|
||
|
|
t.Errorf("LaneRelativePath(%q) = %q, %v", test.id, got, err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestResolveExecutableUsesExplicitPathAndSearchPath(t *testing.T) {
|
||
|
|
dir := t.TempDir()
|
||
|
|
binary := filepath.Join(dir, "notarius-test")
|
||
|
|
if err := os.WriteFile(binary, []byte("#!/bin/sh\nexit 0\n"), 0755); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
t.Setenv("PATH", dir)
|
||
|
|
for _, value := range []string{binary, "notarius-test"} {
|
||
|
|
got, err := ResolveExecutable(value)
|
||
|
|
if err != nil || got != binary {
|
||
|
|
t.Fatalf("resolve %q = %q, %v", value, got, err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, err := ResolveExecutable("missing-notarius"); err == nil {
|
||
|
|
t.Fatal("missing binary was accepted")
|
||
|
|
}
|
||
|
|
}
|