diff --git a/test/cli/add_test.go b/test/cli/add_test.go index 349c046da63a..aa47f7c0b49a 100644 --- a/test/cli/add_test.go +++ b/test/cli/add_test.go @@ -12,13 +12,14 @@ func TestAdd(t *testing.T) { t.Parallel() var ( - shortString = "hello world" - shortStringCidV0 = "Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD" - shortStringCidV1 = "bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e" - shortStringCidV1Sha512 = "bafkrgqbqt3gerhas23vuzrapkdeqf4vu2dwxp3srdj6hvg6nhsug2tgyn6mj3u23yx7utftq3i2ckw2fwdh5qmhid5qf3t35yvkc5e5ottlw6" + shortString = "hello world" + shortStringCidV0 = "Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD" // cidv0 - dag-pb - sha2-256 + shortStringCidV1 = "bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e" // cidv1 - raw - sha2-256 + shortStringCidV1NoRawLeaves = "bafybeihykld7uyxzogax6vgyvag42y7464eywpf55gxi5qpoisibh3c5wa" // cidv1 - dag-pb - sha2-256 + shortStringCidV1Sha512 = "bafkrgqbqt3gerhas23vuzrapkdeqf4vu2dwxp3srdj6hvg6nhsug2tgyn6mj3u23yx7utftq3i2ckw2fwdh5qmhid5qf3t35yvkc5e5ottlw6" ) - t.Run("output cid version: default (CIDv0)", func(t *testing.T) { + t.Run("produced cid version: implicit default (CIDv0)", func(t *testing.T) { t.Parallel() node := harness.NewT(t).NewNode().Init().StartDaemon() defer node.StopDaemon() @@ -27,7 +28,7 @@ func TestAdd(t *testing.T) { require.Equal(t, shortStringCidV0, cidStr) }) - t.Run("output cid version: follows configuration (CIDv0)", func(t *testing.T) { + t.Run("produced cid version: follows user-set configuration Import.CidVersion=0", func(t *testing.T) { t.Parallel() node := harness.NewT(t).NewNode().Init() node.UpdateConfig(func(cfg *config.Config) { @@ -40,7 +41,7 @@ func TestAdd(t *testing.T) { require.Equal(t, shortStringCidV0, cidStr) }) - t.Run("output cid version: follows configuration (hash function)", func(t *testing.T) { + t.Run("produced cid multihash: follows user-set configuration in Import.HashFunction", func(t *testing.T) { t.Parallel() node := harness.NewT(t).NewNode().Init() node.UpdateConfig(func(cfg *config.Config) { @@ -53,7 +54,7 @@ func TestAdd(t *testing.T) { require.Equal(t, shortStringCidV1Sha512, cidStr) }) - t.Run("output cid version: follows configuration (CIDv1)", func(t *testing.T) { + t.Run("produced cid version: follows user-set configuration Import.CidVersion=1", func(t *testing.T) { t.Parallel() node := harness.NewT(t).NewNode().Init() node.UpdateConfig(func(cfg *config.Config) { @@ -66,7 +67,7 @@ func TestAdd(t *testing.T) { require.Equal(t, shortStringCidV1, cidStr) }) - t.Run("output cid version: flag overrides configuration", func(t *testing.T) { + t.Run("produced cid version: command flag overrides configuration in Import.CidVersion", func(t *testing.T) { t.Parallel() node := harness.NewT(t).NewNode().Init() node.UpdateConfig(func(cfg *config.Config) { @@ -78,4 +79,20 @@ func TestAdd(t *testing.T) { cidStr := node.IPFSAddStr(shortString, "--cid-version", "0") require.Equal(t, shortStringCidV0, cidStr) }) + + t.Run("produced unixfs raw leaves: follows user-set configuration Import.UnixFSRawLeaves", func(t *testing.T) { + t.Parallel() + node := harness.NewT(t).NewNode().Init() + node.UpdateConfig(func(cfg *config.Config) { + // CIDv1 defaults to raw-leaves=true + cfg.Import.CidVersion = *config.NewOptionalInteger(1) + // disable manually + cfg.Import.UnixFSRawLeaves = config.False + }) + node.StartDaemon() + defer node.StopDaemon() + + cidStr := node.IPFSAddStr(shortString) + require.Equal(t, shortStringCidV1NoRawLeaves, cidStr) + }) }