Skip to content

Commit

Permalink
test: Import.UnixFSRawLeaves
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed May 13, 2024
1 parent 95cbc78 commit cc2ccd0
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions test/cli/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)
})
}

0 comments on commit cc2ccd0

Please sign in to comment.