Move the common test functions from cmd_test.go to cmd/testing/fake.go

This is so that we can use NewAPIFactory() from cmd/set/*test.go
Up until now we would get a import loop error.

This commit also adds a basic unit test case for cmd/set/set_image.go
This commit is contained in:
Angus Salkeld
2016-10-19 08:53:26 +10:00
parent 4b7024efe7
commit d58554a647
32 changed files with 753 additions and 614 deletions

View File

@@ -25,6 +25,7 @@ import (
metrics_api "k8s.io/heapster/metrics/apis/metrics/v1alpha1"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"net/url"
)
@@ -40,7 +41,7 @@ func TestTopPodAllNamespacesMetrics(t *testing.T) {
expectedPath := fmt.Sprintf("%s/%s/pods", baseMetricsAddress, metricsApiVersion)
f, tf, _, ns := NewAPIFactory()
f, tf, _, ns := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
@@ -99,7 +100,7 @@ func TestTopPodAllInNamespaceMetrics(t *testing.T) {
}
expectedPath := fmt.Sprintf("%s/%s/namespaces/%s/pods", baseMetricsAddress, metricsApiVersion, testNamespace)
f, tf, _, ns := NewAPIFactory()
f, tf, _, ns := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
@@ -150,7 +151,7 @@ func TestTopPodWithNameMetrics(t *testing.T) {
expectedMetrics.Namespace = testNamespace
expectedPath := fmt.Sprintf("%s/%s/namespaces/%s/pods/%s", baseMetricsAddress, metricsApiVersion, testNamespace, expectedMetrics.Name)
f, tf, _, ns := NewAPIFactory()
f, tf, _, ns := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
@@ -203,7 +204,7 @@ func TestTopPodWithLabelSelectorMetrics(t *testing.T) {
expectedPath := fmt.Sprintf("%s/%s/namespaces/%s/pods", baseMetricsAddress, metricsApiVersion, testNamespace)
expectedQuery := fmt.Sprintf("labelSelector=%s", url.QueryEscape(label))
f, tf, _, ns := NewAPIFactory()
f, tf, _, ns := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
@@ -255,7 +256,7 @@ func TestTopPodWithContainersMetrics(t *testing.T) {
expectedMetrics.Namespace = testNamespace
expectedPath := fmt.Sprintf("%s/%s/namespaces/%s/pods/%s", baseMetricsAddress, metricsApiVersion, testNamespace, expectedMetrics.Name)
f, tf, _, ns := NewAPIFactory()
f, tf, _, ns := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,