From fed6f8a18b32fef47758971e7a0c08992f52e767 Mon Sep 17 00:00:00 2001 From: vivekr-splunk <94569031+vivekr-splunk@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:47:52 -0700 Subject: [PATCH] changed ioutils to os Signed-off-by: vivekr-splunk <94569031+vivekr-splunk@users.noreply.github.com> --- .../license-manager/fixture/license_fixture.go | 18 +++++++++--------- .../implementation/license_test.go | 4 ++-- pkg/gateway/splunk/services/fixture/fixture.go | 15 ++++++++------- .../services/implementation/splunk_test.go | 11 ++++++----- .../splunk/implementation/license_test.go | 2 +- .../splunk/implementation/splunk.go | 2 -- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pkg/gateway/splunk/license-manager/fixture/license_fixture.go b/pkg/gateway/splunk/license-manager/fixture/license_fixture.go index d2ff5bd3b..a1b9a2940 100644 --- a/pkg/gateway/splunk/license-manager/fixture/license_fixture.go +++ b/pkg/gateway/splunk/license-manager/fixture/license_fixture.go @@ -9,7 +9,7 @@ import ( "path/filepath" //"encoding/json" - "io/ioutil" + "net/http" "github.com/go-logr/logr" @@ -94,7 +94,7 @@ func (p *fixtureGateway) GetLicenseGroup(ctx context.Context) (*[]licensemodel.L log.Error(err, "fixture: unable to find path") return nil, err } - content, err := ioutil.ReadFile(relativePath + "/license_group.json") + content, err := os.ReadFile(relativePath + "/license_group.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -142,7 +142,7 @@ func (p *fixtureGateway) GetLicense(ctx context.Context) (*[]licensemodel.Licens log.Error(err, "fixture: unable to find path") return nil, err } - content, err := ioutil.ReadFile(relativePath + "/license.json") + content, err := os.ReadFile(relativePath + "/license.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -199,7 +199,7 @@ func (p *fixtureGateway) GetLicenseLocalPeer(ctx context.Context) (*[]licensemod log.Error(err, "fixture: unable to find path") return nil, err } - content, err := ioutil.ReadFile(relativePath + "/license_local_peer.json") + content, err := os.ReadFile(relativePath + "/license_local_peer.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -255,7 +255,7 @@ func (p *fixtureGateway) GetLicenseMessage(ctx context.Context) (*[]licensemodel log.Error(err, "fixture: unable to find path") return nil, err } - content, err := ioutil.ReadFile(relativePath + "/license_message.json") + content, err := os.ReadFile(relativePath + "/license_message.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -311,7 +311,7 @@ func (p *fixtureGateway) GetLicensePools(ctx context.Context) (*[]licensemodel.L log.Error(err, "fixture: unable to find path") return nil, err } - content, err := ioutil.ReadFile(relativePath + "/license_pools.json") + content, err := os.ReadFile(relativePath + "/license_pools.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -367,7 +367,7 @@ func (p *fixtureGateway) GetLicensePeers(context context.Context) (*[]licensemod log.Error(err, "fixture: unable to find path") return nil, err } - content, err := ioutil.ReadFile(relativePath + "/license_peers.json") + content, err := os.ReadFile(relativePath + "/license_peers.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -423,7 +423,7 @@ func (p *fixtureGateway) GetLicenseUsage(ctx context.Context) (*[]licensemodel.L log.Error(err, "fixture: unable to find path") return nil, err } - content, err := ioutil.ReadFile(relativePath + "/license_usage.json") + content, err := os.ReadFile(relativePath + "/license_usage.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -479,7 +479,7 @@ func (p *fixtureGateway) GetLicenseStacks(ctx context.Context) (*[]licensemodel. log.Error(err, "fixture: unable to find path") return nil, err } - content, err := ioutil.ReadFile(relativePath + "/license_stack.json") + content, err := os.ReadFile(relativePath + "/license_stack.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err diff --git a/pkg/gateway/splunk/license-manager/implementation/license_test.go b/pkg/gateway/splunk/license-manager/implementation/license_test.go index 477d91e75..a168ee220 100644 --- a/pkg/gateway/splunk/license-manager/implementation/license_test.go +++ b/pkg/gateway/splunk/license-manager/implementation/license_test.go @@ -3,6 +3,7 @@ package impl import ( "context" "fmt" + "os" "time" "github.com/go-resty/resty/v2" @@ -12,7 +13,6 @@ import ( //managermodel "github.com/splunk/splunk-operator/pkg/gateway/splunk/model/services/cluster/manager" //peermodel "github.com/splunk/splunk-operator/pkg/gateway/splunk/model/services/cluster/peer" - "io/ioutil" "testing" logz "sigs.k8s.io/controller-runtime/pkg/log/zap" @@ -61,7 +61,7 @@ func GetLicenseGroup(t *testing.T) { ctx := context.TODO() sm := setCreds(t) httpmock.ActivateNonDefault(sm.client.GetClient()) - content, err := ioutil.ReadFile("../fixture/license_group.json") + content, err := os.ReadFile("../fixture/license_group.json") if err != nil { t.Errorf("fixture: error in get cluster manager health %v", err) } diff --git a/pkg/gateway/splunk/services/fixture/fixture.go b/pkg/gateway/splunk/services/fixture/fixture.go index 36d2c7086..9b55b66a5 100644 --- a/pkg/gateway/splunk/services/fixture/fixture.go +++ b/pkg/gateway/splunk/services/fixture/fixture.go @@ -9,7 +9,7 @@ import ( "path/filepath" //"encoding/json" - "io/ioutil" + "net/http" "github.com/go-logr/logr" @@ -19,6 +19,7 @@ import ( clustermodel "github.com/splunk/splunk-operator/pkg/gateway/splunk/model/services/cluster" managermodel "github.com/splunk/splunk-operator/pkg/gateway/splunk/model/services/cluster/manager" model "github.com/splunk/splunk-operator/pkg/splunk/model" + // peermodel "github.com/splunk/splunk-operator/pkg/gateway/splunk/model/services/cluster/peer" // searchheadmodel "github.com/splunk/splunk-operator/pkg/gateway/splunk/model/services/cluster/searchhead" // commonmodel "github.com/splunk/splunk-operator/pkg/gateway/splunk/model/services/common" @@ -101,7 +102,7 @@ func (p *fixtureGateway) GetClusterManagerInfo(ctx context.Context) (*[]managerm log.Error(err, "fixture: unable to find path") return nil, err } - content, err := ioutil.ReadFile(relativePath + "/cluster_config.json") + content, err := os.ReadFile(relativePath + "/cluster_config.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -150,7 +151,7 @@ func (p *fixtureGateway) GetClusterManagerPeers(ctx context.Context) (*[]manager } // Read entire file content, giving us little control but // making it very simple. No need to close the file. - content, err := ioutil.ReadFile(relativePath + "cluster_config.json") + content, err := os.ReadFile(relativePath + "cluster_config.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -204,7 +205,7 @@ func (p *fixtureGateway) GetClusterManagerHealth(ctx context.Context) (*[]manage // Read entire file content, giving us little control but // making it very simple. No need to close the file. - content, err := ioutil.ReadFile(relativePath + "cluster_config.json") + content, err := os.ReadFile(relativePath + "cluster_config.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -255,7 +256,7 @@ func (p *fixtureGateway) GetClusterManagerSites(ctx context.Context) (*[]manager } // Read entire file content, giving us little control but // making it very simple. No need to close the file. - content, err := ioutil.ReadFile(relativePath + "/cluster_config.json") + content, err := os.ReadFile(relativePath + "/cluster_config.json") if err != nil { log.Error(err, "fixture: error in get cluster config") return nil, err @@ -304,7 +305,7 @@ func (p *fixtureGateway) GetClusterManagerStatus(ctx context.Context) (*[]manage } // Read entire file content, giving us little control but // making it very simple. No need to close the file. - content, err := ioutil.ReadFile(relativePath + "/cluster_manager_status.json") + content, err := os.ReadFile(relativePath + "/cluster_manager_status.json") if err != nil { log.Error(err, "fixture: error in get cluster manager search heads") return nil, err @@ -355,7 +356,7 @@ func (p *fixtureGateway) SetClusterInMaintenanceMode(context context.Context, mo } // Read entire file content, giving us little control but // making it very simple. No need to close the file. - content, err := ioutil.ReadFile(relativePath + "/cluster_maintenance.json") + content, err := os.ReadFile(relativePath + "/cluster_maintenance.json") if err != nil { log.Error(err, "fixture: error in post cluster maintenance") return err diff --git a/pkg/gateway/splunk/services/implementation/splunk_test.go b/pkg/gateway/splunk/services/implementation/splunk_test.go index 03e1429d3..4faaed56f 100644 --- a/pkg/gateway/splunk/services/implementation/splunk_test.go +++ b/pkg/gateway/splunk/services/implementation/splunk_test.go @@ -3,6 +3,7 @@ package impl import ( "context" "fmt" + "os" "time" "github.com/go-resty/resty/v2" @@ -12,7 +13,7 @@ import ( //managermodel "github.com/splunk/splunk-operator/pkg/gateway/splunk/model/services/cluster/manager" //peermodel "github.com/splunk/splunk-operator/pkg/gateway/splunk/model/services/cluster/peer" - "io/ioutil" + "testing" logz "sigs.k8s.io/controller-runtime/pkg/log/zap" @@ -61,7 +62,7 @@ func TestGetClusterManagerHealth(t *testing.T) { ctx := context.TODO() sm := setCreds(t) httpmock.ActivateNonDefault(sm.client.GetClient()) - content, err := ioutil.ReadFile("../fixture/cluster_manager_health.json") + content, err := os.ReadFile("../fixture/cluster_manager_health.json") if err != nil { t.Errorf("fixture: error in get cluster manager health %v", err) } @@ -83,7 +84,7 @@ func TestGetClusterManagerInfo(t *testing.T) { ctx := context.TODO() sm := setCreds(t) httpmock.ActivateNonDefault(sm.client.GetClient()) - content, err := ioutil.ReadFile("../fixture/cluster_manager_info.json") + content, err := os.ReadFile("../fixture/cluster_manager_info.json") if err != nil { t.Errorf("fixture: error in get cluster manager info %v", err) } @@ -105,7 +106,7 @@ func TestGetClusterManagerPeers(t *testing.T) { ctx := context.TODO() sm := setCreds(t) httpmock.ActivateNonDefault(sm.client.GetClient()) - content, err := ioutil.ReadFile("../fixture/cluster_manager_peers.json") + content, err := os.ReadFile("../fixture/cluster_manager_peers.json") if err != nil { t.Errorf("fixture: error in get cluster manager peers %v", err) } @@ -130,7 +131,7 @@ func TestSetClusterInMaintenanceeMode(t *testing.T) { ctx := context.TODO() sm := setCreds(t) httpmock.ActivateNonDefault(sm.client.GetClient()) - content, err := ioutil.ReadFile("../fixture/cluster_maintenance.json") + content, err := os.ReadFile("../fixture/cluster_maintenance.json") if err != nil { t.Errorf("fixture: error in get cluster manager peers %v", err) } diff --git a/pkg/provisioner/splunk/implementation/license_test.go b/pkg/provisioner/splunk/implementation/license_test.go index 006754588..beac466d6 100644 --- a/pkg/provisioner/splunk/implementation/license_test.go +++ b/pkg/provisioner/splunk/implementation/license_test.go @@ -44,6 +44,6 @@ func TestGetLicenseLocalPeer(t *testing.T) { t.Errorf("fixture: error in set cluster manager %v", err) } if conditions == nil || len(*conditions) == 0 { - t.Errorf("fixture: error in conditions for lm %v", err) + t.Errorf("fixture: error in conditions for license manager %v", err) } } diff --git a/pkg/provisioner/splunk/implementation/splunk.go b/pkg/provisioner/splunk/implementation/splunk.go index d8fcbd829..ead2bea25 100644 --- a/pkg/provisioner/splunk/implementation/splunk.go +++ b/pkg/provisioner/splunk/implementation/splunk.go @@ -135,8 +135,6 @@ func (p *splunkProvisioner) GetClusterManagerStatus(ctx context.Context, conditi meta.SetStatusCondition(conditions, condition) } - // business logic starts here - //healthList, err := callGetClusterManagerHealth(ctx, p) healthList, err := callGetClusterManagerHealth(ctx, p) if err != nil { return result, err