Skip to content

Commit a939820

Browse files
author
potsables
committed
chore: cleanup test
1 parent 6b84e9c commit a939820

File tree

1 file changed

+0
-237
lines changed

1 file changed

+0
-237
lines changed

shell_test.go

Lines changed: 0 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -21,213 +21,6 @@ const (
2121
shellUrl = "192.168.1.101:5001"
2222
)
2323

24-
func TestNewDirectShell(t *testing.T) {
25-
is := is.New(t)
26-
s := NewDirectShell(shellUrl)
27-
mhash, err := s.Add(bytes.NewBufferString("Hello IPFS Shell tests"))
28-
is.Nil(err)
29-
is.Equal(mhash, "QmUfZ9rAdhV5ioBzXKdUTh2ZNsz9bzbkaLVyQ8uc8pj21F")
30-
s.SetTimeout(1 * time.Second)
31-
32-
rand := randString(32)
33-
34-
mhash, err = s.Add(bytes.NewBufferString(rand))
35-
is.Nil(err)
36-
37-
reader, err := s.Cat(mhash)
38-
is.Nil(err)
39-
40-
buf := new(bytes.Buffer)
41-
buf.ReadFrom(reader)
42-
catRand := buf.String()
43-
44-
is.Equal(rand, catRand)
45-
rand = randString(32)
46-
47-
mhash, err = s.Add(bytes.NewBufferString(rand), OnlyHash(true))
48-
is.Nil(err)
49-
50-
_, err = s.Cat(mhash)
51-
is.Err(err) // we expect an http timeout error because `cat` won't find the `rand` string
52-
h, err := s.Add(bytes.NewBufferString(randString(32)), Pin(false))
53-
is.Nil(err)
54-
55-
pins, err := s.Pins()
56-
is.Nil(err)
57-
58-
_, ok := pins[h]
59-
is.False(ok)
60-
h, err = s.AddNoPin(bytes.NewBufferString(randString(32)))
61-
is.Nil(err)
62-
63-
pins, err = s.Pins()
64-
is.Nil(err)
65-
66-
_, ok = pins[h]
67-
is.False(ok)
68-
cid, err := s.AddDir("./testdata")
69-
is.Nil(err)
70-
is.Equal(cid, "QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv")
71-
rc, err := s.Cat(fmt.Sprintf("/ipfs/%s/readme", examplesHash))
72-
is.Nil(err)
73-
74-
md5 := md5.New()
75-
_, err = io.Copy(md5, rc)
76-
is.Nil(err)
77-
is.Equal(fmt.Sprintf("%x", md5.Sum(nil)), "3fdcaad186e79983a6920b4c7eeda949")
78-
list, err := s.List(fmt.Sprintf("/ipfs/%s", examplesHash))
79-
is.Nil(err)
80-
81-
is.Equal(len(list), 7)
82-
83-
// TODO: document difference in size between 'ipfs ls' and 'ipfs file ls -v'. additional object encoding in data block?
84-
expected := map[string]LsLink{
85-
"about": {Type: TFile, Hash: "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V", Name: "about", Size: 1677},
86-
"contact": {Type: TFile, Hash: "QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y", Name: "contact", Size: 200},
87-
"help": {Type: TFile, Hash: "QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7", Name: "help", Size: 322},
88-
"ping": {Type: TFile, Hash: "QmejvEPop4D7YUadeGqYWmZxHhLc4JBUCzJJHWMzdcMe2y", Name: "ping", Size: 12},
89-
"quick-start": {Type: TFile, Hash: "QmXgqKTbzdh83pQtKFb19SpMCpDDcKR2ujqk3pKph9aCNF", Name: "quick-start", Size: 1692},
90-
"readme": {Type: TFile, Hash: "QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB", Name: "readme", Size: 1102},
91-
"security-notes": {Type: TFile, Hash: "QmQ5vhrL7uv6tuoN9KeVBwd4PwfQkXdVVmDLUZuTNxqgvm", Name: "security-notes", Size: 1173},
92-
}
93-
for _, l := range list {
94-
el, ok := expected[l.Name]
95-
is.True(ok)
96-
is.NotNil(el)
97-
is.Equal(*l, el)
98-
}
99-
unixList, err := s.FileList(fmt.Sprintf("/ipfs/%s", examplesHash))
100-
is.Nil(err)
101-
102-
is.Equal(unixList.Type, "Directory")
103-
is.Equal(unixList.Size, 0)
104-
is.Equal(len(unixList.Links), 7)
105-
106-
// TODO: document difference in sice betwen 'ipfs ls' and 'ipfs file ls -v'. additional object encoding in data block?
107-
expectedUnix := map[string]UnixLsLink{
108-
"about": {Type: "File", Hash: "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V", Name: "about", Size: 1677},
109-
"contact": {Type: "File", Hash: "QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y", Name: "contact", Size: 189},
110-
"help": {Type: "File", Hash: "QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7", Name: "help", Size: 311},
111-
"ping": {Type: "File", Hash: "QmejvEPop4D7YUadeGqYWmZxHhLc4JBUCzJJHWMzdcMe2y", Name: "ping", Size: 4},
112-
"quick-start": {Type: "File", Hash: "QmXgqKTbzdh83pQtKFb19SpMCpDDcKR2ujqk3pKph9aCNF", Name: "quick-start", Size: 1681},
113-
"readme": {Type: "File", Hash: "QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB", Name: "readme", Size: 1091},
114-
"security-notes": {Type: "File", Hash: "QmQ5vhrL7uv6tuoN9KeVBwd4PwfQkXdVVmDLUZuTNxqgvm", Name: "security-notes", Size: 1162},
115-
}
116-
for _, l := range unixList.Links {
117-
el, ok := expectedUnix[l.Name]
118-
is.True(ok)
119-
is.NotNil(el)
120-
is.Equal(*l, el)
121-
}
122-
// Add a thing, which pins it by default
123-
h, err = s.Add(bytes.NewBufferString("go-ipfs-api pins test 9F3D1F30-D12A-4024-9477-8F0C8E4B3A63"))
124-
is.Nil(err)
125-
126-
pins, err = s.Pins()
127-
is.Nil(err)
128-
129-
_, ok = pins[h]
130-
is.True(ok)
131-
132-
err = s.Unpin(h)
133-
is.Nil(err)
134-
135-
pins, err = s.Pins()
136-
is.Nil(err)
137-
138-
_, ok = pins[h]
139-
is.False(ok)
140-
141-
err = s.Pin(h)
142-
is.Nil(err)
143-
144-
pins, err = s.Pins()
145-
is.Nil(err)
146-
147-
info, ok := pins[h]
148-
is.True(ok)
149-
is.Equal(info.Type, RecursivePin)
150-
newRoot, err := s.Patch(examplesHash, "rm-link", "about")
151-
is.Nil(err)
152-
is.Equal(newRoot, "QmPmCJpciopaZnKcwymfQyRAEjXReR6UL2rdSfEscZfzcp")
153-
newRoot, err = s.PatchLink(examplesHash, "about", "QmUXTtySmd7LD4p6RG6rZW6RuUuPZXTtNMmRQ6DSQo3aMw", true)
154-
is.Nil(err)
155-
is.Equal(newRoot, "QmVfe7gesXf4t9JzWePqqib8QSifC1ypRBGeJHitSnF7fA")
156-
newRoot, err = s.PatchLink(examplesHash, "about", "QmUXTtySmd7LD4p6RG6rZW6RuUuPZXTtNMmRQ6DSQo3aMw", false)
157-
is.Nil(err)
158-
is.Equal(newRoot, "QmVfe7gesXf4t9JzWePqqib8QSifC1ypRBGeJHitSnF7fA")
159-
newHash, err := s.NewObject("unixfs-dir")
160-
is.Nil(err)
161-
_, err = s.PatchLink(newHash, "a/b/c", newHash, false)
162-
is.NotNil(err)
163-
newHash, err = s.PatchLink(newHash, "a/b/c", newHash, true)
164-
is.Nil(err)
165-
is.Equal(newHash, "QmQ5D3xbMWFQRC9BKqbvnSnHri31GqvtWG1G6rE8xAZf1J")
166-
childHash, err := s.ResolvePath(fmt.Sprintf("/ipfs/%s/about", examplesHash))
167-
is.Nil(err)
168-
is.Equal(childHash, "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V")
169-
var (
170-
topic = "test"
171-
172-
sub *PubSubSubscription
173-
)
174-
175-
t.Log("subscribing...")
176-
sub, err = s.PubSubSubscribe(topic)
177-
is.Nil(err)
178-
is.NotNil(sub)
179-
t.Log("sub: done")
180-
181-
time.Sleep(10 * time.Millisecond)
182-
183-
t.Log("publishing...")
184-
is.Nil(s.PubSubPublish(topic, "Hello World!"))
185-
t.Log("pub: done")
186-
187-
t.Log("next()...")
188-
r, err := sub.Next()
189-
t.Log("next: done. ")
190-
191-
is.Nil(err)
192-
is.NotNil(r)
193-
is.Equal(r.Data, "Hello World!")
194-
195-
sub2, err := s.PubSubSubscribe(topic)
196-
is.Nil(err)
197-
is.NotNil(sub2)
198-
199-
is.Nil(s.PubSubPublish(topic, "Hallo Welt!"))
200-
201-
r, err = sub2.Next()
202-
is.Nil(err)
203-
is.NotNil(r)
204-
is.Equal(r.Data, "Hallo Welt!")
205-
206-
r, err = sub.Next()
207-
is.NotNil(r)
208-
is.Nil(err)
209-
is.Equal(r.Data, "Hallo Welt!")
210-
211-
is.Nil(sub.Cancel())
212-
obj := "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V"
213-
214-
stat, err := s.ObjectStat("QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V")
215-
is.Nil(err)
216-
is.Equal(stat.Hash, obj)
217-
is.Equal(stat.LinksSize, 3)
218-
is.Equal(stat.CumulativeSize, 1688)
219-
c, err := s.DagPut(`{"x": "abc","y":"def"}`, "json", "cbor")
220-
is.Nil(err)
221-
is.Equal(c, "zdpuAt47YjE9XTgSxUBkiYCbmnktKajQNheQBGASHj3FfYf8M")
222-
c, err = s.DagPutWithOpts(`{"x": "abc","y":"def"}`, options.Dag.Pin("true"))
223-
is.Nil(err)
224-
is.Equal(c, "zdpuAt47YjE9XTgSxUBkiYCbmnktKajQNheQBGASHj3FfYf8M")
225-
_, err = s.StatsBW(context.Background())
226-
is.Nil(err)
227-
_, err = s.SwarmPeers(context.Background())
228-
is.Nil(err)
229-
}
230-
23124
func TestAdd(t *testing.T) {
23225
is := is.New(t)
23326
s := NewShell(shellUrl)
@@ -422,36 +215,6 @@ func TestPins(t *testing.T) {
422215
is.Equal(info.Type, RecursivePin)
423216
}
424217

425-
// Runs ipfs pin update
426-
func TestPinUpdate(t *testing.T) {
427-
var (
428-
oldPin = "zb2rheJDzFsa7AsCnSxKimX8eF5wkjriJqeGBamjQF79vr14R"
429-
newPin = "QmbB6M914rwm9ZezVd2u8Y2k4g5TRoWWxP3PYKkDipCzpT"
430-
expectedOldPath = "/ipfs/zb2rheJDzFsa7AsCnSxKimX8eF5wkjriJqeGBamjQF79vr14R"
431-
expectedNewPath = "/ipfs/QmbB6M914rwm9ZezVd2u8Y2k4g5TRoWWxP3PYKkDipCzpT"
432-
)
433-
s := NewShell(shellUrl)
434-
if err := s.Pin(oldPin); err != nil {
435-
t.Fatal(err)
436-
}
437-
if err := s.Pin(newPin); err != nil {
438-
t.Fatal(err)
439-
}
440-
out, err := s.PinUpdate(oldPin, newPin)
441-
if err != nil {
442-
t.Fatal(err)
443-
}
444-
if len(out) == 0 {
445-
t.Fatal("bad output")
446-
}
447-
if out["Pins"][0] != expectedOldPath {
448-
t.Fatal("failed to calculate old pin path")
449-
}
450-
if out["Pins"][1] != expectedNewPath {
451-
t.Fatal("failed to calculate new pin path")
452-
}
453-
}
454-
455218
func TestPatch_rmLink(t *testing.T) {
456219
is := is.New(t)
457220
s := NewShell(shellUrl)

0 commit comments

Comments
 (0)