Skip to content

Commit a0c675d

Browse files
committed
update test about publish offline mode
License: MIT Signed-off-by: Kejie Zhang <[email protected]>
1 parent 264a9fe commit a0c675d

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

core/commands/name/publish.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ import (
2121

2222
var (
2323
ErrAllowOffline = errors.New("cannot publish in offline mode by default,using `--allow-offline` to publish again")
24-
ErrIpnsMount = errors.New("cannot manually publish while IPNS is mounted")
24+
ErrIpnsMount = errors.New("cannot manually publish while IPNS is mounted")
2525
ErrIdentityLoad = errors.New("identity not loaded")
2626
)
2727

2828
const (
29-
ipfsPathOptionName = "ipfs-path"
30-
resolveOptionName = "resolve"
29+
ipfsPathOptionName = "ipfs-path"
30+
resolveOptionName = "resolve"
3131
allowOfflineOptionName = "allow-offline"
32-
lifeTimeOptionName = "lifetime"
33-
ttlOptionName = "ttl"
34-
keyOptionName = "key"
32+
lifeTimeOptionName = "lifetime"
33+
ttlOptionName = "ttl"
34+
keyOptionName = "key"
3535
)
3636

3737
var PublishCmd = &cmds.Command{
@@ -97,7 +97,7 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
9797
allowOffline, _ := req.Options[allowOfflineOptionName].(bool)
9898
if !n.OnlineMode() {
9999
if !allowOffline {
100-
res.SetError(ErrAllowOffline,cmdkit.ErrNormal)
100+
res.SetError(ErrAllowOffline, cmdkit.ErrNormal)
101101
return
102102
}
103103
err := n.SetupOfflineRouting()

test/sharness/t0100-name.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ test_init_ipfs
1212

1313
# test publishing a hash
1414

15-
test_expect_success "'ipfs name publish' succeeds" '
15+
16+
test_expect_success "'ipfs name publish --allow-offline' succeeds" '
1617
PEERID=`ipfs id --format="<id>"` &&
1718
test_check_peerid "${PEERID}" &&
18-
ipfs name publish "/ipfs/$HASH_WELCOME_DOCS" >publish_out
19+
ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS" >publish_out
1920
'
2021

2122
test_expect_success "publish output looks good" '
@@ -34,10 +35,10 @@ test_expect_success "resolve output looks good" '
3435

3536
# now test with a path
3637

37-
test_expect_success "'ipfs name publish' succeeds" '
38+
test_expect_success "'ipfs name publish --allow-offline' succeeds" '
3839
PEERID=`ipfs id --format="<id>"` &&
3940
test_check_peerid "${PEERID}" &&
40-
ipfs name publish "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
41+
ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
4142
'
4243

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

6364
# publish with an explicit node ID
6465

65-
test_expect_failure "'ipfs name publish <local-id> <hash>' succeeds" '
66+
test_expect_failure "'ipfs name publish --allow-offline <local-id> <hash>' succeeds" '
6667
PEERID=`ipfs id --format="<id>"` &&
6768
test_check_peerid "${PEERID}" &&
68-
echo ipfs name publish "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" &&
69-
ipfs name publish "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
69+
echo ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" &&
70+
ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
7071
'
7172

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

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

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

9697
test_expect_success "'ipfs name publish' fails" '
97-
printf '' | test_expect_code 1 ipfs name publish >publish_out 2>&1
98+
printf '' | test_expect_code 1 ipfs name publish --allow-offline >publish_out 2>&1
9899
'
99100

100101
test_expect_success "publish output has the correct error" '
@@ -115,4 +116,15 @@ test_expect_success "empty request to name publish doesn't panic and returns err
115116
test_kill_ipfs_daemon
116117

117118

119+
# Test daemon in offline mode
120+
test_launch_ipfs_daemon --offline
121+
122+
test_expect_success "'ipfs name publish' fails offline mode" '
123+
PEERID=`ipfs id --format="<id>"` &&
124+
test_check_peerid "${PEERID}" &&
125+
test_expect_code 1 ipfs name publish "/ipfs/$HASH_WELCOME_DOCS"
126+
'
127+
128+
test_kill_ipfs_daemon
129+
118130
test_done

test/sharness/t0110-gateway.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ test_expect_success "GET IPFS non existent file returns code expected (404)" '
6262
'
6363

6464
test_expect_failure "GET IPNS path succeeds" '
65-
ipfs name publish "$HASH" &&
65+
ipfs name publish --allow-offline "$HASH" &&
6666
PEERID=$(ipfs config Identity.PeerID) &&
6767
test_check_peerid "$PEERID" &&
6868
curl -sfo actual "http://127.0.0.1:$port/ipns/$PEERID"

test/sharness/t0160-resolve.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test_resolve_setup_name() {
1919

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

3232
test_expect_failure "resolve: prepare name" '
3333
id_hash=$(ipfs id -f="<id>") &&
34-
ipfs name publish "$ref" &&
34+
ipfs name publish --allow-offline "$ref" &&
3535
printf "$ref" >expected_nameval &&
3636
ipfs name resolve >actual_nameval &&
3737
test_cmp expected_nameval actual_nameval

0 commit comments

Comments
 (0)