@cryptotaxi247 / kubo / commits / 9a5349444

update test about publish offline mode

License: MIT Signed-off-by: Kejie Zhang <601172892@qq.com>

Kejie Zhang committed Sep 17, 2018 at 16:32 UTC 9a534944402bd4d0470d22e448f870318a400aaa
4 files changed +36 -24
core/commands/name/publish.go
+11 -11
@@ -20,18 +20,18 @@ import (
20 )
21
22 var (
23 - 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")
25 - ErrIdentityLoad = errors.New("identity not loaded")
23 + 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")
25 + errIdentityLoad = errors.New("identity not loaded")
26 )
27
28 const (
29 - ipfsPathOptionName = "ipfs-path"
30 - resolveOptionName = "resolve"
29 + ipfsPathOptionName = "ipfs-path"
30 + resolveOptionName = "resolve"
31 allowOfflineOptionName = "allow-offline"
32 - lifeTimeOptionName = "lifetime"
33 - ttlOptionName = "ttl"
34 - keyOptionName = "key"
32 + lifeTimeOptionName = "lifetime"
33 + ttlOptionName = "ttl"
34 + keyOptionName = "key"
35 )
36
37 var PublishCmd = &cmds.Command{
@@ -97,7 +97,7 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
97 allowOffline, _ := req.Options[allowOfflineOptionName].(bool)
98 if !n.OnlineMode() {
99 if !allowOffline {
100 - res.SetError(ErrAllowOffline,cmdkit.ErrNormal)
100 + res.SetError(errAllowOffline, cmdkit.ErrNormal)
101 return
102 }
103 err := n.SetupOfflineRouting()
@@ -108,14 +108,14 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
108 }
109
110 if n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() {
111 - res.SetError(ErrIpnsMount, cmdkit.ErrNormal)
111 + res.SetError(errIpnsMount, cmdkit.ErrNormal)
112 return
113 }
114
115 pstr := req.Arguments[0]
116
117 if n.Identity == "" {
118 - res.SetError(ErrIdentityLoad, cmdkit.ErrNormal)
118 + res.SetError(errIdentityLoad, cmdkit.ErrNormal)
119 return
120 }
121
test/sharness/t0100-name.sh
+22 -10
@@ -12,10 +12,11 @@ test_init_ipfs
12
13 # test publishing a hash
14
15 -test_expect_success "'ipfs name publish' succeeds" '
15 +
16 +test_expect_success "'ipfs name publish --allow-offline' succeeds" '
17 PEERID=`ipfs id --format="<id>"` &&
18 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
20 '
21
22 test_expect_success "publish output looks good" '
@@ -34,10 +35,10 @@ test_expect_success "resolve output looks good" '
35
36 # now test with a path
37
37 -test_expect_success "'ipfs name publish' succeeds" '
38 +test_expect_success "'ipfs name publish --allow-offline' succeeds" '
39 PEERID=`ipfs id --format="<id>"` &&
40 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
42 '
43
44 test_expect_success "publish a path looks good" '
@@ -62,11 +63,11 @@ test_expect_success "ipfs cat on published content succeeds" '
63
64 # publish with an explicit node ID
65
65 -test_expect_failure "'ipfs name publish <local-id> <hash>' succeeds" '
66 +test_expect_failure "'ipfs name publish --allow-offline <local-id> <hash>' succeeds" '
67 PEERID=`ipfs id --format="<id>"` &&
68 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
71 '
72
73 test_expect_failure "publish with our explicit node ID looks good" '
@@ -81,8 +82,8 @@ test_expect_success "generate and verify a new key" '
82 test_check_peerid "${NEWID}"
83 '
84
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
87 '
88
89 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" '
95 # test publishing nothing
96
97 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
99 '
100
101 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
116 test_kill_ipfs_daemon
117
118
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 +
130 test_done
test/sharness/t0110-gateway.sh
+1 -1
@@ -62,7 +62,7 @@ test_expect_success "GET IPFS non existent file returns code expected (404)" '
62 '
63
64 test_expect_failure "GET IPNS path succeeds" '
65 - ipfs name publish "$HASH" &&
65 + ipfs name publish --allow-offline "$HASH" &&
66 PEERID=$(ipfs config Identity.PeerID) &&
67 test_check_peerid "$PEERID" &&
68 curl -sfo actual "http://127.0.0.1:$port/ipns/$PEERID"
test/sharness/t0160-resolve.sh
+2 -2
@@ -19,7 +19,7 @@ test_resolve_setup_name() {
19
20 test_expect_success "resolve: prepare name" '
21 id_hash=$(ipfs id -f="<id>") &&
22 - ipfs name publish "$ref" &&
22 + ipfs name publish --allow-offline "$ref" &&
23 printf "$ref\n" >expected_nameval &&
24 ipfs name resolve >actual_nameval &&
25 test_cmp expected_nameval actual_nameval
@@ -31,7 +31,7 @@ test_resolve_setup_name_fail() {
31
32 test_expect_failure "resolve: prepare name" '
33 id_hash=$(ipfs id -f="<id>") &&
34 - ipfs name publish "$ref" &&
34 + ipfs name publish --allow-offline "$ref" &&
35 printf "$ref" >expected_nameval &&
36 ipfs name resolve >actual_nameval &&
37 test_cmp expected_nameval actual_nameval