@@ -2,6 +2,15 @@ package integration
22
33import (
44 "fmt"
5+ "net"
6+ "net/http"
7+ "net/url"
8+ "os"
9+ "slices"
10+ "syscall"
11+ "testing"
12+ "time"
13+
514 "github.com/anchore/k8s-inventory/internal/anchore"
615 "github.com/anchore/k8s-inventory/internal/config"
716 jstime "github.com/anchore/k8s-inventory/internal/time"
@@ -13,14 +22,6 @@ import (
1322 v1 "k8s.io/api/core/v1"
1423 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1524 "k8s.io/client-go/kubernetes/fake"
16- "net"
17- "net/http"
18- "net/url"
19- "os"
20- "slices"
21- "syscall"
22- "testing"
23- "time"
2425)
2526
2627var (
@@ -605,10 +606,11 @@ func TestGetRegistrationInfo(t *testing.T) {
605606 timestamps := []time.Time {time .Now ()}
606607
607608 type args struct {
608- config * config.Application
609- c * client.Client
610- namespace string
611- name string
609+ config * config.Application
610+ c * client.Client
611+ namespace string
612+ name string
613+ replicaCount int32
612614 }
613615 tests := []struct {
614616 name string
@@ -632,9 +634,10 @@ func TestGetRegistrationInfo(t *testing.T) {
632634 },
633635 HealthReportIntervalSeconds : 60 ,
634636 },
635- c : nil ,
636- namespace : "test-namespace" ,
637- name : "" ,
637+ c : nil ,
638+ namespace : "test-namespace" ,
639+ name : "" ,
640+ replicaCount : 1 ,
638641 },
639642 want : & Registration {
640643 RegistrationID : uuids [0 ].String (),
@@ -676,9 +679,10 @@ func TestGetRegistrationInfo(t *testing.T) {
676679 },
677680 HealthReportIntervalSeconds : 60 ,
678681 },
679- c : nil ,
680- namespace : "test-namespace" ,
681- name : "1111223344" ,
682+ c : nil ,
683+ namespace : "test-namespace" ,
684+ name : "1111223344" ,
685+ replicaCount : 0 ,
682686 },
683687 want : & Registration {
684688 RegistrationID : "test-registration-id" ,
@@ -719,8 +723,9 @@ func TestGetRegistrationInfo(t *testing.T) {
719723 c : & client.Client {
720724 Clientset : fake .NewSimpleClientset (& pod , & replicaSet , & deployment ),
721725 },
722- namespace : "test-namespace" ,
723- name : "test-pod" ,
726+ namespace : "test-namespace" ,
727+ name : "test-pod" ,
728+ replicaCount : 2 ,
724729 },
725730 want : & Registration {
726731 RegistrationID : "test-deployment-uid" ,
@@ -740,6 +745,49 @@ func TestGetRegistrationInfo(t *testing.T) {
740745 HealthReportInterval : 60 ,
741746 },
742747 },
748+ {
749+ name : "Values from k8s single replica" ,
750+ args : args {
751+ config : & config.Application {
752+ AnchoreDetails : config.AnchoreInfo {
753+ User : "admin" ,
754+ },
755+ AccountRoutes : config.AccountRoutes {
756+ "account3" : config.AccountRouteDetails {
757+ Namespaces : []string {"ns3" },
758+ },
759+ },
760+ KubeConfig : config.KubeConf {
761+ Cluster : "k8s-cluster1" ,
762+ },
763+ Registration : config.RegistrationOptions {},
764+ HealthReportIntervalSeconds : 60 ,
765+ },
766+ c : & client.Client {
767+ Clientset : fake .NewSimpleClientset (& pod , & replicaSet , & deployment ),
768+ },
769+ namespace : "test-namespace" ,
770+ name : "test-pod" ,
771+ replicaCount : 1 ,
772+ },
773+ want : & Registration {
774+ RegistrationID : "test-deployment-uid" ,
775+ RegistrationInstanceID : deployment .ObjectMeta .Name ,
776+ Type : Type ,
777+ Name : "test-deployment-k8s-inventory" ,
778+ Description : "" ,
779+ Version : "1.7.0" ,
780+ StartedAt : jstime.Datetime {Time : timestamps [0 ].UTC ()},
781+ Uptime : new (jstime.Duration ),
782+ Username : "admin" ,
783+ ExplicitlyAccountBound : []string {"account3" },
784+ Namespaces : []string {"ns3" },
785+ Configuration : nil ,
786+ ClusterName : "k8s-cluster1" ,
787+ Namespace : "test-namespace" ,
788+ HealthReportInterval : 60 ,
789+ },
790+ },
743791 }
744792 for _ , tt := range tests {
745793 t .Run (tt .name , func (t * testing.T ) {
@@ -756,7 +804,7 @@ func TestGetRegistrationInfo(t *testing.T) {
756804 return timestamp
757805 }
758806 result := getRegistrationInfo (tt .args .config , tt .args .c , tt .args .namespace ,
759- tt .args .name , NewUUIDMock , nowMock )
807+ tt .args .name , tt . args . replicaCount , NewUUIDMock , nowMock )
760808 assert .NotNil (t , result )
761809 assert .Equal (t , tt .want , result )
762810 })
0 commit comments