Skip to content

Commit

Permalink
feat!: make --empty-repo default
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Mar 31, 2023
1 parent 95dd93b commit 332abc4
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 22 deletions.
3 changes: 2 additions & 1 deletion cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
algorithmDefault = options.Ed25519Key
algorithmOptionName = "algorithm"
bitsOptionName = "bits"
emptyRepoDefault = true
emptyRepoOptionName = "empty-repo"
profileOptionName = "profile"
)
Expand Down Expand Up @@ -61,7 +62,7 @@ environment variable:
Options: []cmds.Option{
cmds.StringOption(algorithmOptionName, "a", "Cryptographic algorithm to use for key generation.").WithDefault(algorithmDefault),
cmds.IntOption(bitsOptionName, "b", "Number of bits to use in the generated RSA private key."),
cmds.BoolOption(emptyRepoOptionName, "e", "Don't add and pin help files to the local storage."),
cmds.BoolOption(emptyRepoOptionName, "e", "Don't add and pin help files to the local storage.").WithDefault(emptyRepoDefault),
cmds.StringOption(profileOptionName, "p", "Apply profile settings to config. Multiple profiles can be separated by ','"),

// TODO need to decide whether to expose the override as a file or a
Expand Down
18 changes: 9 additions & 9 deletions test/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ func testInitAlgo(t *testing.T, initFlags []string, expOutputName string, expPee
lines := []string{
fmt.Sprintf("generating %s keypair...done", expOutputName),
fmt.Sprintf("peer identity: %s", node.PeerID().String()),
fmt.Sprintf("initializing IPFS node at %s", node.Dir),
"to get started, enter:",
fmt.Sprintf("\n\tipfs cat /ipfs/%s/readme\n\n", CIDWelcomeDocs),
fmt.Sprintf("initializing IPFS node at %s\n", node.Dir),
}
expectedInitOutput := strings.Join(lines, "\n")
assert.Equal(t, expectedInitOutput, initRes.Stdout.String())
Expand All @@ -54,26 +52,28 @@ func testInitAlgo(t *testing.T, initFlags []string, expOutputName string, expPee
res := node.IPFS("config", "Mounts.IPFS")
assert.Equal(t, "/ipfs", res.Stdout.Trimmed())

node.IPFS("cat", fmt.Sprintf("/ipfs/%s/readme", CIDWelcomeDocs))
catRes := node.RunIPFS("cat", fmt.Sprintf("/ipfs/%s/readme", CIDWelcomeDocs))
assert.NotEqual(t, 0, catRes.ExitErr.ExitCode(), "welcome readme doesn't exist")
})

t.Run("init empty repo", func(t *testing.T) {
t.Run("init without empty repo", func(t *testing.T) {
t.Parallel()
node := harness.NewT(t).NewNode()
initRes := node.IPFS(StrCat("init", "--empty-repo", initFlags)...)
initRes := node.IPFS(StrCat("init", "--empty-repo=false", initFlags)...)

validatePeerID(t, node.PeerID(), expPeerIDPubKeyErr, expPeerIDPubKeyType)

lines := []string{
fmt.Sprintf("generating %s keypair...done", expOutputName),
fmt.Sprintf("peer identity: %s", node.PeerID().String()),
fmt.Sprintf("initializing IPFS node at %s\n", node.Dir),
fmt.Sprintf("initializing IPFS node at %s", node.Dir),
"to get started, enter:",
fmt.Sprintf("\n\tipfs cat /ipfs/%s/readme\n\n", CIDWelcomeDocs),
}
expectedEmptyInitOutput := strings.Join(lines, "\n")
assert.Equal(t, expectedEmptyInitOutput, initRes.Stdout.String())

catRes := node.RunIPFS("cat", fmt.Sprintf("/ipfs/%s/readme", CIDWelcomeDocs))
assert.NotEqual(t, 0, catRes.ExitErr.ExitCode(), "welcome readme doesn't exist")
node.IPFS("cat", fmt.Sprintf("/ipfs/%s/readme", CIDWelcomeDocs))

idRes := node.IPFS("id", "-f", "<aver>")
version := node.IPFS("version", "-n").Stdout.Trimmed()
Expand Down
4 changes: 2 additions & 2 deletions test/sharness/lib/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ test_config_set() {
}

test_init_ipfs() {

args=("$@")

# we set the Addresses.API config variable.
# the cli client knows to use it, so only need to set.
# todo: in the future, use env?

test_expect_success "ipfs init succeeds" '
export IPFS_PATH="$(pwd)/.ipfs" &&
ipfs init --profile=test > /dev/null
ipfs init "${args[@]}" --profile=test > /dev/null
'

test_expect_success "prepare config -- mounting" '
Expand Down
4 changes: 2 additions & 2 deletions test/sharness/t0025-datastores.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ test_description="Test non-standard datastores"

. lib/test-lib.sh

test_expect_success "'ipfs init --profile=badgerds' succeeds" '
test_expect_success "'ipfs init --empty-repo=false --profile=badgerds' succeeds" '
BITS="2048" &&
ipfs init --profile=badgerds
ipfs init --empty-repo=false --profile=badgerds
'

test_expect_success "'ipfs pin ls' works" '
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0054-dag-car-import-export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ test_expect_success "shut down nodes" '


# We want to just init the repo, without using a daemon for stuff below
test_init_ipfs
test_init_ipfs --empty-repo=false


test_expect_success "basic offline export of 'getting started' dag works" '
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0080-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test_description="Test ipfs repo operations"

. lib/test-lib.sh

test_init_ipfs
test_init_ipfs --empty-repo=false
test_launch_ipfs_daemon_without_network

test_expect_success "'ipfs repo gc' succeeds" '
Expand Down
10 changes: 5 additions & 5 deletions test/sharness/t0100-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ test_name_with_self() {
export IPFS_PATH="$(pwd)/.ipfs" &&
case $SELF_ALG in
default)
ipfs init --profile=test > /dev/null
ipfs init --empty-repo=false --profile=test > /dev/null
;;
rsa)
ipfs init --profile=test -a=rsa > /dev/null
ipfs init --empty-repo=false --profile=test -a=rsa > /dev/null
;;
ed25519)
ipfs init --profile=test -a=ed25519 > /dev/null
ipfs init --empty-repo=false --profile=test -a=ed25519 > /dev/null
;;
esac &&
export PEERID=`ipfs key list --ipns-base=base36 -l | grep self | cut -d " " -f1` &&
Expand Down Expand Up @@ -273,7 +273,7 @@ test_name_with_key() {

test_expect_success "ipfs init (key variant $GEN_ALG)" '
export IPFS_PATH="$(pwd)/.ipfs" &&
ipfs init --profile=test > /dev/null
ipfs init --empty-repo=false --profile=test > /dev/null
'

test_expect_success "'prepare keys" '
Expand Down Expand Up @@ -317,7 +317,7 @@ test_name_with_key 'ed25519_b36'

# `ipfs name inspect --verify` using the wrong RSA key should not succeed

test_init_ipfs
test_init_ipfs --empty-repo=false
test_launch_ipfs_daemon

test_expect_success "prepare RSA keys" '
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0600-issues-and-regressions-online.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_description="Tests for various fixed issues and regressions."

. lib/test-lib.sh

test_init_ipfs
test_init_ipfs --empty-repo=false

test_launch_ipfs_daemon

Expand Down

0 comments on commit 332abc4

Please sign in to comment.