diff --git a/core/commands/name/publish.go b/core/commands/name/publish.go index 3175b45170ac..c74193b3f200 100644 --- a/core/commands/name/publish.go +++ b/core/commands/name/publish.go @@ -21,17 +21,17 @@ import ( var ( ErrAllowOffline = errors.New("cannot publish in offline mode by default,using `--allow-offline` to publish again") - ErrIpnsMount = errors.New("cannot manually publish while IPNS is mounted") + ErrIpnsMount = errors.New("cannot manually publish while IPNS is mounted") ErrIdentityLoad = errors.New("identity not loaded") ) const ( - ipfsPathOptionName = "ipfs-path" - resolveOptionName = "resolve" + ipfsPathOptionName = "ipfs-path" + resolveOptionName = "resolve" allowOfflineOptionName = "allow-offline" - lifeTimeOptionName = "lifetime" - ttlOptionName = "ttl" - keyOptionName = "key" + lifeTimeOptionName = "lifetime" + ttlOptionName = "ttl" + keyOptionName = "key" ) var PublishCmd = &cmds.Command{ @@ -97,7 +97,7 @@ Alternatively, publish an using a valid PeerID (as listed by allowOffline, _ := req.Options[allowOfflineOptionName].(bool) if !n.OnlineMode() { if !allowOffline { - res.SetError(ErrAllowOffline,cmdkit.ErrNormal) + res.SetError(ErrAllowOffline, cmdkit.ErrNormal) return } err := n.SetupOfflineRouting() diff --git a/test/sharness/t0100-name.sh b/test/sharness/t0100-name.sh index 7dbaa7f7988b..163320f0752d 100755 --- a/test/sharness/t0100-name.sh +++ b/test/sharness/t0100-name.sh @@ -114,5 +114,26 @@ test_expect_success "empty request to name publish doesn't panic and returns err test_kill_ipfs_daemon +# Test daemon in offline mode +test_launch_ipfs_daemon --offline + +test_expect_success "'ipfs name publish' fails offline mode" ' + PEERID=`ipfs id --format=""` && + test_check_peerid "${PEERID}" && + test_expect_code 1 ipfs name publish "/ipfs/$HASH_WELCOME_DOCS/help" +' + +test_expect_success "'ipfs name publish --allow-offline ' succeed offline mode" ' + PEERID=`ipfs id --format=""` && + test_check_peerid "${PEERID}" && + ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out +' + +test_expect_success "publish a path looks good" ' + echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS/help" >expected3 && + test_cmp expected3 publish_out +' + +test_kill_ipfs_daemon test_done