Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8f950223
Commit
8f950223
authored
Jun 07, 2023
by
Derek Nola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
E2E: Inject gocover ENV for k3s commands
Signed-off-by:
Derek Nola
<
derek.nola@suse.com
>
parent
4a68fbd8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
testutils.go
tests/e2e/testutils.go
+21
-3
No files found.
tests/e2e/testutils.go
View file @
8f950223
...
...
@@ -452,9 +452,13 @@ func StopCluster(nodeNames []string) error {
return
nil
}
// RunCmdOnNode executes a command from within the given node
// RunCmdOnNode executes a command from within the given node
as sudo
func
RunCmdOnNode
(
cmd
string
,
nodename
string
)
(
string
,
error
)
{
runcmd
:=
"vagrant ssh "
+
nodename
+
" -c
\"
sudo "
+
cmd
+
"
\"
"
injectEnv
:=
""
if
_
,
ok
:=
os
.
LookupEnv
(
"E2E_GOCOVER"
);
ok
&&
strings
.
HasPrefix
(
cmd
,
"k3s"
)
{
injectEnv
=
"GOCOVERDIR=/tmp/k3scov "
}
runcmd
:=
"vagrant ssh "
+
nodename
+
" -c
\"
sudo "
+
injectEnv
+
cmd
+
"
\"
"
out
,
err
:=
RunCommand
(
runcmd
)
if
err
!=
nil
{
return
out
,
fmt
.
Errorf
(
"failed to run command: %s on node %s: %s, %v"
,
cmd
,
nodename
,
out
,
err
)
...
...
@@ -500,10 +504,24 @@ func GetCoverageReport(nodeNames []string) error {
return
err
}
}
cmd
:=
"go tool covdata textfmt -i "
+
strings
.
Join
(
covDirs
,
","
)
+
" -o coverage.out"
coverageFile
:=
"coverage.out"
cmd
:=
"go tool covdata textfmt -i "
+
strings
.
Join
(
covDirs
,
","
)
+
" -o "
+
coverageFile
if
out
,
err
:=
RunCommand
(
cmd
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to generate coverage report: %s, %v"
,
out
,
err
)
}
f
,
err
:=
os
.
ReadFile
(
coverageFile
)
if
err
!=
nil
{
return
err
}
nf
:=
strings
.
Replace
(
string
(
f
),
"/go/src/github.com/k3s-io/k3s/cmd/server/main.go"
,
"github.com/k3s-io/k3s/cmd/server/main.go"
,
-
1
)
if
err
=
os
.
WriteFile
(
coverageFile
,
[]
byte
(
nf
),
os
.
ModePerm
);
err
!=
nil
{
return
err
}
for
_
,
covDir
:=
range
covDirs
{
if
err
:=
os
.
RemoveAll
(
covDir
);
err
!=
nil
{
return
err
...
...
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