Skip to content

Commit

Permalink
update 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 18, 2018
1 parent 264a9fe commit a0c675d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 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
32 changes: 22 additions & 10 deletions test/sharness/t0100-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ test_init_ipfs

# test publishing a hash

test_expect_success "'ipfs name publish' succeeds" '

test_expect_success "'ipfs name publish --allow-offline' succeeds" '
PEERID=`ipfs id --format="<id>"` &&
test_check_peerid "${PEERID}" &&
ipfs name publish "/ipfs/$HASH_WELCOME_DOCS" >publish_out
ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS" >publish_out
'

test_expect_success "publish output looks good" '
Expand All @@ -34,10 +35,10 @@ test_expect_success "resolve output looks good" '

# now test with a path

test_expect_success "'ipfs name publish' succeeds" '
test_expect_success "'ipfs name publish --allow-offline' succeeds" '
PEERID=`ipfs id --format="<id>"` &&
test_check_peerid "${PEERID}" &&
ipfs name publish "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
'

test_expect_success "publish a path looks good" '
Expand All @@ -62,11 +63,11 @@ test_expect_success "ipfs cat on published content succeeds" '

# publish with an explicit node ID

test_expect_failure "'ipfs name publish <local-id> <hash>' succeeds" '
test_expect_failure "'ipfs name publish --allow-offline <local-id> <hash>' succeeds" '
PEERID=`ipfs id --format="<id>"` &&
test_check_peerid "${PEERID}" &&
echo ipfs name publish "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" &&
ipfs name publish "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
echo ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" &&
ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
'

test_expect_failure "publish with our explicit node ID looks good" '
Expand All @@ -81,8 +82,8 @@ test_expect_success "generate and verify a new key" '
test_check_peerid "${NEWID}"
'

test_expect_success "'ipfs name publish --key=<peer-id> <hash>' succeeds" '
ipfs name publish --key=${NEWID} "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
test_expect_success "'ipfs name publis --allow-offline --key=<peer-id> <hash>' succeeds" '
ipfs name publish --allow-offline --key=${NEWID} "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
'

test_expect_success "publish an explicit node ID as key name looks good" '
Expand All @@ -94,7 +95,7 @@ test_expect_success "publish an explicit node ID as key name looks good" '
# test publishing nothing

test_expect_success "'ipfs name publish' fails" '
printf '' | test_expect_code 1 ipfs name publish >publish_out 2>&1
printf '' | test_expect_code 1 ipfs name publish --allow-offline >publish_out 2>&1
'

test_expect_success "publish output has the correct error" '
Expand All @@ -115,4 +116,15 @@ 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"
'

test_kill_ipfs_daemon

test_done
2 changes: 1 addition & 1 deletion test/sharness/t0110-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test_expect_success "GET IPFS non existent file returns code expected (404)" '
'

test_expect_failure "GET IPNS path succeeds" '
ipfs name publish "$HASH" &&
ipfs name publish --allow-offline "$HASH" &&
PEERID=$(ipfs config Identity.PeerID) &&
test_check_peerid "$PEERID" &&
curl -sfo actual "http://127.0.0.1:$port/ipns/$PEERID"
Expand Down
4 changes: 2 additions & 2 deletions test/sharness/t0160-resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_resolve_setup_name() {

test_expect_success "resolve: prepare name" '
id_hash=$(ipfs id -f="<id>") &&
ipfs name publish "$ref" &&
ipfs name publish --allow-offline "$ref" &&
printf "$ref\n" >expected_nameval &&
ipfs name resolve >actual_nameval &&
test_cmp expected_nameval actual_nameval
Expand All @@ -31,7 +31,7 @@ test_resolve_setup_name_fail() {

test_expect_failure "resolve: prepare name" '
id_hash=$(ipfs id -f="<id>") &&
ipfs name publish "$ref" &&
ipfs name publish --allow-offline "$ref" &&
printf "$ref" >expected_nameval &&
ipfs name resolve >actual_nameval &&
test_cmp expected_nameval actual_nameval
Expand Down

0 comments on commit a0c675d

Please sign in to comment.