cidbase_test.go 686 Bytes
Newer Older
1 2 3 4 5 6 7 8
package cmdenv

import (
	"testing"
)

func TestExtractCidString(t *testing.T) {
	test := func(path string, cid string) {
9 10 11
		res := extractCidString(path)
		if res != cid {
			t.Errorf("extractCidString(%s) failed: expected '%s' but got '%s'", path, cid, res)
12 13 14 15 16 17 18 19 20 21 22
		}
	}
	p := "QmRqVG8VGdKZ7KARqR96MV7VNHgWvEQifk94br5HpURpfu"
	test(p, p)
	test("/ipfs/"+p, p)

	p = "zb2rhfkM4FjkMLaUnygwhuqkETzbYXnUDf1P9MSmdNjW1w1Lk"
	test(p, p)
	test("/ipfs/"+p, p)
	test("/ipld/"+p, p)

23 24 25 26 27 28 29
	p = "bafyreifrcnyjokuw4i4ggkzg534tjlc25lqgt3ttznflmyv5fftdgu52hm"
	test(p, p)
	test("/ipfs/"+p, p)
	test("/ipld/"+p, p)

	// an error is also acceptable in future versions of extractCidString
	test("/ipfs", "/ipfs")
30
}