Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
825fb90c
Commit
825fb90c
authored
6 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
added simple log reader
parent
4f679638
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
importer/fetch_converter_utils.go
+26
-0
26 additions, 0 deletions
importer/fetch_converter_utils.go
importer/fetch_converter_utils_test.go
+102
-0
102 additions, 0 deletions
importer/fetch_converter_utils_test.go
with
128 additions
and
0 deletions
importer/fetch_converter_utils.go
+
26
−
0
View file @
825fb90c
...
...
@@ -81,3 +81,29 @@ func (l *convLogger) run() {
func
(
l
*
convLogger
)
Wait
()
{
<-
l
.
done
}
// this is not a perfect io.Reader:
// - it will only return one line on each invocation even if len(p) would allow us to
// return more than one line
// - lines longer than len(p) will be truncated
type
JobLogReader
struct
{
log
JobLog
pos
int
stream
string
}
func
NewJobLogReader
(
log
JobLog
,
stream
string
)
*
JobLogReader
{
return
&
JobLogReader
{
log
,
-
1
,
stream
}
}
func
(
r
*
JobLogReader
)
Read
(
p
[]
byte
)
(
n
int
,
err
error
)
{
for
{
r
.
pos
++
if
r
.
pos
>=
len
(
r
.
log
)
{
return
0
,
io
.
EOF
}
if
r
.
stream
==
""
||
r
.
log
[
r
.
pos
]
.
Stream
==
r
.
stream
{
return
copy
(
p
,
[]
byte
(
r
.
log
[
r
.
pos
]
.
Line
)),
nil
}
}
}
This diff is collapsed.
Click to expand it.
importer/fetch_converter_utils_test.go
0 → 100644
+
102
−
0
View file @
825fb90c
//
// tank
//
// Import and Playlist Daemon for autoradio project
//
//
// Copyright (C) 2017-2018 Christian Pointner <equinox@helsinki.at>
//
// This file is part of tank.
//
// tank is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// tank is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with tank. If not, see <http://www.gnu.org/licenses/>.
//
package
importer
import
(
"io"
"testing"
)
func
TestJobLogReader
(
t
*
testing
.
T
)
{
var
log
JobLog
var
buf
[
1024
]
byte
r
:=
NewJobLogReader
(
log
,
""
)
p
:=
buf
[
:
]
n
,
err
:=
r
.
Read
(
p
)
if
n
!=
0
||
err
!=
io
.
EOF
{
t
.
Fatalf
(
"an empty log should yield %d, %v but got: %d, %v"
,
0
,
io
.
EOF
,
n
,
err
)
}
log
.
append
(
"stdout"
,
"this is a test"
)
log
.
append
(
"stdout"
,
"this is another test"
)
log
.
append
(
"stderr"
,
"oh no something went wrong!"
)
r
=
NewJobLogReader
(
log
,
""
)
for
i
,
l
:=
range
log
{
p
=
buf
[
:
]
n
,
err
=
r
.
Read
(
p
)
if
n
!=
len
(
l
.
Line
)
||
err
!=
nil
{
t
.
Fatalf
(
"reading line %d failed, expected return code %d, %v but got: %d, %v"
,
i
+
1
,
len
(
l
.
Line
),
nil
,
n
,
err
)
}
line
:=
string
(
p
[
:
n
])
if
l
.
Line
!=
line
{
t
.
Fatalf
(
"reading line %d failed, expected line %q but got: %q"
,
i
+
1
,
l
.
Line
,
line
)
}
}
if
n
,
err
=
r
.
Read
(
p
);
n
!=
0
||
err
!=
io
.
EOF
{
t
.
Fatalf
(
"reading after the end of log should yield %d, %v but got: %d, %v"
,
0
,
io
.
EOF
,
n
,
err
)
}
r
=
NewJobLogReader
(
log
,
"stderr"
)
for
i
,
l
:=
range
log
{
if
l
.
Stream
!=
"stderr"
{
continue
}
p
=
buf
[
:
]
n
,
err
=
r
.
Read
(
p
)
if
n
!=
len
(
l
.
Line
)
||
err
!=
nil
{
t
.
Fatalf
(
"reading line %d failed, expected return code %d, %v but got: %d, %v"
,
i
+
1
,
len
(
l
.
Line
),
nil
,
n
,
err
)
}
line
:=
string
(
p
[
:
n
])
if
l
.
Line
!=
line
{
t
.
Fatalf
(
"reading line %d failed, expected line %q but got: %q"
,
i
+
1
,
l
.
Line
,
line
)
}
}
if
n
,
err
=
r
.
Read
(
p
);
n
!=
0
||
err
!=
io
.
EOF
{
t
.
Fatalf
(
"reading after the end of log should yield %d, %v but got: %d, %v"
,
0
,
io
.
EOF
,
n
,
err
)
}
r
=
NewJobLogReader
(
log
,
"stdout"
)
for
i
,
l
:=
range
log
{
if
l
.
Stream
!=
"stdout"
{
continue
}
p
=
buf
[
:
]
n
,
err
=
r
.
Read
(
p
)
if
n
!=
len
(
l
.
Line
)
||
err
!=
nil
{
t
.
Fatalf
(
"reading line %d failed, expected return code %d, %v but got: %d, %v"
,
i
+
1
,
len
(
l
.
Line
),
nil
,
n
,
err
)
}
line
:=
string
(
p
[
:
n
])
if
l
.
Line
!=
line
{
t
.
Fatalf
(
"reading line %d failed, expected line %q but got: %q"
,
i
+
1
,
l
.
Line
,
line
)
}
}
if
n
,
err
=
r
.
Read
(
p
);
n
!=
0
||
err
!=
io
.
EOF
{
t
.
Fatalf
(
"reading after the end of log should yield %d, %v but got: %d, %v"
,
0
,
io
.
EOF
,
n
,
err
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment