mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
Unit test unknown value in config
This commit is contained in:
parent
cde038b9be
commit
3f01685943
@ -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) {
|
|||||||
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.
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user