Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pkg/splunk/client/enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func TestGetclusterManagerInfo(t *testing.T) {
}
return nil
}
body = splcommon.TestGetCMInfoEmpty
body = loadFixture(t, "get_cm_info_empty.json")
splunkClientTester(t, "TestGetclusterManagerInfo", 200, body, wantRequest, test)

// test error code
Expand All @@ -331,7 +331,7 @@ func TestGetIndexerClusterPeerInfo(t *testing.T) {
}
return nil
}
body := splcommon.TestGetIndexerClusterPeerInfo
body := loadFixture(t, "get_indexer_cluster_peer_info.json")
splunkClientTester(t, "TestGetIndexerClusterPeerInfo", 200, body, wantRequest, test)

// test body with no entries
Expand All @@ -342,7 +342,7 @@ func TestGetIndexerClusterPeerInfo(t *testing.T) {
}
return nil
}
body = splcommon.TestGetIndexerClusterPeerInfoEmpty
body = loadFixture(t, "get_indexer_cluster_peer_info_empty.json")
splunkClientTester(t, "TestGetIndexerClusterPeerInfo", 200, body, wantRequest, test)

// test error code
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestGetClusterManagerPeers(t *testing.T) {
}
return nil
}
body := splcommon.TestGetCMPeers
body := loadFixture(t, "get_cm_peers.json")
splunkClientTester(t, "TestGetClusterManagerPeers", 200, body, wantRequest, test)

// test error response
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestAutomateMCApplyChanges(t *testing.T) {
wantRequests = []*http.Request(append(wantRequests, request1, request2, request3, request4, request5, request6, request7, request8, request9, request10))
body := []string{
`{"links":{},"origin":"https://localhost:8089/services/server/info","updated":"2020-09-24T06:38:53+00:00","generator":{"build":"a1a6394cc5ae","version":"8.0.5"},"entry":[{"name":"server-info","id":"https://localhost:8089/services/server/info/server-info","updated":"1970-01-01T00:00:00+00:00","links":{"alternate":"/services/server/info/server-info","list":"/services/server/info/server-info"},"author":"system","acl":{"app":"","can_list":true,"can_write":true,"modifiable":false,"owner":"system","perms":{"read":["*"],"write":[]},"removable":false,"sharing":"system"},"fields":{"required":[],"optional":[],"wildcard":[]},"content":{"activeLicenseGroup":"Trial","activeLicenseSubgroup":"Production","build":"a1a6394cc5ae","cluster_label":["idxc_label"],"cpu_arch":"x86_64","eai:acl":null,"fips_mode":false,"guid":"0F93F33C-4BDA-4A74-AD9F-3FCE26C6AFF0","health_info":"green","health_version":1,"host":"splunk-default-monitoring-console-86bc9b7c8c-d96x2","host_fqdn":"splunk-default-monitoring-console-86bc9b7c8c-d96x2","host_resolved":"splunk-default-monitoring-console-86bc9b7c8c-d96x2","isForwarding":true,"isFree":false,"isTrial":true,"kvStoreStatus":"ready","licenseKeys":["5C52DA5145AD67B8188604C49962D12F2C3B2CF1B82A6878E46F68CA2812807B"],"licenseSignature":"139bf73ec92c84121c79a9b8307a6724","licenseState":"OK","license_labels":["Splunk Enterprise Splunk Analytics for Hadoop Download Trial"],"master_guid":"0F93F33C-4BDA-4A74-AD9F-3FCE26C6AFF0","master_uri":"self","max_users":4294967295,"mode":"normal","numberOfCores":1,"numberOfVirtualCores":2,"os_build":"#1 SMP Thu Sep 3 19:04:44 UTC 2020","os_name":"Linux","os_name_extended":"Linux","os_version":"4.14.193-149.317.amzn2.x86_64","physicalMemoryMB":7764,"product_type":"enterprise","rtsearch_enabled":true,"serverName":"splunk-default-monitoring-console-86bc9b7c8c-d96x2","server_roles":["license_master","cluster_search_head","search_head"],"startup_time":1600928786,"staticAssetId":"CFE3D41EE2CCD1465E8C8453F83E4ECFFF540780B4490E84458DD4A3694CE4D1","version":"8.0.5"}}],"paging":{"total":1,"perPage":30,"offset":0},"messages":[]}`,
splcommon.TestMCApplyChanges,
loadFixture(t, "mc_apply_changes.json"),
"",
"",
"",
Expand Down Expand Up @@ -464,7 +464,7 @@ func TestGetMonitoringconsoleServerRoles(t *testing.T) {
}
return nil
}
body := splcommon.TestGetClusterInfo
body := loadFixture(t, "get_cluster_info.json")
splunkClientTester(t, "TestGetMonitoringconsoleServerRoles", 200, body, wantRequest, test)

// Test negative conditions
Expand Down Expand Up @@ -510,7 +510,7 @@ func TestGetMonitoringconsoleAssetTable(t *testing.T) {
}
return nil
}
body := splcommon.TestGetMCAssetTable
body := loadFixture(t, "get_mc_asset_table.json")
splunkClientTester(t, "TestGetMonitoringconsoleAssetTable", 200, body, wantRequest, test)

