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
6d360e64
Unverified
Commit
6d360e64
authored
Jul 31, 2023
by
Derek Nola
Committed by
GitHub
Jul 31, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit test for MustFindString (#8013)
Signed-off-by:
Derek Nola
<
derek.nola@suse.com
>
parent
946c8ea8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
defaultparser_test.go
pkg/configfilearg/defaultparser_test.go
+55
-0
No files found.
pkg/configfilearg/defaultparser_test.go
View file @
6d360e64
package
configfilearg
import
(
"os"
"reflect"
"testing"
)
...
...
@@ -72,3 +73,57 @@ func Test_UnitMustParse(t *testing.T) {
})
}
}
func
Test_UnitMustFindString
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
args
[]
string
target
string
setup
func
()
error
// Optional, delete if unused
teardown
func
()
error
// Optional, delete if unused
want
string
}{
{
name
:
"Target not found in config file"
,
args
:
[]
string
{
"--foo"
,
"bar"
},
target
:
"token"
,
want
:
""
,
setup
:
func
()
error
{
return
os
.
Setenv
(
"K3S_CONFIG_FILE"
,
"./testdata/data.yaml"
)
},
teardown
:
func
()
error
{
return
os
.
Unsetenv
(
"K3S_CONFIG_FILE"
)
},
},
{
name
:
"Target found in config file"
,
args
:
[]
string
{
"--foo"
,
"bar"
},
target
:
"token"
,
want
:
"12345"
,
setup
:
func
()
error
{
return
os
.
Setenv
(
"K3S_CONFIG_FILE"
,
"./testdata/defaultdata.yaml"
)
},
teardown
:
func
()
error
{
return
os
.
Unsetenv
(
"K3S_CONFIG_FILE"
)
},
},
{
name
:
"Override flag found, function is short-circuited"
,
args
:
[]
string
{
"--foo"
,
"bar"
,
"-h"
},
target
:
"token"
,
want
:
"-h"
,
setup
:
func
()
error
{
return
os
.
Setenv
(
"K3S_CONFIG_FILE"
,
"./testdata/defaultdata.yaml"
)
},
teardown
:
func
()
error
{
return
os
.
Unsetenv
(
"K3S_CONFIG_FILE"
)
},
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
defer
tt
.
teardown
()
if
err
:=
tt
.
setup
();
err
!=
nil
{
t
.
Errorf
(
"Setup for MustFindString() failed = %v"
,
err
)
return
}
if
got
:=
MustFindString
(
tt
.
args
,
tt
.
target
);
got
!=
tt
.
want
{
t
.
Errorf
(
"MustFindString() = %+v
\n
Want = %+v"
,
got
,
tt
.
want
)
}
})
}
}
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