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
8874ef9c
Commit
8874ef9c
authored
Apr 11, 2015
by
nikhiljindal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating test/integration to use testapi.Version everywhere
parent
86d30724
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
258 additions
and
86 deletions
+258
-86
testapi.go
pkg/api/testapi/testapi.go
+23
-7
testapi_test.go
pkg/api/testapi/testapi_test.go
+169
-0
auth_test.go
test/integration/auth_test.go
+0
-0
client_test.go
test/integration/client_test.go
+58
-64
etcd_tools_test.go
test/integration/etcd_tools_test.go
+3
-4
secret_test.go
test/integration/secret_test.go
+5
-11
No files found.
pkg/api/testapi/testapi.go
View file @
8874ef9c
...
...
@@ -20,6 +20,7 @@ package testapi
import
(
"fmt"
"os"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
...
...
@@ -76,14 +77,21 @@ func SelfLink(resource, name string) string {
return
fmt
.
Sprintf
(
"/api/%s/%s/%s"
,
Version
(),
resource
,
name
)
}
// Returns the appropriate path for the given resource, namespace and name.
// Returns the appropriate path for the given
prefix (watch, proxy, redirect, etc),
resource, namespace and name.
// For ex, this is of the form:
// /api/v1beta1/pods/pod0 for v1beta1 and
// /api/v1beta3/namespaces/foo/pods/pod0 for v1beta3.
func
ResourcePath
(
resource
,
namespace
,
name
string
)
string
{
// /api/v1beta1/
watch/
pods/pod0 for v1beta1 and
// /api/v1beta3/
watch/
namespaces/foo/pods/pod0 for v1beta3.
func
ResourcePath
WithPrefix
(
prefix
,
resource
,
namespace
,
name
string
)
string
{
path
:=
"/api/"
+
Version
()
if
!
api
.
PreV1Beta3
(
Version
())
&&
namespace
!=
""
{
path
=
path
+
"/namespaces/"
+
namespace
if
prefix
!=
""
{
path
=
path
+
"/"
+
prefix
}
if
!
api
.
PreV1Beta3
(
Version
())
{
if
namespace
!=
""
{
path
=
path
+
"/namespaces/"
+
namespace
}
// Resource names in v1beta3 are lower case.
resource
=
strings
.
ToLower
(
resource
)
}
if
resource
!=
""
{
path
=
path
+
"/"
+
resource
...
...
@@ -94,6 +102,14 @@ func ResourcePath(resource, namespace, name string) string {
return
path
}
// Returns the appropriate path for the given resource, namespace and name.
// For ex, this is of the form:
// /api/v1beta1/pods/pod0 for v1beta1 and
// /api/v1beta3/namespaces/foo/pods/pod0 for v1beta3.
func
ResourcePath
(
resource
,
namespace
,
name
string
)
string
{
return
ResourcePathWithPrefix
(
""
,
resource
,
namespace
,
name
)
}
// Returns the appropriate path along with the query params for the given resource, namespace and name.
// For ex, this is of the form:
// /api/v1beta1/pods/pod0?namespace=foo for v1beta1 and
...
...
@@ -101,7 +117,7 @@ func ResourcePath(resource, namespace, name string) string {
func
ResourcePathWithQueryParams
(
resource
,
namespace
,
name
string
)
string
{
path
:=
ResourcePath
(
resource
,
namespace
,
name
)
// Add namespace as query param for pre v1beta3.
if
api
.
PreV1Beta3
(
Version
())
{
if
api
.
PreV1Beta3
(
Version
())
&&
namespace
!=
""
{
path
=
path
+
"?namespace="
+
namespace
}
return
path
...
...
pkg/api/testapi/testapi_test.go
0 → 100644
View file @
8874ef9c
/*
Copyright 2015 Google Inc. 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
testapi
import
(
"testing"
)
func
TestResourcePathWithPrefixForV1Beta3
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1beta3"
{
// Skip the test if we are not testing v1beta3.
return
}
testCases
:=
[]
struct
{
prefix
string
resource
string
namespace
string
name
string
expected
string
}{
{
"prefix"
,
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1beta3/prefix/namespaces/mynamespace/resource/myresource"
},
{
"prefix"
,
"resource"
,
""
,
"myresource"
,
"/api/v1beta3/prefix/resource/myresource"
},
{
"prefix"
,
"resource"
,
"mynamespace"
,
""
,
"/api/v1beta3/prefix/namespaces/mynamespace/resource"
},
{
"prefix"
,
"resource"
,
""
,
""
,
"/api/v1beta3/prefix/resource"
},
{
""
,
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1beta3/namespaces/mynamespace/resource/myresource"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
ResourcePathWithPrefix
(
item
.
prefix
,
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
t
.
Errorf
(
"Expected: %s, got: %s for prefix: %s, resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
prefix
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
}
}
}
func
TestResourcePathWithPrefixForV1Beta1
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1beta1"
{
// Skip the test if we are not testing v1beta1.
return
}
testCases
:=
[]
struct
{
prefix
string
resource
string
namespace
string
name
string
expected
string
}{
{
"prefix"
,
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1beta1/prefix/resource/myresource"
},
{
"prefix"
,
"resource"
,
""
,
"myresource"
,
"/api/v1beta1/prefix/resource/myresource"
},
{
"prefix"
,
"resource"
,
"mynamespace"
,
""
,
"/api/v1beta1/prefix/resource"
},
{
"prefix"
,
"resource"
,
""
,
""
,
"/api/v1beta1/prefix/resource"
},
{
""
,
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1beta1/resource/myresource"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
ResourcePathWithPrefix
(
item
.
prefix
,
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
t
.
Errorf
(
"Expected: %s, got: %s for prefix: %s, resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
prefix
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
}
}
}
func
TestResourcePathForV1Beta3
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1beta3"
{
// Skip the test if we are not testing v1beta3.
return
}
testCases
:=
[]
struct
{
resource
string
namespace
string
name
string
expected
string
}{
{
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1beta3/namespaces/mynamespace/resource/myresource"
},
{
"resource"
,
""
,
"myresource"
,
"/api/v1beta3/resource/myresource"
},
{
"resource"
,
"mynamespace"
,
""
,
"/api/v1beta3/namespaces/mynamespace/resource"
},
{
"resource"
,
""
,
""
,
"/api/v1beta3/resource"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
ResourcePath
(
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
t
.
Errorf
(
"Expected: %s, got: %s for resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
}
}
}
func
TestResourcePathForV1Beta1
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1beta1"
{
// Skip the test if we are not testing v1beta1.
return
}
testCases
:=
[]
struct
{
resource
string
namespace
string
name
string
expected
string
}{
{
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1beta1/resource/myresource"
},
{
"resource"
,
""
,
"myresource"
,
"/api/v1beta1/resource/myresource"
},
{
"resource"
,
"mynamespace"
,
""
,
"/api/v1beta1/resource"
},
{
"resource"
,
""
,
""
,
"/api/v1beta1/resource"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
ResourcePath
(
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
t
.
Errorf
(
"Expected: %s, got: %s for resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
}
}
}
func
TestResourcePathWithQueryParamsForV1Beta3
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1beta3"
{
// Skip the test if we are not testing v1beta3.
return
}
testCases
:=
[]
struct
{
resource
string
namespace
string
name
string
expected
string
}{
{
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1beta3/namespaces/mynamespace/resource/myresource"
},
{
"resource"
,
""
,
"myresource"
,
"/api/v1beta3/resource/myresource"
},
{
"resource"
,
"mynamespace"
,
""
,
"/api/v1beta3/namespaces/mynamespace/resource"
},
{
"resource"
,
""
,
""
,
"/api/v1beta3/resource"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
ResourcePathWithQueryParams
(
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
t
.
Errorf
(
"Expected: %s, got: %s for resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
}
}
}
func
TestResourcePathWithQueryParamsForV1Beta1
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1beta1"
{
// Skip the test if we are not testing v1beta1.
return
}
testCases
:=
[]
struct
{
resource
string
namespace
string
name
string
expected
string
}{
{
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1beta1/resource/myresource?namespace=mynamespace"
},
{
"resource"
,
""
,
"myresource"
,
"/api/v1beta1/resource/myresource"
},
{
"resource"
,
"mynamespace"
,
""
,
"/api/v1beta1/resource?namespace=mynamespace"
},
{
"resource"
,
""
,
""
,
"/api/v1beta1/resource"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
ResourcePathWithQueryParams
(
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
t
.
Errorf
(
"Expected: %s, got: %s for resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
}
}
}
test/integration/auth_test.go
View file @
8874ef9c
This diff is collapsed.
Click to expand it.
test/integration/client_test.go
View file @
8874ef9c
...
...
@@ -30,6 +30,7 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
...
...
@@ -45,7 +46,7 @@ func init() {
}
func
RunAMaster
(
t
*
testing
.
T
)
(
*
master
.
Master
,
*
httptest
.
Server
)
{
helper
,
err
:=
master
.
NewEtcdHelper
(
newEtcdClient
(),
"v1beta1"
)
helper
,
err
:=
master
.
NewEtcdHelper
(
newEtcdClient
(),
testapi
.
Version
()
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
...
...
@@ -73,76 +74,69 @@ func TestClient(t *testing.T) {
_
,
s
:=
RunAMaster
(
t
)
defer
s
.
Close
()
testCases
:=
[]
string
{
"v1beta1"
,
"v1beta2"
,
"v1beta3"
,
}
for
_
,
apiVersion
:=
range
testCases
{
ns
:=
api
.
NamespaceDefault
deleteAllEtcdKeys
()
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
s
.
URL
,
Version
:
apiVersion
})
ns
:=
api
.
NamespaceDefault
deleteAllEtcdKeys
()
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
s
.
URL
,
Version
:
testapi
.
Version
()})
info
,
err
:=
client
.
ServerVersion
()
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
e
,
a
:=
version
.
Get
(),
*
info
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"expected %#v, got %#v"
,
e
,
a
)
}
info
,
err
:=
client
.
ServerVersion
()
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
e
,
a
:=
version
.
Get
(),
*
info
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"expected %#v, got %#v"
,
e
,
a
)
}
pods
,
err
:=
client
.
Pods
(
ns
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
len
(
pods
.
Items
)
!=
0
{
t
.
Errorf
(
"expected no pods, got %#v"
,
pods
)
}
pods
,
err
:=
client
.
Pods
(
ns
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
len
(
pods
.
Items
)
!=
0
{
t
.
Errorf
(
"expected no pods, got %#v"
,
pods
)
}
// get a validation error
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
GenerateName
:
"test"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"test"
,
},
// get a validation error
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
GenerateName
:
"test"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"test"
,
},
},
}
},
}
got
,
err
:=
client
.
Pods
(
ns
)
.
Create
(
pod
)
if
err
==
nil
{
t
.
Fatalf
(
"unexpected non-error: %v"
,
got
)
}
got
,
err
:=
client
.
Pods
(
ns
)
.
Create
(
pod
)
if
err
==
nil
{
t
.
Fatalf
(
"unexpected non-error: %v"
,
got
)
}
// get a created pod
pod
.
Spec
.
Containers
[
0
]
.
Image
=
"an-image"
got
,
err
=
client
.
Pods
(
ns
)
.
Create
(
pod
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
got
.
Name
==
""
{
t
.
Errorf
(
"unexpected empty pod Name %v"
,
got
)
}
// get a created pod
pod
.
Spec
.
Containers
[
0
]
.
Image
=
"an-image"
got
,
err
=
client
.
Pods
(
ns
)
.
Create
(
pod
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
got
.
Name
==
""
{
t
.
Errorf
(
"unexpected empty pod Name %v"
,
got
)
}
// pod is shown, but not scheduled
pods
,
err
=
client
.
Pods
(
ns
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
len
(
pods
.
Items
)
!=
1
{
t
.
Errorf
(
"expected one pod, got %#v"
,
pods
)
}
actual
:=
pods
.
Items
[
0
]
if
actual
.
Name
!=
got
.
Name
{
t
.
Errorf
(
"expected pod %#v, got %#v"
,
got
,
actual
)
}
if
actual
.
Spec
.
Host
!=
""
{
t
.
Errorf
(
"expected pod to be unscheduled, got %#v"
,
actual
)
}
// pod is shown, but not scheduled
pods
,
err
=
client
.
Pods
(
ns
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
len
(
pods
.
Items
)
!=
1
{
t
.
Errorf
(
"expected one pod, got %#v"
,
pods
)
}
actual
:=
pods
.
Items
[
0
]
if
actual
.
Name
!=
got
.
Name
{
t
.
Errorf
(
"expected pod %#v, got %#v"
,
got
,
actual
)
}
if
actual
.
Spec
.
Host
!=
""
{
t
.
Errorf
(
"expected pod to be unscheduled, got %#v"
,
actual
)
}
}
...
...
@@ -159,7 +153,7 @@ func TestMultiWatch(t *testing.T) {
defer
s
.
Close
()
ns
:=
api
.
NamespaceDefault
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
s
.
URL
,
Version
:
"v1beta1"
})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
s
.
URL
,
Version
:
testapi
.
Version
()
})
dummyEvent
:=
func
(
i
int
)
*
api
.
Event
{
name
:=
fmt
.
Sprintf
(
"unrelated-%v"
,
i
)
...
...
test/integration/etcd_tools_test.go
View file @
8874ef9c
...
...
@@ -23,8 +23,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
...
...
@@ -93,9 +92,9 @@ func TestExtractObj(t *testing.T) {
func
TestWatch
(
t
*
testing
.
T
)
{
client
:=
newEtcdClient
()
helper
:=
tools
.
NewEtcdHelper
(
client
,
latest
.
Codec
)
helper
:=
tools
.
NewEtcdHelper
(
client
,
testapi
.
Codec
()
)
withEtcdKey
(
func
(
key
string
)
{
resp
,
err
:=
client
.
Set
(
key
,
runtime
.
EncodeOrDie
(
v1beta1
.
Codec
,
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}),
0
)
resp
,
err
:=
client
.
Set
(
key
,
runtime
.
EncodeOrDie
(
testapi
.
Codec
()
,
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
}}),
0
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
...
...
test/integration/secret_test.go
View file @
8874ef9c
...
...
@@ -26,6 +26,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
...
...
@@ -49,7 +50,7 @@ func deleteSecretOrErrorf(t *testing.T, c *client.Client, ns, name string) {
// TestSecrets tests apiserver-side behavior of creation of secret objects and their use by pods.
func
TestSecrets
(
t
*
testing
.
T
)
{
helper
,
err
:=
master
.
NewEtcdHelper
(
newEtcdClient
(),
"v1beta1"
)
helper
,
err
:=
master
.
NewEtcdHelper
(
newEtcdClient
(),
testapi
.
Version
()
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
...
...
@@ -71,16 +72,9 @@ func TestSecrets(t *testing.T) {
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
})
testCases
:=
[]
string
{
"v1beta1"
,
"v1beta2"
,
}
for
_
,
apiVersion
:=
range
testCases
{
deleteAllEtcdKeys
()
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
s
.
URL
,
Version
:
apiVersion
})
DoTestSecrets
(
t
,
client
,
apiVersion
)
}
deleteAllEtcdKeys
()
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
s
.
URL
,
Version
:
testapi
.
Version
()})
DoTestSecrets
(
t
,
client
,
testapi
.
Version
())
}
// DoTestSecrets test secrets for one api version.
...
...
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