Created
October 8, 2020 22:47
-
-
Save monchier/3d77a42d29f3558433fa120455b41e35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"github.com/stretchr/testify/assert" | |
apiv1 "k8s.io/api/core/v1" | |
"k8s.io/apimachinery/pkg/api/resource" | |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
"k8s.io/apimachinery/pkg/runtime" | |
"k8s.io/metrics/pkg/apis/metrics/v1beta1" | |
mfake "k8s.io/metrics/pkg/client/clientset/versioned/fake" | |
"testing" | |
"time" | |
) | |
func Test_MetricsWatcher(t *testing.T) { | |
objects := []runtime.Object{&v1beta1.PodMetrics{ | |
ObjectMeta: metav1.ObjectMeta{ | |
Name: "some pod", | |
Namespace: metav1.NamespaceDefault, | |
}, | |
Timestamp:metav1.Time{Time: time.Now()}, | |
Window:metav1.Duration{Duration:time.Second}, | |
Containers: []v1beta1.ContainerMetrics{ | |
{ | |
Usage: map[apiv1.ResourceName]resource.Quantity{ | |
apiv1.ResourceCPU: *resource.NewMilliQuantity(1, resource.DecimalSI), | |
apiv1.ResourceMemory: *resource.NewQuantity(100, resource.DecimalSI), | |
}, | |
}, | |
}, | |
}} | |
metricsClient := mfake.NewSimpleClientset(objects...) | |
_, err := metricsClient.MetricsV1beta1().PodMetricses(apiv1.NamespaceDefault).Get("some pod", metav1.GetOptions{}) | |
assert.Nil(t, err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment