Skip to content

Commit

Permalink
add test about publish offline mode
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kejie Zhang <601172892@qq.com>
  • Loading branch information
kjzz committed Sep 17, 2018
1 parent 264a9fe commit 5e77465
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
14 changes: 7 additions & 7 deletions core/commands/name/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -97,7 +97,7 @@ Alternatively, publish an <ipfs-path> 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()
Expand Down
21 changes: 21 additions & 0 deletions test/sharness/t0100-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="<id>"` &&
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="<id>"` &&
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

0 comments on commit 5e77465

Please sign in to comment.