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
3f016859
Commit
3f016859
authored
Jul 26, 2017
by
Nick Sardo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit test unknown value in config
parent
cde038b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
gce.go
pkg/cloudprovider/providers/gce/gce.go
+12
-3
gce_test.go
pkg/cloudprovider/providers/gce/gce_test.go
+17
-0
No files found.
pkg/cloudprovider/providers/gce/gce.go
View file @
3f016859
...
@@ -198,11 +198,11 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
...
@@ -198,11 +198,11 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
var
nodeTags
[]
string
var
nodeTags
[]
string
var
nodeInstancePrefix
string
var
nodeInstancePrefix
string
if
config
!=
nil
{
if
config
!=
nil
{
var
cfg
Config
cfg
,
err
:=
readConfig
(
config
)
if
err
:=
gcfg
.
FatalOnly
(
gcfg
.
ReadInto
(
&
cfg
,
config
));
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Couldn't read config: %v"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
glog
.
Infof
(
"Using GCE provider config %+v"
,
cfg
)
glog
.
Infof
(
"Using GCE provider config %+v"
,
cfg
)
if
cfg
.
Global
.
ApiEndpoint
!=
""
{
if
cfg
.
Global
.
ApiEndpoint
!=
""
{
apiEndpoint
=
cfg
.
Global
.
ApiEndpoint
apiEndpoint
=
cfg
.
Global
.
ApiEndpoint
...
@@ -241,6 +241,15 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
...
@@ -241,6 +241,15 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
nodeTags
,
nodeInstancePrefix
,
tokenSource
,
true
/* useMetadataServer */
)
nodeTags
,
nodeInstancePrefix
,
tokenSource
,
true
/* useMetadataServer */
)
}
}
func
readConfig
(
reader
io
.
Reader
)
(
*
Config
,
error
)
{
cfg
:=
&
Config
{}
if
err
:=
gcfg
.
FatalOnly
(
gcfg
.
ReadInto
(
cfg
,
reader
));
err
!=
nil
{
glog
.
Errorf
(
"Couldn't read config: %v"
,
err
)
return
nil
,
err
}
return
cfg
,
nil
}
// Creates a GCECloud object using the specified parameters.
// Creates a GCECloud object using the specified parameters.
// If no networkUrl is specified, loads networkName via rest call.
// If no networkUrl is specified, loads networkName via rest call.
// If no tokenSource is specified, uses oauth2.DefaultTokenSource.
// If no tokenSource is specified, uses oauth2.DefaultTokenSource.
...
...
pkg/cloudprovider/providers/gce/gce_test.go
View file @
3f016859
...
@@ -18,9 +18,26 @@ package gce
...
@@ -18,9 +18,26 @@ package gce
import
(
import
(
"reflect"
"reflect"
"strings"
"testing"
"testing"
)
)
func
TestExtraKeyInConfig
(
t
*
testing
.
T
)
{
const
s
=
`[Global]
project-id = my-project
unknown-key = abc
network-name = my-network
`
reader
:=
strings
.
NewReader
(
s
)
config
,
err
:=
readConfig
(
reader
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected config parsing error %v"
,
err
)
}
if
config
.
Global
.
ProjectID
!=
"my-project"
||
config
.
Global
.
NetworkName
!=
"my-network"
{
t
.
Fatalf
(
"Expected config values to continue to be read despite extra key-value pair."
)
}
}
func
TestGetRegion
(
t
*
testing
.
T
)
{
func
TestGetRegion
(
t
*
testing
.
T
)
{
zoneName
:=
"us-central1-b"
zoneName
:=
"us-central1-b"
regionName
,
err
:=
GetGCERegion
(
zoneName
)
regionName
,
err
:=
GetGCERegion
(
zoneName
)
...
...
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