mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 01:12:24 +08:00
add tests for path parsing
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
30
path/path_test.go
Normal file
30
path/path_test.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package path
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPathParsing(t *testing.T) {
|
||||||
|
cases := map[string]bool{
|
||||||
|
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": true,
|
||||||
|
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a": true,
|
||||||
|
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f": true,
|
||||||
|
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f": true,
|
||||||
|
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": true,
|
||||||
|
"QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f": true,
|
||||||
|
"QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": true,
|
||||||
|
"/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": false,
|
||||||
|
"/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a": false,
|
||||||
|
"/ipfs/": false,
|
||||||
|
"ipfs/": false,
|
||||||
|
"ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": false,
|
||||||
|
}
|
||||||
|
|
||||||
|
for p, expected := range cases {
|
||||||
|
_, err := ParsePath(p)
|
||||||
|
valid := (err == nil)
|
||||||
|
if valid != expected {
|
||||||
|
t.Fatalf("expected %s to have valid == %s", p, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user