Skip to content

Instantly share code, notes, and snippets.

@monchier
Created October 8, 2020 22:47
Show Gist options
  • Save monchier/3d77a42d29f3558433fa120455b41e35 to your computer and use it in GitHub Desktop.
Save monchier/3d77a42d29f3558433fa120455b41e35 to your computer and use it in GitHub Desktop.
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