// Test negative conditions
Expand Down Expand Up @@ -615,7 +615,7 @@ func TestGetClusterInfo(t *testing.T) {
}
return nil
}
body := splcommon.TestGetClusterInfo
body := loadFixture(t, "get_cluster_info.json")
splunkClientTester(t, "TestGetClusterInfo", 200, body, wantRequest, test)

// Test negative conditions
Expand Down
39 changes: 39 additions & 0 deletions pkg/splunk/client/test_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2018-2022 Splunk Inc. All rights reserved.

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package client

import (
"bytes"
"encoding/json"
"os"
"path/filepath"
"testing"
)

func loadFixture(t *testing.T, filename string) string {
t.Helper()
path := filepath.Join("testdata", "fixtures", filename)
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("Failed to load fixture %s: %v", filename, err)
}

var compactJSON bytes.Buffer
if err := json.Compact(&compactJSON, data); err != nil {
t.Fatalf("Failed to compact JSON from fixture %s: %v", filename, err)
}
return compactJSON.String()
}
98 changes: 98 additions & 0 deletions pkg/splunk/client/testdata/fixtures/get_cluster_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"links": {},
"origin": "https://localhost:8089/services/server/info",
"updated": "2020-09-24T06:38:53+00:00",
"generator": {
"build": "a1a6394cc5ae",
"version": "8.0.5"
},
"entry": [
{
"name": "server-info",
"id": "https://localhost:8089/services/server/info/server-info",
"updated": "1970-01-01T00:00:00+00:00",
"links": {
"alternate": "/services/server/info/server-info",
"list": "/services/server/info/server-info"
},
"author": "system",
"acl": {
"app": "",
"can_list": true,
"can_write": true,
"modifiable": false,
"owner": "system",
"perms": {
"read": [
"*"
],
"write": []
},
"removable": false,
"sharing": "system"
},
"fields": {
"required": [],
"optional": [],
"wildcard": []
},
"content": {
"activeLicenseGroup": "Trial",
"activeLicenseSubgroup": "Production",
"build": "a1a6394cc5ae",
"cluster_label": [
"idxc_label"
],
"cpu_arch": "x86_64",
"eai:acl": null,
"fips_mode": false,
"guid": "0F93F33C-4BDA-4A74-AD9F-3FCE26C6AFF0",
"health_info": "green",
"health_version": 1,
"host": "splunk-default-monitoring-console-86bc9b7c8c-d96x2",
"host_fqdn": "splunk-default-monitoring-console-86bc9b7c8c-d96x2",
"host_resolved": "splunk-default-monitoring-console-86bc9b7c8c-d96x2",
"isForwarding": true,
"isFree": false,
"isTrial": true,
"kvStoreStatus": "ready",
"licenseKeys": [
"5C52DA5145AD67B8188604C49962D12F2C3B2CF1B82A6878E46F68CA2812807B"
],
"licenseSignature": "139bf73ec92c84121c79a9b8307a6724",
"licenseState": "OK",
"license_labels": [
"Splunk Enterprise Splunk Analytics for Hadoop Download Trial"
],
"master_guid": "0F93F33C-4BDA-4A74-AD9F-3FCE26C6AFF0",
"master_uri": "self",
"max_users": 4294967295,
"mode": "normal",
"numberOfCores": 1,
"numberOfVirtualCores": 2,
"os_build": "#1 SMP Thu Sep 3 19:04:44 UTC 2020",
"os_name": "Linux",
"os_name_extended": "Linux",
"os_version": "4.14.193-149.317.amzn2.x86_64",
"physicalMemoryMB": 7764,
"product_type": "enterprise",
"rtsearch_enabled": true,
"serverName": "splunk-default-monitoring-console-86bc9b7c8c-d96x2",
"server_roles": [
"license_master",
"cluster_search_head",
"search_head"
],
"startup_time": 1600928786,
"staticAssetId": "CFE3D41EE2CCD1465E8C8453F83E4ECFFF540780B4490E84458DD4A3694CE4D1",
"version": "8.0.5"
}
}
],
"paging": {
"total": 1,
"perPage": 30,
"offset": 0
},
"messages": []
}
16 changes: 16 additions & 0 deletions pkg/splunk/client/testdata/fixtures/get_cm_info_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"links": {},
"origin": "https://localhost:8089/services/cluster/master/info",
"updated": "2020-03-18T01:04:53+00:00",
"generator": {
"build": "a7f645ddaf91",
"version": "8.0.2"
},
"entry": [],
"paging": {
"total": 1,
"perPage": 30,
"offset": 0
},
"messages": []
}
113 changes: 113 additions & 0 deletions pkg/splunk/client/testdata/fixtures/get_cm_peers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"links": {
"create": "/services/cluster/master/peers/_new"
},
"origin": "https://localhost:8089/services/cluster/master/peers",
"updated": "2020-03-18T01:08:53+00:00",
"generator": {
"build": "a7f645ddaf91",
"version": "8.0.2"
},
"entry": [
{
"name": "D39B1729-E2C5-4273-B9B2-534DA7C2F866",
"id": "https://localhost:8089/services/cluster/master/peers/D39B1729-E2C5-4273-B9B2-534DA7C2F866",
"updated": "1970-01-01T00:00:00+00:00",
"links": {
"alternate": "/services/cluster/master/peers/D39B1729-E2C5-4273-B9B2-534DA7C2F866",
"list": "/services/cluster/master/peers/D39B1729-E2C5-4273-B9B2-534DA7C2F866",
"edit": "/services/cluster/master/peers/D39B1729-E2C5-4273-B9B2-534DA7C2F866"
},
"author": "system",
"acl": {
"app": "",
"can_list": true,
"can_write": true,
"modifiable": false,
"owner": "system",
"perms": {
"read": [
"admin",
"splunk-system-role"
],
"write": [
"admin",
"splunk-system-role"
]
},
"removable": false,
"sharing": "system"
},
"content": {
"active_bundle_id": "14310A4AABD23E85BBD4559C4A3B59F8",
"apply_bundle_status": {
"invalid_bundle": {
"bundle_validation_errors": [],
"invalid_bundle_id": ""
},
"reasons_for_restart": [],
"restart_required_for_apply_bundle": false,
"status": "None"
},
"base_generation_id": 26,
"bucket_count": 73,
"bucket_count_by_index": {
"_audit": 24,
"_internal": 45,
"_telemetry": 4
},
"buckets_rf_by_origin_site": {
"default": 73
},
"buckets_sf_by_origin_site": {
"default": 73
},
"delayed_buckets_to_discard": [],
"eai:acl": null,
"fixup_set": [],
"heartbeat_started": true,
"host_port_pair": "10.36.0.6:8089",
"indexing_disk_space": 210707374080,
"is_searchable": true,
"is_valid_bundle": true,
"label": "splunk-s1-indexer-0",
"last_dry_run_bundle": "",
"last_heartbeat": 1584493732,
"last_validated_bundle": "14310A4AABD23E85BBD4559C4A3B59F8",
"latest_bundle_id": "14310A4AABD23E85BBD4559C4A3B59F8",
"peer_registered_summaries": true,
"pending_builds": [],
"pending_job_count": 0,
"primary_count": 73,
"primary_count_remote": 0,
"register_search_address": "10.36.0.6:8089",
"replication_count": 0,
"replication_port": 9887,
"replication_use_ssl": false,
"restart_required_for_applying_dry_run_bundle": false,
"search_state_counter": {
"PendingSearchable": 0,
"Searchable": 73,
"SearchablePendingMask": 0,
"Unsearchable": 0
},
"site": "default",
"splunk_version": "8.0.2",
"status": "Up",
"status_counter": {
"Complete": 69,
"NonStreamingTarget": 0,
"StreamingSource": 4,
"StreamingTarget": 0
},
"summary_replication_count": 0
}
}
],
"paging": {
"total": 1,
"perPage": 30,
"offset": 0
},
"messages": []
}
Loading
Loading