+ defer func() { resetHelmExecMock() }()
+ helmExec = mockedHelmExec
+ helmExecRetErr = errors.New("some helm command error")
+
+ if _, err := NewHelm().Delete(name); err == nil {
+ t.Errorf("Delete expected to fail but it didn't")
+ }
+}
+
+func TestFetchSuccessIfCmdArgHasTestSuffix(t *testing.T) {
+ if err := NewHelm().Fetch("kissa", "koira"); err != nil {
+ t.Errorf("Fetch failed: %v", err)
+ }
+}
+
+func TestGetVersionSuccess(t *testing.T) {
+ defer func() { resetHelmExecMock() }()
+ helmExec = mockedHelmExec
+ helmExecRetOut = helListOutput
+
+ if version := NewHelm().GetVersion("dummy-xapp"); version != "1.0" {
+ t.Errorf("GetVersion failed: expected 1.0, got %v", version)
+ }
+
+ expectedHelmCommand := "list --deployed --output yaml --namespace=ricxapp dummy-xapp"
+ if caughtHelmExecArgs != expectedHelmCommand {
+ t.Errorf("GetVersion failed: expected %v, got %v", expectedHelmCommand, caughtHelmExecArgs)
+ }
+}
+
+func TestGetVersionReturnsEmptyStringIfHelmListFails(t *testing.T) {
+ defer func() { resetHelmExecMock() }()
+ helmExec = mockedHelmExec
+ helmExecRetErr = errors.New("some helm command error")
+
+ if version := NewHelm().GetVersion("dummy-xapp"); version != "" {
+ t.Errorf("GetVersion expected to return empty string, got %v", version)
+ }
+}
+
+func TestGetAddressSuccess(t *testing.T) {
+ ip, port := NewHelm().GetAddress(helmStatusOutput)
+ if ip != "10.102.184.212" {
+ t.Errorf("GetAddress failed: expected 10.102.184.212, got %v", ip)
+ }
+ if port != "80/TCP" {
+ t.Errorf("GetAddress failed: expected 80/TCP, got %v", port)
+ }
+}
+
+func TestGetEndpointInfoSuccess(t *testing.T) {
+ defer func() { resetKubeExecMock() }()
+ kubeExec = mockedKubeExec
+ kubeExecRetOut = kubeServiceOutput
+
+ svc, port := NewHelm().GetEndpointInfo("dummy-xapp")
+ expectedSvc := "service-ricxapp-dummy-xapp-rmr.ricxapp"
+ if svc != expectedSvc {
+ t.Errorf("GetEndpointInfo failed: expected %v, got %v", expectedSvc, svc)
+ }
+ if port != 4560 {
+ t.Errorf("GetEndpointInfo failed: expected port 4560, got %v", port)
+ }
+ expectedKubeCommand := " get service -n ricxapp service-ricxapp-dummy-xapp-rmr -o json"
+ if caughtKubeExecArgs != expectedKubeCommand {
+ t.Errorf("GetEndpointInfo failed: expected %v, got %v", expectedKubeCommand, caughtKubeExecArgs)
+ }
+}
+
+func TestGetEndpointInfoReturnsDefaultPortIfJsonParseFails(t *testing.T) {
+ defer func() { resetKubeExecMock() }()
+ kubeExec = mockedKubeExec
+ kubeExecRetOut = "not-json-syntax"
+
+ svc, port := NewHelm().GetEndpointInfo("dummy-xapp")
+ expectedSvc := "service-ricxapp-dummy-xapp-rmr.ricxapp"
+ if svc != expectedSvc {
+ t.Errorf("GetEndpointInfo failed: expected %v, got %v", expectedSvc, svc)
+ }
+ if port != 4560 {
+ t.Errorf("GetEndpointInfo failed: expected port 4560, got %v", port)
+ }
+}
+
+func TestGetEndpointInfoReturnsDefaultPortIfKubeGetServiceFails(t *testing.T) {
+ defer func() { resetKubeExecMock() }()
+ kubeExec = mockedKubeExec
+ kubeExecRetErr = errors.New("some helm command error")
+
+ svc, port := NewHelm().GetEndpointInfo("dummy-xapp")
+ expectedSvc := "service-ricxapp-dummy-xapp-rmr.ricxapp"
+ if svc != expectedSvc {
+ t.Errorf("GetEndpointInfo failed: expected %v, got %v", expectedSvc, svc)
+ }
+ if port != 4560 {
+ t.Errorf("GetEndpointInfo failed: expected port 4560, got %v", port)
+ }
+}
+
+func TestHelmStatusAllSuccess(t *testing.T) {
+ defer func() { resetHelmExecMock() }()
+ helmExec = mockedHelmExec
+ helmExecRetOut = helListAllOutput
+
+ if _, err := NewHelm().StatusAll(); err != nil {
+ t.Errorf("StatusAll failed: %v", err)
+ }
+ // Todo: check StatusAll response content
+}
+
+func TestStatusAllReturnsErrorIfHelmListFails(t *testing.T) {
+ defer func() { resetHelmExecMock() }()
+ helmExec = mockedHelmExec
+ helmExecRetErr = errors.New("some helm command error")
+
+ if _, err := NewHelm().StatusAll(); err == nil {
+ t.Errorf("StatusAll expected to fail but it didn't")
+ }
+}
+
+func TestGetNamesSuccess(t *testing.T) {
+ names, err := NewHelm().GetNames(helListAllOutput)
+ if err != nil {
+ t.Errorf("GetNames failed: %v", err)
+ }