Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-cidutil
Commits
2bc018ba
Commit
2bc018ba
authored
Aug 09, 2018
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace DecodeV2 with ExtractEncoding
parent
eb97b6f3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
10 deletions
+11
-10
cid-fmt/main.go
cid-fmt/main.go
+4
-3
cid-fmt/main_test.go
cid-fmt/main_test.go
+2
-2
format_test.go
format_test.go
+5
-5
No files found.
cid-fmt/main.go
View file @
2bc018ba
...
...
@@ -69,15 +69,16 @@ outer:
}
}
for
_
,
cidStr
:=
range
args
[
1
:
]
{
base
,
cid
,
err
:=
c
.
Decode
V2
(
cidStr
)
cid
,
err
:=
c
.
Decode
(
cidStr
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stdout
,
"!INVALID_CID!
\n
"
)
errorMsg
(
"%s: %v"
,
cidStr
,
err
)
// Don't abort on a bad cid
continue
}
if
newBase
!=
-
1
{
base
=
newBase
base
:=
newBase
if
newBase
==
-
1
{
base
,
_
=
c
.
ExtractEncoding
(
cidStr
)
}
if
verConv
!=
nil
{
cid
,
err
=
verConv
(
cid
)
...
...
cid-fmt/main_test.go
View file @
2bc018ba
...
...
@@ -10,7 +10,7 @@ import (
func
TestCidConv
(
t
*
testing
.
T
)
{
cidv0
:=
"QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"
cidv1
:=
"zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi"
_
,
cid
,
err
:=
c
.
Decode
V2
(
cidv0
)
cid
,
err
:=
c
.
Decode
(
cidv0
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -34,7 +34,7 @@ func TestCidConv(t *testing.T) {
func
TestBadCidConv
(
t
*
testing
.
T
)
{
// this cid is a raw leaf and should not be able to convert to cidv0
cidv1
:=
"zb2rhhzX7uSKrtQ2ZZXFAabKiKFYZrJqKY2KE1cJ8yre2GSWZ"
_
,
cid
,
err
:=
c
.
Decode
V2
(
cidv1
)
cid
,
err
:=
c
.
Decode
(
cidv1
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
format_test.go
View file @
2bc018ba
...
...
@@ -55,13 +55,14 @@ func TestFmt(t *testing.T) {
}
func
testFmt
(
t
*
testing
.
T
,
cidStr
string
,
newBase
mb
.
Encoding
,
fmtStr
string
,
result
string
)
{
base
,
cid
,
err
:=
DecodeV2
(
cidStr
)
if
newBase
!=
-
1
{
base
=
newBase
}
cid
,
err
:=
Decode
(
cidStr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
base
:=
newBase
if
newBase
==
-
1
{
base
,
_
=
ExtractEncoding
(
cidStr
)
}
str
,
err
:=
Format
(
fmtStr
,
base
,
cid
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -70,4 +71,3 @@ func testFmt(t *testing.T, cidStr string, newBase mb.Encoding, fmtStr string, re
t
.
Error
(
fmt
.
Sprintf
(
"expected: %s; but got: %s"
,
result
,
str
))
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment