Skip to content

Commit cc2ccd0

Browse files
committed
test: Import.UnixFSRawLeaves
1 parent 95cbc78 commit cc2ccd0

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

test/cli/add_test.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ func TestAdd(t *testing.T) {
1212
t.Parallel()
1313

1414
var (
15-
shortString = "hello world"
16-
shortStringCidV0 = "Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD"
17-
shortStringCidV1 = "bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e"
18-
shortStringCidV1Sha512 = "bafkrgqbqt3gerhas23vuzrapkdeqf4vu2dwxp3srdj6hvg6nhsug2tgyn6mj3u23yx7utftq3i2ckw2fwdh5qmhid5qf3t35yvkc5e5ottlw6"
15+
shortString = "hello world"
16+
shortStringCidV0 = "Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD" // cidv0 - dag-pb - sha2-256
17+
shortStringCidV1 = "bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e" // cidv1 - raw - sha2-256
18+
shortStringCidV1NoRawLeaves = "bafybeihykld7uyxzogax6vgyvag42y7464eywpf55gxi5qpoisibh3c5wa" // cidv1 - dag-pb - sha2-256
19+
shortStringCidV1Sha512 = "bafkrgqbqt3gerhas23vuzrapkdeqf4vu2dwxp3srdj6hvg6nhsug2tgyn6mj3u23yx7utftq3i2ckw2fwdh5qmhid5qf3t35yvkc5e5ottlw6"
1920
)
2021

21-
t.Run("output cid version: default (CIDv0)", func(t *testing.T) {
22+
t.Run("produced cid version: implicit default (CIDv0)", func(t *testing.T) {
2223
t.Parallel()
2324
node := harness.NewT(t).NewNode().Init().StartDaemon()
2425
defer node.StopDaemon()
@@ -27,7 +28,7 @@ func TestAdd(t *testing.T) {
2728
require.Equal(t, shortStringCidV0, cidStr)
2829
})
2930

30-
t.Run("output cid version: follows configuration (CIDv0)", func(t *testing.T) {
31+
t.Run("produced cid version: follows user-set configuration Import.CidVersion=0", func(t *testing.T) {
3132
t.Parallel()
3233
node := harness.NewT(t).NewNode().Init()
3334
node.UpdateConfig(func(cfg *config.Config) {
@@ -40,7 +41,7 @@ func TestAdd(t *testing.T) {
4041
require.Equal(t, shortStringCidV0, cidStr)
4142
})
4243

43-
t.Run("output cid version: follows configuration (hash function)", func(t *testing.T) {
44+
t.Run("produced cid multihash: follows user-set configuration in Import.HashFunction", func(t *testing.T) {
4445
t.Parallel()
4546
node := harness.NewT(t).NewNode().Init()
4647
node.UpdateConfig(func(cfg *config.Config) {
@@ -53,7 +54,7 @@ func TestAdd(t *testing.T) {
5354
require.Equal(t, shortStringCidV1Sha512, cidStr)
5455
})
5556

56-
t.Run("output cid version: follows configuration (CIDv1)", func(t *testing.T) {
57+
t.Run("produced cid version: follows user-set configuration Import.CidVersion=1", func(t *testing.T) {
5758
t.Parallel()
5859
node := harness.NewT(t).NewNode().Init()
5960
node.UpdateConfig(func(cfg *config.Config) {
@@ -66,7 +67,7 @@ func TestAdd(t *testing.T) {
6667
require.Equal(t, shortStringCidV1, cidStr)
6768
})
6869

69-
t.Run("output cid version: flag overrides configuration", func(t *testing.T) {
70+
t.Run("produced cid version: command flag overrides configuration in Import.CidVersion", func(t *testing.T) {
7071
t.Parallel()
7172
node := harness.NewT(t).NewNode().Init()
7273
node.UpdateConfig(func(cfg *config.Config) {
@@ -78,4 +79,20 @@ func TestAdd(t *testing.T) {
7879
cidStr := node.IPFSAddStr(shortString, "--cid-version", "0")
7980
require.Equal(t, shortStringCidV0, cidStr)
8081
})
82+
83+
t.Run("produced unixfs raw leaves: follows user-set configuration Import.UnixFSRawLeaves", func(t *testing.T) {
84+
t.Parallel()
85+
node := harness.NewT(t).NewNode().Init()
86+
node.UpdateConfig(func(cfg *config.Config) {
87+
// CIDv1 defaults to raw-leaves=true
88+
cfg.Import.CidVersion = *config.NewOptionalInteger(1)
89+
// disable manually
90+
cfg.Import.UnixFSRawLeaves = config.False
91+
})
92+
node.StartDaemon()
93+
defer node.StopDaemon()
94+
95+
cidStr := node.IPFSAddStr(shortString)
96+
require.Equal(t, shortStringCidV1NoRawLeaves, cidStr)
97+
})
8198
}

0 commit comments

Comments
 (0)