diff --git a/.gitignore b/.gitignore index 69912fb6..0d43dde1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,8 @@ dist notes styles vendor -go.mod1 \ No newline at end of file +go.mod1 +popeye1.go +gen.sh +cluster_info_test.go +*.test diff --git a/go.sum b/go.sum index 640ed2f1..3ada0062 100644 --- a/go.sum +++ b/go.sum @@ -117,6 +117,7 @@ github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+v github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/petergtz/pegomock v0.0.0-20181206220228-b113d17a7e81 h1:MhSbvsIs4KvpPYr4taOvb6j+r9VNbj/08AfjsKi+Ui0= github.com/petergtz/pegomock v0.0.0-20181206220228-b113d17a7e81/go.mod h1:nuBLWZpVyv/fLo56qTwt/AUau7jgouO1h7bEvZCq82o= +github.com/petergtz/pegomock v2.2.0+incompatible h1:UjfRYEyjM8X8lNPuZs8FKakZI1pD7FqMRYc6KfLFNJU= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/internal/config/config.go b/internal/config/config.go index 04fad978..75e1d12b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -52,10 +52,6 @@ func NewConfig(ks KubeSettings) *Config { return &Config{K9s: NewK9s(), settings: ks} } -func isSet(s *string) bool { - return s != nil && len(*s) > 0 -} - // Refine the configuration based on cli args. func (c *Config) Refine(flags *genericclioptions.ConfigFlags) { cfg, err := flags.ToRawKubeConfigLoader().RawConfig() @@ -205,3 +201,10 @@ func (c *Config) Dump(msg string) { log.Debug().Msgf("K9s cluster: %s -- %s\n", k, cl.Namespace) } } + +// ---------------------------------------------------------------------------- +// Helpers... + +func isSet(s *string) bool { + return s != nil && len(*s) > 0 +} diff --git a/internal/config/mock_connection_test.go b/internal/config/mock_connection_test.go index 82c41068..f5df4912 100644 --- a/internal/config/mock_connection_test.go +++ b/internal/config/mock_connection_test.go @@ -7,6 +7,7 @@ import ( k8s "github.com/derailed/k9s/internal/k8s" pegomock "github.com/petergtz/pegomock" v1 "k8s.io/api/core/v1" + version "k8s.io/apimachinery/pkg/version" dynamic "k8s.io/client-go/dynamic" kubernetes "k8s.io/client-go/kubernetes" rest "k8s.io/client-go/rest" @@ -68,6 +69,25 @@ func (mock *MockConnection) DynDialOrDie() dynamic.Interface { return ret0 } +func (mock *MockConnection) FetchNodes() (*v1.NodeList, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodes", params, []reflect.Type{reflect.TypeOf((**v1.NodeList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *v1.NodeList + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*v1.NodeList) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + func (mock *MockConnection) HasMetrics() bool { if mock == nil { panic("mock must not be nil. Use myMock := NewMockConnection().") @@ -147,6 +167,25 @@ func (mock *MockConnection) RestConfigOrDie() *rest.Config { return ret0 } +func (mock *MockConnection) ServerVersion() (*version.Info, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("ServerVersion", params, []reflect.Type{reflect.TypeOf((**version.Info)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *version.Info + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*version.Info) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + func (mock *MockConnection) SupportsRes(_param0 string, _param1 []string) (string, bool) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockConnection().") @@ -315,6 +354,23 @@ func (c *Connection_DynDialOrDie_OngoingVerification) GetCapturedArguments() { func (c *Connection_DynDialOrDie_OngoingVerification) GetAllCapturedArguments() { } +func (verifier *VerifierConnection) FetchNodes() *Connection_FetchNodes_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchNodes", params, verifier.timeout) + return &Connection_FetchNodes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_FetchNodes_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_FetchNodes_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_FetchNodes_OngoingVerification) GetAllCapturedArguments() { +} + func (verifier *VerifierConnection) HasMetrics() *Connection_HasMetrics_OngoingVerification { params := []pegomock.Param{} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) @@ -410,6 +466,23 @@ func (c *Connection_RestConfigOrDie_OngoingVerification) GetCapturedArguments() func (c *Connection_RestConfigOrDie_OngoingVerification) GetAllCapturedArguments() { } +func (verifier *VerifierConnection) ServerVersion() *Connection_ServerVersion_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ServerVersion", params, verifier.timeout) + return &Connection_ServerVersion_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_ServerVersion_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_ServerVersion_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_ServerVersion_OngoingVerification) GetAllCapturedArguments() { +} + func (verifier *VerifierConnection) SupportsRes(_param0 string, _param1 []string) *Connection_SupportsRes_OngoingVerification { params := []pegomock.Param{_param0, _param1} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsRes", params, verifier.timeout) diff --git a/internal/k8s/api.go b/internal/k8s/api.go index 5414f774..97e3eb1e 100644 --- a/internal/k8s/api.go +++ b/internal/k8s/api.go @@ -9,6 +9,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/version" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" restclient "k8s.io/client-go/rest" @@ -57,6 +58,8 @@ type ( ValidNamespaces() ([]v1.Namespace, error) ValidPods(node string) ([]v1.Pod, error) SupportsRes(grp string, versions []string) (string, bool) + ServerVersion() (*version.Info, error) + FetchNodes() (*v1.NodeList, error) } // APIClient represents a Kubernetes api client. @@ -80,6 +83,16 @@ func InitConnectionOrDie(config *Config, logger zerolog.Logger) *APIClient { return &conn } +// ServerVersion returns the current server version info. +func (a *APIClient) ServerVersion() (*version.Info, error) { + return a.DialOrDie().Discovery().ServerVersion() +} + +// FetchNodes returns all available nodes. +func (a *APIClient) FetchNodes() (*v1.NodeList, error) { + return a.DialOrDie().CoreV1().Nodes().List(metav1.ListOptions{}) +} + // ValidNamespaces returns all available namespaces. func (a *APIClient) ValidNamespaces() ([]v1.Namespace, error) { nn, err := a.DialOrDie().CoreV1().Namespaces().List(metav1.ListOptions{}) diff --git a/internal/k8s/cluster.go b/internal/k8s/cluster.go index 9c301274..e6e0c94f 100644 --- a/internal/k8s/cluster.go +++ b/internal/k8s/cluster.go @@ -3,7 +3,6 @@ package k8s import ( "github.com/rs/zerolog" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // Cluster represents a Kubernetes cluster. @@ -20,7 +19,7 @@ func NewCluster(c Connection, l *zerolog.Logger) *Cluster { // Version returns the current cluster git version. func (c *Cluster) Version() (string, error) { - rev, err := c.DialOrDie().Discovery().ServerVersion() + rev, err := c.ServerVersion() if err != nil { c.logger.Warn().Msgf("%s", err) return "", err @@ -58,9 +57,9 @@ func (c *Cluster) UserName() string { return usr } -// FetchNodes get all available nodes in the cluster. -func (c *Cluster) FetchNodes() ([]v1.Node, error) { - list, err := c.DialOrDie().CoreV1().Nodes().List(metav1.ListOptions{}) +// GetNodes get all available nodes in the cluster. +func (c *Cluster) GetNodes() ([]v1.Node, error) { + list, err := c.FetchNodes() if err != nil { return nil, err } diff --git a/internal/resource/cluster.go b/internal/resource/cluster.go index e8d2f1c9..dff86f8b 100644 --- a/internal/resource/cluster.go +++ b/internal/resource/cluster.go @@ -16,7 +16,7 @@ type ( ContextName() string ClusterName() string UserName() string - FetchNodes() ([]v1.Node, error) + GetNodes() ([]v1.Node, error) } // MetricsServer gather metrics information from pods and nodes. @@ -87,7 +87,7 @@ func (c *Cluster) FetchNodesMetrics() ([]mv1beta1.NodeMetrics, error) { return c.mx.FetchNodesMetrics() } -// FetchNodes fetch all available nodes. -func (c *Cluster) FetchNodes() ([]v1.Node, error) { - return c.api.FetchNodes() +// GetNodes fetch all available nodes. +func (c *Cluster) GetNodes() ([]v1.Node, error) { + return c.api.GetNodes() } diff --git a/internal/resource/cluster_test.go b/internal/resource/cluster_test.go index 0a5feadd..81494205 100644 --- a/internal/resource/cluster_test.go +++ b/internal/resource/cluster_test.go @@ -62,11 +62,11 @@ func TestClusterMetrics(t *testing.T) { func TestClusterGetNodes(t *testing.T) { mm, mx := NewMockClusterMeta(), NewMockMetricsServer() - m.When(mm.FetchNodes()).ThenReturn([]v1.Node{*k8sNode()}, nil) + m.When(mm.GetNodes()).ThenReturn([]v1.Node{*k8sNode()}, nil) m.When(mx.ClusterLoad([]v1.Node{}, []mv1beta1.NodeMetrics{})).ThenReturn(clusterMetric()) c := resource.NewClusterWithArgs(mm, mx) - nodes, err := c.FetchNodes() + nodes, err := c.GetNodes() assert.Nil(t, err) assert.Equal(t, 1, len(nodes)) @@ -74,7 +74,7 @@ func TestClusterGetNodes(t *testing.T) { func TestClusterFetchNodesMetrics(t *testing.T) { mm, mx := NewMockClusterMeta(), NewMockMetricsServer() - m.When(mm.FetchNodes()).ThenReturn([]v1.Node{*k8sNode()}, nil) + m.When(mm.GetNodes()).ThenReturn([]v1.Node{*k8sNode()}, nil) m.When(mx.FetchNodesMetrics()).ThenReturn([]mv1beta1.NodeMetrics{makeMxNode("fred", "100m", "10Mi")}, nil) c := resource.NewClusterWithArgs(mm, mx) diff --git a/internal/resource/mock_clustermeta_test.go b/internal/resource/mock_clustermeta_test.go index b319ffd2..fb4e70cb 100644 --- a/internal/resource/mock_clustermeta_test.go +++ b/internal/resource/mock_clustermeta_test.go @@ -7,6 +7,7 @@ import ( k8s "github.com/derailed/k9s/internal/k8s" pegomock "github.com/petergtz/pegomock" v1 "k8s.io/api/core/v1" + version "k8s.io/apimachinery/pkg/version" dynamic "k8s.io/client-go/dynamic" kubernetes "k8s.io/client-go/kubernetes" rest "k8s.io/client-go/rest" @@ -98,12 +99,31 @@ func (mock *MockClusterMeta) DynDialOrDie() dynamic.Interface { return ret0 } -func (mock *MockClusterMeta) FetchNodes() ([]v1.Node, error) { +func (mock *MockClusterMeta) FetchNodes() (*v1.NodeList, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClusterMeta().") } params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodes", params, []reflect.Type{reflect.TypeOf((*[]v1.Node)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodes", params, []reflect.Type{reflect.TypeOf((**v1.NodeList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *v1.NodeList + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*v1.NodeList) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockClusterMeta) GetNodes() ([]v1.Node, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("GetNodes", params, []reflect.Type{reflect.TypeOf((*[]v1.Node)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) var ret0 []v1.Node var ret1 error if len(result) != 0 { @@ -196,6 +216,25 @@ func (mock *MockClusterMeta) RestConfigOrDie() *rest.Config { return ret0 } +func (mock *MockClusterMeta) ServerVersion() (*version.Info, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("ServerVersion", params, []reflect.Type{reflect.TypeOf((**version.Info)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *version.Info + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*version.Info) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + func (mock *MockClusterMeta) SupportsRes(_param0 string, _param1 []string) (string, bool) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClusterMeta().") @@ -449,6 +488,23 @@ func (c *ClusterMeta_FetchNodes_OngoingVerification) GetCapturedArguments() { func (c *ClusterMeta_FetchNodes_OngoingVerification) GetAllCapturedArguments() { } +func (verifier *VerifierClusterMeta) GetNodes() *ClusterMeta_GetNodes_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetNodes", params, verifier.timeout) + return &ClusterMeta_GetNodes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_GetNodes_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_GetNodes_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_GetNodes_OngoingVerification) GetAllCapturedArguments() { +} + func (verifier *VerifierClusterMeta) HasMetrics() *ClusterMeta_HasMetrics_OngoingVerification { params := []pegomock.Param{} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) @@ -544,6 +600,23 @@ func (c *ClusterMeta_RestConfigOrDie_OngoingVerification) GetCapturedArguments() func (c *ClusterMeta_RestConfigOrDie_OngoingVerification) GetAllCapturedArguments() { } +func (verifier *VerifierClusterMeta) ServerVersion() *ClusterMeta_ServerVersion_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ServerVersion", params, verifier.timeout) + return &ClusterMeta_ServerVersion_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_ServerVersion_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_ServerVersion_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_ServerVersion_OngoingVerification) GetAllCapturedArguments() { +} + func (verifier *VerifierClusterMeta) SupportsRes(_param0 string, _param1 []string) *ClusterMeta_SupportsRes_OngoingVerification { params := []pegomock.Param{_param0, _param1} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsRes", params, verifier.timeout) diff --git a/internal/resource/mock_connection_test.go b/internal/resource/mock_connection_test.go index fe6db524..213e1a45 100644 --- a/internal/resource/mock_connection_test.go +++ b/internal/resource/mock_connection_test.go @@ -7,6 +7,7 @@ import ( k8s "github.com/derailed/k9s/internal/k8s" pegomock "github.com/petergtz/pegomock" v1 "k8s.io/api/core/v1" + version "k8s.io/apimachinery/pkg/version" dynamic "k8s.io/client-go/dynamic" kubernetes "k8s.io/client-go/kubernetes" rest "k8s.io/client-go/rest" @@ -68,6 +69,25 @@ func (mock *MockConnection) DynDialOrDie() dynamic.Interface { return ret0 } +func (mock *MockConnection) FetchNodes() (*v1.NodeList, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodes", params, []reflect.Type{reflect.TypeOf((**v1.NodeList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *v1.NodeList + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*v1.NodeList) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + func (mock *MockConnection) HasMetrics() bool { if mock == nil { panic("mock must not be nil. Use myMock := NewMockConnection().") @@ -147,6 +167,25 @@ func (mock *MockConnection) RestConfigOrDie() *rest.Config { return ret0 } +func (mock *MockConnection) ServerVersion() (*version.Info, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("ServerVersion", params, []reflect.Type{reflect.TypeOf((**version.Info)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *version.Info + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*version.Info) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + func (mock *MockConnection) SupportsRes(_param0 string, _param1 []string) (string, bool) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockConnection().") @@ -315,6 +354,23 @@ func (c *Connection_DynDialOrDie_OngoingVerification) GetCapturedArguments() { func (c *Connection_DynDialOrDie_OngoingVerification) GetAllCapturedArguments() { } +func (verifier *VerifierConnection) FetchNodes() *Connection_FetchNodes_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchNodes", params, verifier.timeout) + return &Connection_FetchNodes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_FetchNodes_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_FetchNodes_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_FetchNodes_OngoingVerification) GetAllCapturedArguments() { +} + func (verifier *VerifierConnection) HasMetrics() *Connection_HasMetrics_OngoingVerification { params := []pegomock.Param{} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) @@ -410,6 +466,23 @@ func (c *Connection_RestConfigOrDie_OngoingVerification) GetCapturedArguments() func (c *Connection_RestConfigOrDie_OngoingVerification) GetAllCapturedArguments() { } +func (verifier *VerifierConnection) ServerVersion() *Connection_ServerVersion_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ServerVersion", params, verifier.timeout) + return &Connection_ServerVersion_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_ServerVersion_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_ServerVersion_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_ServerVersion_OngoingVerification) GetAllCapturedArguments() { +} + func (verifier *VerifierConnection) SupportsRes(_param0 string, _param1 []string) *Connection_SupportsRes_OngoingVerification { params := []pegomock.Param{_param0, _param1} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsRes", params, verifier.timeout) diff --git a/internal/views/app.go b/internal/views/app.go index 0e5bfe49..a7ffde30 100644 --- a/internal/views/app.go +++ b/internal/views/app.go @@ -63,11 +63,6 @@ type ( } ) -func init() { - initKeys() - initStyles() -} - // NewApp returns a K9s app instance. func NewApp(cfg *config.Config) *appView { v := appView{Application: tview.NewApplication(), config: cfg} @@ -81,7 +76,7 @@ func NewApp(cfg *config.Config) *appView { v.command = newCommand(&v) v.flashView = newFlashView(v.Application, "Initializing...") v.crumbsView = newCrumbsView(v.Application) - v.clusterInfoView = newInfoView(&v) + v.clusterInfoView = newClusterInfoView(&v, k8s.NewMetricsServer(cfg.GetConnection())) v.focusChanged = v.changedFocus v.SetInputCapture(v.keyboard) } diff --git a/internal/views/cluster_info.go b/internal/views/cluster_info.go index c06b2fae..06ed8ed4 100644 --- a/internal/views/cluster_info.go +++ b/internal/views/cluster_info.go @@ -3,7 +3,6 @@ package views import ( "strings" - "github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/resource" "github.com/derailed/tview" "github.com/gdamore/tcell" @@ -17,11 +16,21 @@ type clusterInfoView struct { cluster *resource.Cluster } -func newInfoView(app *appView) *clusterInfoView { +type ClusterInfo interface { + ContextName() string + ClusterName() string + UserName() string + K9sVersion() string + K8sVersion() string + CurrentCPU() float64 + CurrentMEM() float64 +} + +func newClusterInfoView(app *appView, mx resource.MetricsServer) *clusterInfoView { return &clusterInfoView{ app: app, Table: tview.NewTable(), - cluster: resource.NewCluster(app.conn(), &log.Logger, k8s.NewMetricsServer(app.conn())), + cluster: resource.NewCluster(app.conn(), &log.Logger, mx), } } @@ -82,7 +91,7 @@ func (v *clusterInfoView) refresh() { v.GetCell(row, 1).SetText(v.cluster.Version()) row++ - nodes, err := v.cluster.FetchNodes() + nodes, err := v.cluster.GetNodes() if err != nil { log.Warn().Msgf("ClusterInfo %s", err) return diff --git a/internal/views/colorer.go b/internal/views/colorer.go index 274ef69d..55366a27 100644 --- a/internal/views/colorer.go +++ b/internal/views/colorer.go @@ -92,11 +92,17 @@ func pvColorer(ns string, r *resource.RowEvent) tcell.Color { return c } - if strings.TrimSpace(r.Fields[4]) != "Bound" { - return errColor + status := strings.TrimSpace(r.Fields[4]) + switch status { + case "Bound": + c = stdColor + case "Available": + c = tcell.ColorYellow + default: + c = errColor } - return stdColor + return c } func pvcColorer(ns string, r *resource.RowEvent) tcell.Color { diff --git a/internal/views/details.go b/internal/views/details.go index 07977962..0b790f47 100644 --- a/internal/views/details.go +++ b/internal/views/details.go @@ -31,7 +31,7 @@ func newDetailsView(app *appView, backFn actionHandler) *detailsView { { v.backFn = backFn v.SetScrollable(true) - v.SetWrap(false) + v.SetWrap(true) v.SetDynamicColors(true) v.SetRegions(true) v.SetBorder(true) diff --git a/internal/views/helpers.go b/internal/views/helpers.go index 23f2132b..39a3f44b 100644 --- a/internal/views/helpers.go +++ b/internal/views/helpers.go @@ -2,6 +2,7 @@ package views import ( "fmt" + "regexp" "strconv" "strings" "time" @@ -31,6 +32,18 @@ func deltas(o, n string) string { } } + if i, ok := percentage(o); ok { + j, _ := percentage(n) + switch { + case i < j: + return plus() + case i > j: + return minus() + default: + return "" + } + } + if q1, err := resource.ParseQuantity(o); err == nil { q2, _ := resource.ParseQuantity(n) switch q1.Cmp(q2) { @@ -63,6 +76,17 @@ func deltas(o, n string) string { } } +var percent = regexp.MustCompile(`\A(\d+)\%\z`) + +func percentage(s string) (int, bool) { + if res := percent.FindStringSubmatch(s); len(res) == 2 { + n, _ := strconv.Atoi(res[1]) + return n, true + } + + return 0, false +} + func numerical(s string) (int, bool) { n, err := strconv.Atoi(s) if err != nil { diff --git a/internal/views/helpers_test.go b/internal/views/helpers_test.go index f154dc67..50b16390 100644 --- a/internal/views/helpers_test.go +++ b/internal/views/helpers_test.go @@ -11,18 +11,30 @@ func TestDeltas(t *testing.T) { uu := []struct { s1, s2, e string }{ - {"fred", "fred", ""}, - {"fred", "blee", delta()}, - {"1", "2", plus()}, - {"2", "1", minus()}, - {"2m33s", "1m", minus()}, - {"10Gi", "20Gi", plus()}, - {"15%(-)", "15%", delta()}, + {"", "", ""}, {resource.MissingValue, "", delta()}, {resource.NAValue, "", delta()}, + {"fred", "fred", ""}, + {"fred", "blee", delta()}, + {"1", "1", ""}, + {"1", "2", plus()}, + {"2", "1", minus()}, + {"2m33s", "2m33s", ""}, + {"2m33s", "1m", minus()}, + {"33s", "1m", plus()}, + {"10Gi", "10Gi", ""}, + {"10Gi", "20Gi", plus()}, + {"30Gi", "20Gi", minus()}, + {"15%", "15%", ""}, + {"20%", "40%", plus()}, + {"5%", "2%", minus()}, } for _, u := range uu { assert.Equal(t, u.e, deltas(u.s1, u.s2)) } } + +func TestToPerc(t *testing.T) { + assert.Equal(t, "50%", toPerc(50)) +} diff --git a/internal/views/menu.go b/internal/views/menu.go index beeb76b8..36aa84a1 100644 --- a/internal/views/menu.go +++ b/internal/views/menu.go @@ -13,6 +13,11 @@ import ( "github.com/rs/zerolog/log" ) +func init() { + initKeys() + initStyles() +} + const ( menuSepFmt = " [dodgerblue::b]%-%ds [white::d]%s " menuIndexFmt = " [fuchsia::b]<%d> [white::d]%s " diff --git a/internal/views/mock_clustermeta.go b/internal/views/mock_clustermeta.go new file mode 100644 index 00000000..15365469 --- /dev/null +++ b/internal/views/mock_clustermeta.go @@ -0,0 +1,781 @@ +// Code generated by pegomock. DO NOT EDIT. +// Source: github.com/derailed/k9s/internal/resource (interfaces: ClusterMeta) + +package views + +import ( + k8s "github.com/derailed/k9s/internal/k8s" + pegomock "github.com/petergtz/pegomock" + v1 "k8s.io/api/core/v1" + version "k8s.io/apimachinery/pkg/version" + dynamic "k8s.io/client-go/dynamic" + kubernetes "k8s.io/client-go/kubernetes" + rest "k8s.io/client-go/rest" + versioned "k8s.io/metrics/pkg/client/clientset/versioned" + "reflect" + "time" +) + +type MockClusterMeta struct { + fail func(message string, callerSkip ...int) +} + +func NewMockClusterMeta() *MockClusterMeta { + return &MockClusterMeta{fail: pegomock.GlobalFailHandler} +} + +func (mock *MockClusterMeta) ClusterName() string { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("ClusterName", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem()}) + var ret0 string + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(string) + } + } + return ret0 +} + +func (mock *MockClusterMeta) Config() *k8s.Config { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("Config", params, []reflect.Type{reflect.TypeOf((**k8s.Config)(nil)).Elem()}) + var ret0 *k8s.Config + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*k8s.Config) + } + } + return ret0 +} + +func (mock *MockClusterMeta) ContextName() string { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("ContextName", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem()}) + var ret0 string + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(string) + } + } + return ret0 +} + +func (mock *MockClusterMeta) DialOrDie() kubernetes.Interface { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("DialOrDie", params, []reflect.Type{reflect.TypeOf((*kubernetes.Interface)(nil)).Elem()}) + var ret0 kubernetes.Interface + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(kubernetes.Interface) + } + } + return ret0 +} + +func (mock *MockClusterMeta) DynDialOrDie() dynamic.Interface { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("DynDialOrDie", params, []reflect.Type{reflect.TypeOf((*dynamic.Interface)(nil)).Elem()}) + var ret0 dynamic.Interface + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(dynamic.Interface) + } + } + return ret0 +} + +func (mock *MockClusterMeta) FetchNodes() (*v1.NodeList, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodes", params, []reflect.Type{reflect.TypeOf((**v1.NodeList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *v1.NodeList + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*v1.NodeList) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockClusterMeta) GetNodes() ([]v1.Node, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("GetNodes", params, []reflect.Type{reflect.TypeOf((*[]v1.Node)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1.Node + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1.Node) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockClusterMeta) HasMetrics() bool { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("HasMetrics", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) + var ret0 bool + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(bool) + } + } + return ret0 +} + +func (mock *MockClusterMeta) IsNamespaced(_param0 string) bool { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("IsNamespaced", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) + var ret0 bool + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(bool) + } + } + return ret0 +} + +func (mock *MockClusterMeta) MXDial() (*versioned.Clientset, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("MXDial", params, []reflect.Type{reflect.TypeOf((**versioned.Clientset)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *versioned.Clientset + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*versioned.Clientset) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockClusterMeta) NSDialOrDie() dynamic.NamespaceableResourceInterface { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("NSDialOrDie", params, []reflect.Type{reflect.TypeOf((*dynamic.NamespaceableResourceInterface)(nil)).Elem()}) + var ret0 dynamic.NamespaceableResourceInterface + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(dynamic.NamespaceableResourceInterface) + } + } + return ret0 +} + +func (mock *MockClusterMeta) RestConfigOrDie() *rest.Config { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("RestConfigOrDie", params, []reflect.Type{reflect.TypeOf((**rest.Config)(nil)).Elem()}) + var ret0 *rest.Config + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*rest.Config) + } + } + return ret0 +} + +func (mock *MockClusterMeta) ServerVersion() (*version.Info, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("ServerVersion", params, []reflect.Type{reflect.TypeOf((**version.Info)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *version.Info + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*version.Info) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockClusterMeta) SupportsRes(_param0 string, _param1 []string) (string, bool) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{_param0, _param1} + result := pegomock.GetGenericMockFrom(mock).Invoke("SupportsRes", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*bool)(nil)).Elem()}) + var ret0 string + var ret1 bool + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(string) + } + if result[1] != nil { + ret1 = result[1].(bool) + } + } + return ret0, ret1 +} + +func (mock *MockClusterMeta) SupportsResource(_param0 string) bool { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("SupportsResource", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) + var ret0 bool + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(bool) + } + } + return ret0 +} + +func (mock *MockClusterMeta) SwitchContextOrDie(_param0 string) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{_param0} + pegomock.GetGenericMockFrom(mock).Invoke("SwitchContextOrDie", params, []reflect.Type{}) +} + +func (mock *MockClusterMeta) UserName() string { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("UserName", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem()}) + var ret0 string + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(string) + } + } + return ret0 +} + +func (mock *MockClusterMeta) ValidNamespaces() ([]v1.Namespace, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("ValidNamespaces", params, []reflect.Type{reflect.TypeOf((*[]v1.Namespace)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1.Namespace + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1.Namespace) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockClusterMeta) ValidPods(_param0 string) ([]v1.Pod, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("ValidPods", params, []reflect.Type{reflect.TypeOf((*[]v1.Pod)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1.Pod + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1.Pod) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockClusterMeta) Version() (string, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("Version", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 string + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(string) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockClusterMeta) VerifyWasCalledOnce() *VerifierClusterMeta { + return &VerifierClusterMeta{ + mock: mock, + invocationCountMatcher: pegomock.Times(1), + } +} + +func (mock *MockClusterMeta) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierClusterMeta { + return &VerifierClusterMeta{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + } +} + +func (mock *MockClusterMeta) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierClusterMeta { + return &VerifierClusterMeta{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + inOrderContext: inOrderContext, + } +} + +func (mock *MockClusterMeta) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierClusterMeta { + return &VerifierClusterMeta{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + timeout: timeout, + } +} + +type VerifierClusterMeta struct { + mock *MockClusterMeta + invocationCountMatcher pegomock.Matcher + inOrderContext *pegomock.InOrderContext + timeout time.Duration +} + +func (verifier *VerifierClusterMeta) ClusterName() *ClusterMeta_ClusterName_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ClusterName", params, verifier.timeout) + return &ClusterMeta_ClusterName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_ClusterName_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_ClusterName_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_ClusterName_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) Config() *ClusterMeta_Config_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Config", params, verifier.timeout) + return &ClusterMeta_Config_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_Config_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_Config_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_Config_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) ContextName() *ClusterMeta_ContextName_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ContextName", params, verifier.timeout) + return &ClusterMeta_ContextName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_ContextName_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_ContextName_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_ContextName_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) DialOrDie() *ClusterMeta_DialOrDie_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "DialOrDie", params, verifier.timeout) + return &ClusterMeta_DialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_DialOrDie_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_DialOrDie_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_DialOrDie_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) DynDialOrDie() *ClusterMeta_DynDialOrDie_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "DynDialOrDie", params, verifier.timeout) + return &ClusterMeta_DynDialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_DynDialOrDie_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_DynDialOrDie_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_DynDialOrDie_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) FetchNodes() *ClusterMeta_FetchNodes_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchNodes", params, verifier.timeout) + return &ClusterMeta_FetchNodes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_FetchNodes_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_FetchNodes_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_FetchNodes_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) GetNodes() *ClusterMeta_GetNodes_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetNodes", params, verifier.timeout) + return &ClusterMeta_GetNodes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_GetNodes_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_GetNodes_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_GetNodes_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) HasMetrics() *ClusterMeta_HasMetrics_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) + return &ClusterMeta_HasMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_HasMetrics_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_HasMetrics_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_HasMetrics_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) IsNamespaced(_param0 string) *ClusterMeta_IsNamespaced_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "IsNamespaced", params, verifier.timeout) + return &ClusterMeta_IsNamespaced_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_IsNamespaced_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_IsNamespaced_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *ClusterMeta_IsNamespaced_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} + +func (verifier *VerifierClusterMeta) MXDial() *ClusterMeta_MXDial_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MXDial", params, verifier.timeout) + return &ClusterMeta_MXDial_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_MXDial_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_MXDial_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_MXDial_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) NSDialOrDie() *ClusterMeta_NSDialOrDie_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "NSDialOrDie", params, verifier.timeout) + return &ClusterMeta_NSDialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_NSDialOrDie_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_NSDialOrDie_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_NSDialOrDie_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) RestConfigOrDie() *ClusterMeta_RestConfigOrDie_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "RestConfigOrDie", params, verifier.timeout) + return &ClusterMeta_RestConfigOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_RestConfigOrDie_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_RestConfigOrDie_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_RestConfigOrDie_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) ServerVersion() *ClusterMeta_ServerVersion_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ServerVersion", params, verifier.timeout) + return &ClusterMeta_ServerVersion_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_ServerVersion_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_ServerVersion_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_ServerVersion_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) SupportsRes(_param0 string, _param1 []string) *ClusterMeta_SupportsRes_OngoingVerification { + params := []pegomock.Param{_param0, _param1} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsRes", params, verifier.timeout) + return &ClusterMeta_SupportsRes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_SupportsRes_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_SupportsRes_OngoingVerification) GetCapturedArguments() (string, []string) { + _param0, _param1 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1], _param1[len(_param1)-1] +} + +func (c *ClusterMeta_SupportsRes_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 [][]string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + _param1 = make([][]string, len(params[1])) + for u, param := range params[1] { + _param1[u] = param.([]string) + } + } + return +} + +func (verifier *VerifierClusterMeta) SupportsResource(_param0 string) *ClusterMeta_SupportsResource_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsResource", params, verifier.timeout) + return &ClusterMeta_SupportsResource_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_SupportsResource_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_SupportsResource_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *ClusterMeta_SupportsResource_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} + +func (verifier *VerifierClusterMeta) SwitchContextOrDie(_param0 string) *ClusterMeta_SwitchContextOrDie_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SwitchContextOrDie", params, verifier.timeout) + return &ClusterMeta_SwitchContextOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_SwitchContextOrDie_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_SwitchContextOrDie_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *ClusterMeta_SwitchContextOrDie_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} + +func (verifier *VerifierClusterMeta) UserName() *ClusterMeta_UserName_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UserName", params, verifier.timeout) + return &ClusterMeta_UserName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_UserName_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_UserName_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_UserName_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) ValidNamespaces() *ClusterMeta_ValidNamespaces_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidNamespaces", params, verifier.timeout) + return &ClusterMeta_ValidNamespaces_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_ValidNamespaces_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_ValidNamespaces_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_ValidNamespaces_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) ValidPods(_param0 string) *ClusterMeta_ValidPods_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidPods", params, verifier.timeout) + return &ClusterMeta_ValidPods_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_ValidPods_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_ValidPods_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *ClusterMeta_ValidPods_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} + +func (verifier *VerifierClusterMeta) Version() *ClusterMeta_Version_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Version", params, verifier.timeout) + return &ClusterMeta_Version_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_Version_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_Version_OngoingVerification) GetCapturedArguments() { +} + +func (c *ClusterMeta_Version_OngoingVerification) GetAllCapturedArguments() { +} diff --git a/internal/views/mock_connection.go b/internal/views/mock_connection.go new file mode 100644 index 00000000..b593e6dc --- /dev/null +++ b/internal/views/mock_connection.go @@ -0,0 +1,613 @@ +// Code generated by pegomock. DO NOT EDIT. +// Source: github.com/derailed/k9s/internal/k8s (interfaces: Connection) + +package views + +import ( + k8s "github.com/derailed/k9s/internal/k8s" + pegomock "github.com/petergtz/pegomock" + v1 "k8s.io/api/core/v1" + version "k8s.io/apimachinery/pkg/version" + dynamic "k8s.io/client-go/dynamic" + kubernetes "k8s.io/client-go/kubernetes" + rest "k8s.io/client-go/rest" + versioned "k8s.io/metrics/pkg/client/clientset/versioned" + "reflect" + "time" +) + +type MockConnection struct { + fail func(message string, callerSkip ...int) +} + +func NewMockConnection() *MockConnection { + return &MockConnection{fail: pegomock.GlobalFailHandler} +} + +func (mock *MockConnection) Config() *k8s.Config { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("Config", params, []reflect.Type{reflect.TypeOf((**k8s.Config)(nil)).Elem()}) + var ret0 *k8s.Config + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*k8s.Config) + } + } + return ret0 +} + +func (mock *MockConnection) DialOrDie() kubernetes.Interface { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("DialOrDie", params, []reflect.Type{reflect.TypeOf((*kubernetes.Interface)(nil)).Elem()}) + var ret0 kubernetes.Interface + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(kubernetes.Interface) + } + } + return ret0 +} + +func (mock *MockConnection) DynDialOrDie() dynamic.Interface { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("DynDialOrDie", params, []reflect.Type{reflect.TypeOf((*dynamic.Interface)(nil)).Elem()}) + var ret0 dynamic.Interface + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(dynamic.Interface) + } + } + return ret0 +} + +func (mock *MockConnection) FetchNodes() (*v1.NodeList, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodes", params, []reflect.Type{reflect.TypeOf((**v1.NodeList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *v1.NodeList + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*v1.NodeList) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockConnection) HasMetrics() bool { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("HasMetrics", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) + var ret0 bool + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(bool) + } + } + return ret0 +} + +func (mock *MockConnection) IsNamespaced(_param0 string) bool { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("IsNamespaced", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) + var ret0 bool + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(bool) + } + } + return ret0 +} + +func (mock *MockConnection) MXDial() (*versioned.Clientset, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("MXDial", params, []reflect.Type{reflect.TypeOf((**versioned.Clientset)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *versioned.Clientset + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*versioned.Clientset) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockConnection) NSDialOrDie() dynamic.NamespaceableResourceInterface { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("NSDialOrDie", params, []reflect.Type{reflect.TypeOf((*dynamic.NamespaceableResourceInterface)(nil)).Elem()}) + var ret0 dynamic.NamespaceableResourceInterface + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(dynamic.NamespaceableResourceInterface) + } + } + return ret0 +} + +func (mock *MockConnection) RestConfigOrDie() *rest.Config { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("RestConfigOrDie", params, []reflect.Type{reflect.TypeOf((**rest.Config)(nil)).Elem()}) + var ret0 *rest.Config + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*rest.Config) + } + } + return ret0 +} + +func (mock *MockConnection) ServerVersion() (*version.Info, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("ServerVersion", params, []reflect.Type{reflect.TypeOf((**version.Info)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *version.Info + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(*version.Info) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockConnection) SupportsRes(_param0 string, _param1 []string) (string, bool) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{_param0, _param1} + result := pegomock.GetGenericMockFrom(mock).Invoke("SupportsRes", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*bool)(nil)).Elem()}) + var ret0 string + var ret1 bool + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(string) + } + if result[1] != nil { + ret1 = result[1].(bool) + } + } + return ret0, ret1 +} + +func (mock *MockConnection) SupportsResource(_param0 string) bool { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("SupportsResource", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) + var ret0 bool + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(bool) + } + } + return ret0 +} + +func (mock *MockConnection) SwitchContextOrDie(_param0 string) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{_param0} + pegomock.GetGenericMockFrom(mock).Invoke("SwitchContextOrDie", params, []reflect.Type{}) +} + +func (mock *MockConnection) ValidNamespaces() ([]v1.Namespace, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("ValidNamespaces", params, []reflect.Type{reflect.TypeOf((*[]v1.Namespace)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1.Namespace + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1.Namespace) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockConnection) ValidPods(_param0 string) ([]v1.Pod, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("ValidPods", params, []reflect.Type{reflect.TypeOf((*[]v1.Pod)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1.Pod + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1.Pod) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockConnection) VerifyWasCalledOnce() *VerifierConnection { + return &VerifierConnection{ + mock: mock, + invocationCountMatcher: pegomock.Times(1), + } +} + +func (mock *MockConnection) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierConnection { + return &VerifierConnection{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + } +} + +func (mock *MockConnection) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierConnection { + return &VerifierConnection{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + inOrderContext: inOrderContext, + } +} + +func (mock *MockConnection) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierConnection { + return &VerifierConnection{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + timeout: timeout, + } +} + +type VerifierConnection struct { + mock *MockConnection + invocationCountMatcher pegomock.Matcher + inOrderContext *pegomock.InOrderContext + timeout time.Duration +} + +func (verifier *VerifierConnection) Config() *Connection_Config_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Config", params, verifier.timeout) + return &Connection_Config_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_Config_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_Config_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_Config_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) DialOrDie() *Connection_DialOrDie_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "DialOrDie", params, verifier.timeout) + return &Connection_DialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_DialOrDie_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_DialOrDie_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_DialOrDie_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) DynDialOrDie() *Connection_DynDialOrDie_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "DynDialOrDie", params, verifier.timeout) + return &Connection_DynDialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_DynDialOrDie_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_DynDialOrDie_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_DynDialOrDie_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) FetchNodes() *Connection_FetchNodes_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchNodes", params, verifier.timeout) + return &Connection_FetchNodes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_FetchNodes_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_FetchNodes_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_FetchNodes_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) HasMetrics() *Connection_HasMetrics_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) + return &Connection_HasMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_HasMetrics_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_HasMetrics_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_HasMetrics_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) IsNamespaced(_param0 string) *Connection_IsNamespaced_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "IsNamespaced", params, verifier.timeout) + return &Connection_IsNamespaced_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_IsNamespaced_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_IsNamespaced_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *Connection_IsNamespaced_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} + +func (verifier *VerifierConnection) MXDial() *Connection_MXDial_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MXDial", params, verifier.timeout) + return &Connection_MXDial_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_MXDial_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_MXDial_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_MXDial_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) NSDialOrDie() *Connection_NSDialOrDie_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "NSDialOrDie", params, verifier.timeout) + return &Connection_NSDialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_NSDialOrDie_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_NSDialOrDie_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_NSDialOrDie_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) RestConfigOrDie() *Connection_RestConfigOrDie_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "RestConfigOrDie", params, verifier.timeout) + return &Connection_RestConfigOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_RestConfigOrDie_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_RestConfigOrDie_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_RestConfigOrDie_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) ServerVersion() *Connection_ServerVersion_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ServerVersion", params, verifier.timeout) + return &Connection_ServerVersion_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_ServerVersion_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_ServerVersion_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_ServerVersion_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) SupportsRes(_param0 string, _param1 []string) *Connection_SupportsRes_OngoingVerification { + params := []pegomock.Param{_param0, _param1} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsRes", params, verifier.timeout) + return &Connection_SupportsRes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_SupportsRes_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_SupportsRes_OngoingVerification) GetCapturedArguments() (string, []string) { + _param0, _param1 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1], _param1[len(_param1)-1] +} + +func (c *Connection_SupportsRes_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 [][]string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + _param1 = make([][]string, len(params[1])) + for u, param := range params[1] { + _param1[u] = param.([]string) + } + } + return +} + +func (verifier *VerifierConnection) SupportsResource(_param0 string) *Connection_SupportsResource_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsResource", params, verifier.timeout) + return &Connection_SupportsResource_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_SupportsResource_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_SupportsResource_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *Connection_SupportsResource_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} + +func (verifier *VerifierConnection) SwitchContextOrDie(_param0 string) *Connection_SwitchContextOrDie_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SwitchContextOrDie", params, verifier.timeout) + return &Connection_SwitchContextOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_SwitchContextOrDie_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_SwitchContextOrDie_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *Connection_SwitchContextOrDie_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} + +func (verifier *VerifierConnection) ValidNamespaces() *Connection_ValidNamespaces_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidNamespaces", params, verifier.timeout) + return &Connection_ValidNamespaces_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_ValidNamespaces_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_ValidNamespaces_OngoingVerification) GetCapturedArguments() { +} + +func (c *Connection_ValidNamespaces_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) ValidPods(_param0 string) *Connection_ValidPods_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidPods", params, verifier.timeout) + return &Connection_ValidPods_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_ValidPods_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_ValidPods_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *Connection_ValidPods_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} diff --git a/internal/views/mock_kubesettings.go b/internal/views/mock_kubesettings.go new file mode 100644 index 00000000..fda68e58 --- /dev/null +++ b/internal/views/mock_kubesettings.go @@ -0,0 +1,242 @@ +// Code generated by pegomock. DO NOT EDIT. +// Source: github.com/derailed/k9s/internal/config (interfaces: KubeSettings) + +package views + +import ( + pegomock "github.com/petergtz/pegomock" + v1 "k8s.io/api/core/v1" + "reflect" + "time" +) + +type MockKubeSettings struct { + fail func(message string, callerSkip ...int) +} + +func NewMockKubeSettings() *MockKubeSettings { + return &MockKubeSettings{fail: pegomock.GlobalFailHandler} +} + +func (mock *MockKubeSettings) ClusterNames() ([]string, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockKubeSettings().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("ClusterNames", params, []reflect.Type{reflect.TypeOf((*[]string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []string + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]string) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockKubeSettings) CurrentClusterName() (string, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockKubeSettings().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("CurrentClusterName", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 string + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(string) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockKubeSettings) CurrentContextName() (string, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockKubeSettings().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("CurrentContextName", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 string + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(string) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockKubeSettings) CurrentNamespaceName() (string, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockKubeSettings().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("CurrentNamespaceName", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 string + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(string) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockKubeSettings) NamespaceNames(_param0 []v1.Namespace) []string { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockKubeSettings().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("NamespaceNames", params, []reflect.Type{reflect.TypeOf((*[]string)(nil)).Elem()}) + var ret0 []string + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]string) + } + } + return ret0 +} + +func (mock *MockKubeSettings) VerifyWasCalledOnce() *VerifierKubeSettings { + return &VerifierKubeSettings{ + mock: mock, + invocationCountMatcher: pegomock.Times(1), + } +} + +func (mock *MockKubeSettings) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierKubeSettings { + return &VerifierKubeSettings{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + } +} + +func (mock *MockKubeSettings) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierKubeSettings { + return &VerifierKubeSettings{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + inOrderContext: inOrderContext, + } +} + +func (mock *MockKubeSettings) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierKubeSettings { + return &VerifierKubeSettings{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + timeout: timeout, + } +} + +type VerifierKubeSettings struct { + mock *MockKubeSettings + invocationCountMatcher pegomock.Matcher + inOrderContext *pegomock.InOrderContext + timeout time.Duration +} + +func (verifier *VerifierKubeSettings) ClusterNames() *KubeSettings_ClusterNames_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ClusterNames", params, verifier.timeout) + return &KubeSettings_ClusterNames_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type KubeSettings_ClusterNames_OngoingVerification struct { + mock *MockKubeSettings + methodInvocations []pegomock.MethodInvocation +} + +func (c *KubeSettings_ClusterNames_OngoingVerification) GetCapturedArguments() { +} + +func (c *KubeSettings_ClusterNames_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierKubeSettings) CurrentClusterName() *KubeSettings_CurrentClusterName_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CurrentClusterName", params, verifier.timeout) + return &KubeSettings_CurrentClusterName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type KubeSettings_CurrentClusterName_OngoingVerification struct { + mock *MockKubeSettings + methodInvocations []pegomock.MethodInvocation +} + +func (c *KubeSettings_CurrentClusterName_OngoingVerification) GetCapturedArguments() { +} + +func (c *KubeSettings_CurrentClusterName_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierKubeSettings) CurrentContextName() *KubeSettings_CurrentContextName_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CurrentContextName", params, verifier.timeout) + return &KubeSettings_CurrentContextName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type KubeSettings_CurrentContextName_OngoingVerification struct { + mock *MockKubeSettings + methodInvocations []pegomock.MethodInvocation +} + +func (c *KubeSettings_CurrentContextName_OngoingVerification) GetCapturedArguments() { +} + +func (c *KubeSettings_CurrentContextName_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierKubeSettings) CurrentNamespaceName() *KubeSettings_CurrentNamespaceName_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CurrentNamespaceName", params, verifier.timeout) + return &KubeSettings_CurrentNamespaceName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type KubeSettings_CurrentNamespaceName_OngoingVerification struct { + mock *MockKubeSettings + methodInvocations []pegomock.MethodInvocation +} + +func (c *KubeSettings_CurrentNamespaceName_OngoingVerification) GetCapturedArguments() { +} + +func (c *KubeSettings_CurrentNamespaceName_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierKubeSettings) NamespaceNames(_param0 []v1.Namespace) *KubeSettings_NamespaceNames_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "NamespaceNames", params, verifier.timeout) + return &KubeSettings_NamespaceNames_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type KubeSettings_NamespaceNames_OngoingVerification struct { + mock *MockKubeSettings + methodInvocations []pegomock.MethodInvocation +} + +func (c *KubeSettings_NamespaceNames_OngoingVerification) GetCapturedArguments() []v1.Namespace { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *KubeSettings_NamespaceNames_OngoingVerification) GetAllCapturedArguments() (_param0 [][]v1.Namespace) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([][]v1.Namespace, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.([]v1.Namespace) + } + } + return +} diff --git a/internal/views/mock_metricsserver.go b/internal/views/mock_metricsserver.go new file mode 100644 index 00000000..0fe4833c --- /dev/null +++ b/internal/views/mock_metricsserver.go @@ -0,0 +1,300 @@ +// Code generated by pegomock. DO NOT EDIT. +// Source: github.com/derailed/k9s/internal/resource (interfaces: MetricsServer) + +package views + +import ( + k8s "github.com/derailed/k9s/internal/k8s" + pegomock "github.com/petergtz/pegomock" + v1 "k8s.io/api/core/v1" + v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" + "reflect" + "time" +) + +type MockMetricsServer struct { + fail func(message string, callerSkip ...int) +} + +func NewMockMetricsServer() *MockMetricsServer { + return &MockMetricsServer{fail: pegomock.GlobalFailHandler} +} + +func (mock *MockMetricsServer) ClusterLoad(_param0 []v1.Node, _param1 []v1beta1.NodeMetrics) k8s.ClusterMetrics { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockMetricsServer().") + } + params := []pegomock.Param{_param0, _param1} + result := pegomock.GetGenericMockFrom(mock).Invoke("ClusterLoad", params, []reflect.Type{reflect.TypeOf((*k8s.ClusterMetrics)(nil)).Elem()}) + var ret0 k8s.ClusterMetrics + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(k8s.ClusterMetrics) + } + } + return ret0 +} + +func (mock *MockMetricsServer) FetchNodesMetrics() ([]v1beta1.NodeMetrics, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockMetricsServer().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodesMetrics", params, []reflect.Type{reflect.TypeOf((*[]v1beta1.NodeMetrics)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1beta1.NodeMetrics + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1beta1.NodeMetrics) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockMetricsServer) FetchPodsMetrics(_param0 string) ([]v1beta1.PodMetrics, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockMetricsServer().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("FetchPodsMetrics", params, []reflect.Type{reflect.TypeOf((*[]v1beta1.PodMetrics)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1beta1.PodMetrics + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1beta1.PodMetrics) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockMetricsServer) HasMetrics() bool { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockMetricsServer().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("HasMetrics", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) + var ret0 bool + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(bool) + } + } + return ret0 +} + +func (mock *MockMetricsServer) NodesMetrics(_param0 []v1.Node, _param1 []v1beta1.NodeMetrics, _param2 k8s.NodesMetrics) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockMetricsServer().") + } + params := []pegomock.Param{_param0, _param1, _param2} + pegomock.GetGenericMockFrom(mock).Invoke("NodesMetrics", params, []reflect.Type{}) +} + +func (mock *MockMetricsServer) PodsMetrics(_param0 []v1beta1.PodMetrics, _param1 k8s.PodsMetrics) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockMetricsServer().") + } + params := []pegomock.Param{_param0, _param1} + pegomock.GetGenericMockFrom(mock).Invoke("PodsMetrics", params, []reflect.Type{}) +} + +func (mock *MockMetricsServer) VerifyWasCalledOnce() *VerifierMetricsServer { + return &VerifierMetricsServer{ + mock: mock, + invocationCountMatcher: pegomock.Times(1), + } +} + +func (mock *MockMetricsServer) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierMetricsServer { + return &VerifierMetricsServer{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + } +} + +func (mock *MockMetricsServer) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierMetricsServer { + return &VerifierMetricsServer{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + inOrderContext: inOrderContext, + } +} + +func (mock *MockMetricsServer) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierMetricsServer { + return &VerifierMetricsServer{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + timeout: timeout, + } +} + +type VerifierMetricsServer struct { + mock *MockMetricsServer + invocationCountMatcher pegomock.Matcher + inOrderContext *pegomock.InOrderContext + timeout time.Duration +} + +func (verifier *VerifierMetricsServer) ClusterLoad(_param0 []v1.Node, _param1 []v1beta1.NodeMetrics) *MetricsServer_ClusterLoad_OngoingVerification { + params := []pegomock.Param{_param0, _param1} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ClusterLoad", params, verifier.timeout) + return &MetricsServer_ClusterLoad_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type MetricsServer_ClusterLoad_OngoingVerification struct { + mock *MockMetricsServer + methodInvocations []pegomock.MethodInvocation +} + +func (c *MetricsServer_ClusterLoad_OngoingVerification) GetCapturedArguments() ([]v1.Node, []v1beta1.NodeMetrics) { + _param0, _param1 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1], _param1[len(_param1)-1] +} + +func (c *MetricsServer_ClusterLoad_OngoingVerification) GetAllCapturedArguments() (_param0 [][]v1.Node, _param1 [][]v1beta1.NodeMetrics) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([][]v1.Node, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.([]v1.Node) + } + _param1 = make([][]v1beta1.NodeMetrics, len(params[1])) + for u, param := range params[1] { + _param1[u] = param.([]v1beta1.NodeMetrics) + } + } + return +} + +func (verifier *VerifierMetricsServer) FetchNodesMetrics() *MetricsServer_FetchNodesMetrics_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchNodesMetrics", params, verifier.timeout) + return &MetricsServer_FetchNodesMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type MetricsServer_FetchNodesMetrics_OngoingVerification struct { + mock *MockMetricsServer + methodInvocations []pegomock.MethodInvocation +} + +func (c *MetricsServer_FetchNodesMetrics_OngoingVerification) GetCapturedArguments() { +} + +func (c *MetricsServer_FetchNodesMetrics_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierMetricsServer) FetchPodsMetrics(_param0 string) *MetricsServer_FetchPodsMetrics_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchPodsMetrics", params, verifier.timeout) + return &MetricsServer_FetchPodsMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type MetricsServer_FetchPodsMetrics_OngoingVerification struct { + mock *MockMetricsServer + methodInvocations []pegomock.MethodInvocation +} + +func (c *MetricsServer_FetchPodsMetrics_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *MetricsServer_FetchPodsMetrics_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} + +func (verifier *VerifierMetricsServer) HasMetrics() *MetricsServer_HasMetrics_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) + return &MetricsServer_HasMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type MetricsServer_HasMetrics_OngoingVerification struct { + mock *MockMetricsServer + methodInvocations []pegomock.MethodInvocation +} + +func (c *MetricsServer_HasMetrics_OngoingVerification) GetCapturedArguments() { +} + +func (c *MetricsServer_HasMetrics_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierMetricsServer) NodesMetrics(_param0 []v1.Node, _param1 []v1beta1.NodeMetrics, _param2 k8s.NodesMetrics) *MetricsServer_NodesMetrics_OngoingVerification { + params := []pegomock.Param{_param0, _param1, _param2} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "NodesMetrics", params, verifier.timeout) + return &MetricsServer_NodesMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type MetricsServer_NodesMetrics_OngoingVerification struct { + mock *MockMetricsServer + methodInvocations []pegomock.MethodInvocation +} + +func (c *MetricsServer_NodesMetrics_OngoingVerification) GetCapturedArguments() ([]v1.Node, []v1beta1.NodeMetrics, k8s.NodesMetrics) { + _param0, _param1, _param2 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1] +} + +func (c *MetricsServer_NodesMetrics_OngoingVerification) GetAllCapturedArguments() (_param0 [][]v1.Node, _param1 [][]v1beta1.NodeMetrics, _param2 []k8s.NodesMetrics) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([][]v1.Node, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.([]v1.Node) + } + _param1 = make([][]v1beta1.NodeMetrics, len(params[1])) + for u, param := range params[1] { + _param1[u] = param.([]v1beta1.NodeMetrics) + } + _param2 = make([]k8s.NodesMetrics, len(params[2])) + for u, param := range params[2] { + _param2[u] = param.(k8s.NodesMetrics) + } + } + return +} + +func (verifier *VerifierMetricsServer) PodsMetrics(_param0 []v1beta1.PodMetrics, _param1 k8s.PodsMetrics) *MetricsServer_PodsMetrics_OngoingVerification { + params := []pegomock.Param{_param0, _param1} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PodsMetrics", params, verifier.timeout) + return &MetricsServer_PodsMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type MetricsServer_PodsMetrics_OngoingVerification struct { + mock *MockMetricsServer + methodInvocations []pegomock.MethodInvocation +} + +func (c *MetricsServer_PodsMetrics_OngoingVerification) GetCapturedArguments() ([]v1beta1.PodMetrics, k8s.PodsMetrics) { + _param0, _param1 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1], _param1[len(_param1)-1] +} + +func (c *MetricsServer_PodsMetrics_OngoingVerification) GetAllCapturedArguments() (_param0 [][]v1beta1.PodMetrics, _param1 []k8s.PodsMetrics) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([][]v1beta1.PodMetrics, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.([]v1beta1.PodMetrics) + } + _param1 = make([]k8s.PodsMetrics, len(params[1])) + for u, param := range params[1] { + _param1[u] = param.(k8s.PodsMetrics) + } + } + return +} diff --git a/internal/views/mock_metricsservice.go b/internal/views/mock_metricsservice.go new file mode 100644 index 00000000..766a99a5 --- /dev/null +++ b/internal/views/mock_metricsservice.go @@ -0,0 +1,170 @@ +// Code generated by pegomock. DO NOT EDIT. +// Source: github.com/derailed/k9s/internal/resource (interfaces: MetricsService) + +package views + +import ( + pegomock "github.com/petergtz/pegomock" + v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" + "reflect" + "time" +) + +type MockMetricsService struct { + fail func(message string, callerSkip ...int) +} + +func NewMockMetricsService() *MockMetricsService { + return &MockMetricsService{fail: pegomock.GlobalFailHandler} +} + +func (mock *MockMetricsService) FetchNodesMetrics() ([]v1beta1.NodeMetrics, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockMetricsService().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodesMetrics", params, []reflect.Type{reflect.TypeOf((*[]v1beta1.NodeMetrics)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1beta1.NodeMetrics + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1beta1.NodeMetrics) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockMetricsService) FetchPodsMetrics(_param0 string) ([]v1beta1.PodMetrics, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockMetricsService().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("FetchPodsMetrics", params, []reflect.Type{reflect.TypeOf((*[]v1beta1.PodMetrics)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1beta1.PodMetrics + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1beta1.PodMetrics) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + +func (mock *MockMetricsService) HasMetrics() bool { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockMetricsService().") + } + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("HasMetrics", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) + var ret0 bool + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].(bool) + } + } + return ret0 +} + +func (mock *MockMetricsService) VerifyWasCalledOnce() *VerifierMetricsService { + return &VerifierMetricsService{ + mock: mock, + invocationCountMatcher: pegomock.Times(1), + } +} + +func (mock *MockMetricsService) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierMetricsService { + return &VerifierMetricsService{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + } +} + +func (mock *MockMetricsService) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierMetricsService { + return &VerifierMetricsService{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + inOrderContext: inOrderContext, + } +} + +func (mock *MockMetricsService) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierMetricsService { + return &VerifierMetricsService{ + mock: mock, + invocationCountMatcher: invocationCountMatcher, + timeout: timeout, + } +} + +type VerifierMetricsService struct { + mock *MockMetricsService + invocationCountMatcher pegomock.Matcher + inOrderContext *pegomock.InOrderContext + timeout time.Duration +} + +func (verifier *VerifierMetricsService) FetchNodesMetrics() *MetricsService_FetchNodesMetrics_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchNodesMetrics", params, verifier.timeout) + return &MetricsService_FetchNodesMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type MetricsService_FetchNodesMetrics_OngoingVerification struct { + mock *MockMetricsService + methodInvocations []pegomock.MethodInvocation +} + +func (c *MetricsService_FetchNodesMetrics_OngoingVerification) GetCapturedArguments() { +} + +func (c *MetricsService_FetchNodesMetrics_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierMetricsService) FetchPodsMetrics(_param0 string) *MetricsService_FetchPodsMetrics_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchPodsMetrics", params, verifier.timeout) + return &MetricsService_FetchPodsMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type MetricsService_FetchPodsMetrics_OngoingVerification struct { + mock *MockMetricsService + methodInvocations []pegomock.MethodInvocation +} + +func (c *MetricsService_FetchPodsMetrics_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *MetricsService_FetchPodsMetrics_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} + +func (verifier *VerifierMetricsService) HasMetrics() *MetricsService_HasMetrics_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) + return &MetricsService_HasMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type MetricsService_HasMetrics_OngoingVerification struct { + mock *MockMetricsService + methodInvocations []pegomock.MethodInvocation +} + +func (c *MetricsService_HasMetrics_OngoingVerification) GetCapturedArguments() { +} + +func (c *MetricsService_HasMetrics_OngoingVerification) GetAllCapturedArguments() { +} diff --git a/internal/views/popeye.go b/internal/views/popeye.go deleted file mode 100644 index 86c02f4d..00000000 --- a/internal/views/popeye.go +++ /dev/null @@ -1,77 +0,0 @@ -package views - -// import ( -// "context" -// "fmt" -// "io" -// "os" -// "path/filepath" - -// "github.com/derailed/k9s/internal/config" -// "github.com/derailed/popeye/pkg" -// cfg "github.com/derailed/popeye/pkg/config" -// "github.com/derailed/tview" -// "github.com/gdamore/tcell" -// "github.com/rs/zerolog/log" -// ) - -// type popeyeView struct { -// *detailsView - -// current igniter -// ansiWriter io.Writer -// } - -// func newPopeyeView(app *appView) *popeyeView { -// v := popeyeView{} -// { -// v.detailsView = newDetailsView(app, v.backCmd) -// v.SetBorderPadding(0, 0, 1, 1) -// v.current = app.content.GetPrimitive("main").(igniter) -// v.SetDynamicColors(true) -// v.SetWrap(true) -// v.setTitle("Popeye") -// v.ansiWriter = tview.ANSIWriter(v) -// } -// v.actions[KeyP] = newKeyAction("Previous", v.app.prevCmd, false) - -// return &v -// } - -// func (v *popeyeView) init(ctx context.Context, ns string) { -// defer func() { -// if err := recover(); err != nil { -// v.app.flash(flashErr, fmt.Sprintf("%v", err)) -// } -// }() - -// c := cfg.New() - -// spinach := filepath.Join(config.K9sHome, "spinach.yml") - -// if _, err := os.Stat(spinach); err == nil { -// c.Spinach = spinach -// } - -// if v.app.config.K9s.CurrentContext != "" { -// v.app.flags.Context = &v.app.config.K9s.CurrentContext -// } - -// if err := c.Init(v.app.flags); err != nil { -// log.Error().Err(err).Msg("Unable to load spinach config") -// } - -// p := pkg.NewPopeye(c, &log.Logger, v.ansiWriter) -// p.Sanitize(false) -// } - -// func (v *popeyeView) getTitle() string { -// return "Popeye" -// } - -// func (v *popeyeView) backCmd(evt *tcell.EventKey) *tcell.EventKey { -// v.app.command.previousCmd() -// v.app.inject(v.current) - -// return nil -// }