Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
ff7cb9ae
M
minikube
项目概览
Chu Peng 楚鹏
/
minikube
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
minikube
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ff7cb9ae
编写于
5月 13, 2016
作者:
D
Dan Gillespie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add kubeconfig tests
上级
b1ebe65c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
188 addition
and
0 deletion
+188
-0
pkg/minikube/kubeconfig/config_test.go
pkg/minikube/kubeconfig/config_test.go
+188
-0
未找到文件。
pkg/minikube/kubeconfig/config_test.go
0 → 100644
浏览文件 @
ff7cb9ae
package
kubeconfig
import
(
"io/ioutil"
"os"
"path/filepath"
"testing"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
)
func
TestEmptyConfig
(
t
*
testing
.
T
)
{
tmp
:=
tempFile
(
t
,
[]
byte
{})
defer
os
.
Remove
(
tmp
)
cfg
,
err
:=
ReadConfig
(
tmp
)
if
err
!=
nil
{
t
.
Fatalf
(
"could not read config: %v"
,
err
)
}
if
len
(
cfg
.
AuthInfos
)
!=
0
{
t
.
Fail
()
}
if
len
(
cfg
.
Clusters
)
!=
0
{
t
.
Fail
()
}
if
len
(
cfg
.
Contexts
)
!=
0
{
t
.
Fail
()
}
}
func
TestNewConfig
(
t
*
testing
.
T
)
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
".kube"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// setup minikube config
expected
:=
api
.
NewConfig
()
minikubeConfig
(
expected
)
// write actual
filename
:=
filepath
.
Join
(
dir
,
"config"
)
err
=
WriteConfig
(
expected
,
filename
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
actual
,
err
:=
ReadConfig
(
filename
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
configEquals
(
actual
,
expected
)
{
t
.
Fatal
(
"configs did not match"
)
}
}
// tempFile creates a temporary with the provided bytes as its contents.
// The caller is responsible for deleting file after use.
func
tempFile
(
t
*
testing
.
T
,
data
[]
byte
)
string
{
tmp
,
err
:=
ioutil
.
TempFile
(
""
,
"kubeconfig"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
data
)
>
0
{
if
_
,
err
:=
tmp
.
Write
(
data
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
if
err
:=
tmp
.
Close
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
tmp
.
Name
()
}
// minikubeConfig returns a config that reasonably approximates a localkube cluster
func
minikubeConfig
(
config
*
api
.
Config
)
{
// cluster
clusterName
:=
"minikube"
cluster
:=
api
.
NewCluster
()
cluster
.
Server
=
"https://192.168.99.100:443"
cluster
.
CertificateAuthority
=
"/home/tux/.minikube/apiserver.crt"
config
.
Clusters
[
clusterName
]
=
cluster
// user
userName
:=
"minikube"
user
:=
api
.
NewAuthInfo
()
user
.
ClientCertificate
=
"/home/tux/.minikube/apiserver.crt"
user
.
ClientKey
=
"/home/tux/.minikube/apiserver.key"
config
.
AuthInfos
[
userName
]
=
user
// context
contextName
:=
"minikube"
context
:=
api
.
NewContext
()
context
.
Cluster
=
clusterName
context
.
AuthInfo
=
userName
config
.
Contexts
[
contextName
]
=
context
config
.
CurrentContext
=
contextName
}
// configEquals checks if configs are identical
func
configEquals
(
a
,
b
*
api
.
Config
)
bool
{
if
a
.
Kind
!=
b
.
Kind
{
return
false
}
if
a
.
APIVersion
!=
b
.
APIVersion
{
return
false
}
if
a
.
Preferences
.
Colors
!=
b
.
Preferences
.
Colors
{
return
false
}
if
len
(
a
.
Extensions
)
!=
len
(
b
.
Extensions
)
{
return
false
}
// clusters
if
len
(
a
.
Clusters
)
!=
len
(
b
.
Clusters
)
{
return
false
}
for
k
,
aCluster
:=
range
a
.
Clusters
{
bCluster
,
exists
:=
b
.
Clusters
[
k
]
if
!
exists
{
return
false
}
if
aCluster
.
LocationOfOrigin
!=
bCluster
.
LocationOfOrigin
||
aCluster
.
Server
!=
bCluster
.
Server
||
aCluster
.
APIVersion
!=
bCluster
.
APIVersion
||
aCluster
.
InsecureSkipTLSVerify
!=
bCluster
.
InsecureSkipTLSVerify
||
aCluster
.
CertificateAuthority
!=
bCluster
.
CertificateAuthority
||
len
(
aCluster
.
CertificateAuthorityData
)
!=
len
(
bCluster
.
CertificateAuthorityData
)
||
len
(
aCluster
.
Extensions
)
!=
len
(
bCluster
.
Extensions
)
{
return
false
}
}
// users
if
len
(
a
.
AuthInfos
)
!=
len
(
b
.
AuthInfos
)
{
return
false
}
for
k
,
aAuth
:=
range
a
.
AuthInfos
{
bAuth
,
exists
:=
b
.
AuthInfos
[
k
]
if
!
exists
{
return
false
}
if
aAuth
.
LocationOfOrigin
!=
bAuth
.
LocationOfOrigin
||
aAuth
.
ClientCertificate
!=
bAuth
.
ClientCertificate
||
len
(
aAuth
.
ClientCertificateData
)
!=
len
(
bAuth
.
ClientCertificateData
)
||
aAuth
.
ClientKey
!=
bAuth
.
ClientKey
||
len
(
aAuth
.
ClientKeyData
)
!=
len
(
bAuth
.
ClientKeyData
)
||
aAuth
.
Token
!=
bAuth
.
Token
||
aAuth
.
Username
!=
bAuth
.
Username
||
aAuth
.
Password
!=
bAuth
.
Password
||
len
(
aAuth
.
Extensions
)
!=
len
(
bAuth
.
Extensions
)
{
return
false
}
}
// contexts
if
len
(
a
.
Contexts
)
!=
len
(
b
.
Contexts
)
{
return
false
}
for
k
,
aContext
:=
range
a
.
Contexts
{
bContext
,
exists
:=
b
.
Contexts
[
k
]
if
!
exists
{
return
false
}
if
aContext
.
LocationOfOrigin
!=
bContext
.
LocationOfOrigin
||
aContext
.
Cluster
!=
bContext
.
Cluster
||
aContext
.
AuthInfo
!=
bContext
.
AuthInfo
||
aContext
.
Namespace
!=
bContext
.
Namespace
||
len
(
aContext
.
Extensions
)
!=
len
(
aContext
.
Extensions
)
{
return
false
}
}
return
true
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录