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
e0ef253f
Commit
e0ef253f
authored
Jan 18, 2016
by
Paul Morie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add integration test for ConfigMap
parent
318705fe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
142 additions
and
5 deletions
+142
-5
configmap_test.go
test/integration/configmap_test.go
+134
-0
secret_test.go
test/integration/secret_test.go
+0
-5
utils.go
test/integration/utils.go
+8
-0
No files found.
test/integration/configmap_test.go
0 → 100644
View file @
e0ef253f
// +build integration,!no-etcd
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
integration
// This file tests use of the configMap API resource.
import
(
"net/http"
"net/http/httptest"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/master"
"k8s.io/kubernetes/test/integration/framework"
)
// TestConfigMap tests apiserver-side behavior of creation of ConfigMaps and pods that consume them.
func
TestConfigMap
(
t
*
testing
.
T
)
{
var
m
*
master
.
Master
s
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
m
.
Handler
.
ServeHTTP
(
w
,
req
)
}))
// TODO: Uncomment when fix #19254
// defer s.Close()
masterConfig
:=
framework
.
NewIntegrationTestMasterConfig
()
m
,
err
:=
master
.
New
(
masterConfig
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error in bringing up the master: %v"
,
err
)
}
framework
.
DeleteAllEtcdKeys
()
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
s
.
URL
,
ContentConfig
:
client
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
DoTestConfigMap
(
t
,
client
)
}
func
DoTestConfigMap
(
t
*
testing
.
T
,
client
*
client
.
Client
)
{
ns
:=
"ns"
cfg
:=
api
.
ConfigMap
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"configmap"
,
Namespace
:
ns
,
},
Data
:
map
[
string
]
string
{
"data-1"
:
"value-1"
,
"data-2"
:
"value-2"
,
"data-3"
:
"value-3"
,
},
}
if
_
,
err
:=
client
.
ConfigMaps
(
cfg
.
Namespace
)
.
Create
(
&
cfg
);
err
!=
nil
{
t
.
Errorf
(
"unable to create test configMap: %v"
,
err
)
}
defer
deleteConfigMapOrErrorf
(
t
,
client
,
cfg
.
Namespace
,
cfg
.
Name
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"XXX"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"fake-name"
,
Image
:
"fakeimage"
,
Env
:
[]
api
.
EnvVar
{
{
Name
:
"CONFIG_DATA_1"
,
ValueFrom
:
&
api
.
EnvVarSource
{
ConfigMapKeyRef
:
&
api
.
ConfigMapKeySelector
{
LocalObjectReference
:
api
.
LocalObjectReference
{
Name
:
"configmap"
,
},
Key
:
"data-1"
,
},
},
},
{
Name
:
"CONFIG_DATA_2"
,
ValueFrom
:
&
api
.
EnvVarSource
{
ConfigMapKeyRef
:
&
api
.
ConfigMapKeySelector
{
LocalObjectReference
:
api
.
LocalObjectReference
{
Name
:
"configmap"
,
},
Key
:
"data-2"
,
},
},
},
{
Name
:
"CONFIG_DATA_3"
,
ValueFrom
:
&
api
.
EnvVarSource
{
ConfigMapKeyRef
:
&
api
.
ConfigMapKeySelector
{
LocalObjectReference
:
api
.
LocalObjectReference
{
Name
:
"configmap"
,
},
Key
:
"data-3"
,
},
},
},
},
},
},
},
}
pod
.
ObjectMeta
.
Name
=
"uses-configmap"
if
_
,
err
:=
client
.
Pods
(
ns
)
.
Create
(
pod
);
err
!=
nil
{
t
.
Errorf
(
"Failed to create pod: %v"
,
err
)
}
defer
deletePodOrErrorf
(
t
,
client
,
ns
,
pod
.
Name
)
}
func
deleteConfigMapOrErrorf
(
t
*
testing
.
T
,
c
*
client
.
Client
,
ns
,
name
string
)
{
if
err
:=
c
.
ConfigMaps
(
ns
)
.
Delete
(
name
);
err
!=
nil
{
t
.
Errorf
(
"unable to delete ConfigMap %v: %v"
,
name
,
err
)
}
}
test/integration/secret_test.go
View file @
e0ef253f
...
@@ -32,11 +32,6 @@ import (
...
@@ -32,11 +32,6 @@ import (
"k8s.io/kubernetes/test/integration/framework"
"k8s.io/kubernetes/test/integration/framework"
)
)
func
deletePodOrErrorf
(
t
*
testing
.
T
,
c
*
client
.
Client
,
ns
,
name
string
)
{
if
err
:=
c
.
Pods
(
ns
)
.
Delete
(
name
,
nil
);
err
!=
nil
{
t
.
Errorf
(
"unable to delete pod %v: %v"
,
name
,
err
)
}
}
func
deleteSecretOrErrorf
(
t
*
testing
.
T
,
c
*
client
.
Client
,
ns
,
name
string
)
{
func
deleteSecretOrErrorf
(
t
*
testing
.
T
,
c
*
client
.
Client
,
ns
,
name
string
)
{
if
err
:=
c
.
Secrets
(
ns
)
.
Delete
(
name
);
err
!=
nil
{
if
err
:=
c
.
Secrets
(
ns
)
.
Delete
(
name
);
err
!=
nil
{
t
.
Errorf
(
"unable to delete secret %v: %v"
,
name
,
err
)
t
.
Errorf
(
"unable to delete secret %v: %v"
,
name
,
err
)
...
...
test/integration/utils.go
View file @
e0ef253f
...
@@ -21,10 +21,12 @@ import (
...
@@ -21,10 +21,12 @@ import (
"io/ioutil"
"io/ioutil"
"math/rand"
"math/rand"
"os"
"os"
"testing"
etcd
"github.com/coreos/etcd/client"
etcd
"github.com/coreos/etcd/client"
"github.com/golang/glog"
"github.com/golang/glog"
"golang.org/x/net/context"
"golang.org/x/net/context"
client
"k8s.io/kubernetes/pkg/client/unversioned"
)
)
func
newEtcdClient
()
etcd
.
Client
{
func
newEtcdClient
()
etcd
.
Client
{
...
@@ -77,3 +79,9 @@ func MakeTempDirOrDie(prefix string, baseDir string) string {
...
@@ -77,3 +79,9 @@ func MakeTempDirOrDie(prefix string, baseDir string) string {
}
}
return
tempDir
return
tempDir
}
}
func
deletePodOrErrorf
(
t
*
testing
.
T
,
c
*
client
.
Client
,
ns
,
name
string
)
{
if
err
:=
c
.
Pods
(
ns
)
.
Delete
(
name
,
nil
);
err
!=
nil
{
t
.
Errorf
(
"unable to delete pod %v: %v"
,
name
,
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