master
sh 80 lines 2.83 KB
Raw
1 #!/usr/bin/env bash
2
3 test_description="Test to make sure our identity information looks sane"
4
5 . lib/test-lib.sh
6
7 test_init_ipfs
8
9 test_id_compute_agent() {
10 local AGENT_SUFFIX
11 AGENT_SUFFIX=$1
12 AGENT_VERSION="$(ipfs version --number)" || return 1
13 AGENT_COMMIT="$(ipfs version --number --commit)" || return 1
14 if test "$AGENT_COMMIT" = "$AGENT_VERSION"; then
15 AGENT_COMMIT=""
16 else
17 AGENT_COMMIT="${AGENT_COMMIT##$AGENT_VERSION-}"
18 fi
19 AGENT_VERSION="kubo/$AGENT_VERSION"
20 if test -n "$AGENT_COMMIT"; then
21 AGENT_VERSION="$AGENT_VERSION/$AGENT_COMMIT"
22 fi
23 if test -n "$AGENT_SUFFIX"; then
24 AGENT_VERSION="$AGENT_VERSION/$AGENT_SUFFIX"
25 fi
26 echo "$AGENT_VERSION"
27 }
28
29 test_expect_success "checking AgentVersion" '
30 test_id_compute_agent > expected-agent-version &&
31 ipfs id -f "<aver>\n" > actual-agent-version &&
32 test_cmp expected-agent-version actual-agent-version
33 '
34
35 test_expect_success "checking ID of self" '
36 ipfs config Identity.PeerID > expected-id &&
37 ipfs id -f "<id>\n" > actual-id &&
38 test_cmp expected-id actual-id
39 '
40
41 test_expect_success "checking and converting ID of a random peer while offline" '
42 # Peer ID taken from `t0140-swarm.sh` test.
43 echo k2k4r8ncs1yoluq95unsd7x2vfhgve0ncjoggwqx9vyh3vl8warrcp15 > expected-id &&
44 ipfs id -f "<id>\n" --peerid-base base36 --offline QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N > actual-id &&
45 test_cmp expected-id actual-id
46 '
47
48 # agent-version-suffix (local, offline)
49 test_launch_ipfs_daemon --agent-version-suffix=test-suffix
50 test_expect_success "checking AgentVersion with suffix (local)" '
51 test_id_compute_agent test-suffix > expected-agent-version &&
52 ipfs id -f "<aver>\n" > actual-agent-version &&
53 test_cmp expected-agent-version actual-agent-version
54 '
55
56 # agent-version-suffix (over libp2p identify protocol)
57 iptb testbed create -type localipfs -count 2 -init
58 startup_cluster 2 --agent-version-suffix=test-suffix-identify
59 test_expect_success "checking AgentVersion with suffix (fetched via libp2p identify protocol)" '
60 ipfsi 0 id -f "<aver>\n" > expected-identify-agent-version &&
61 ipfsi 1 id "$(ipfsi 0 config Identity.PeerID)" -f "<aver>\n" > actual-libp2p-identify-agent-version &&
62 test_cmp expected-identify-agent-version actual-libp2p-identify-agent-version
63 '
64 iptb stop
65
66 test_kill_ipfs_daemon
67
68 # Version.AgentSuffix overrides --agent-version-suffix (local, offline)
69 test_expect_success "setting Version.AgentSuffix in config" '
70 ipfs config Version.AgentSuffix json-config-suffix
71 '
72 test_launch_ipfs_daemon --agent-version-suffix=ignored-cli-suffix
73 test_expect_success "checking AgentVersion with suffix set via JSON config" '
74 test_id_compute_agent json-config-suffix > expected-agent-version &&
75 ipfs id -f "<aver>\n" > actual-agent-version &&
76 test_cmp expected-agent-version actual-agent-version
77 '
78 test_kill_ipfs_daemon
79
80 test_done