diff --git a/account_groups.go b/account_groups.go index 5d74500..66ea74d 100644 --- a/account_groups.go +++ b/account_groups.go @@ -7,16 +7,16 @@ type AccountGroups []AccountGroup // AccountGroup - An account within a ThousandEyes organization type AccountGroup struct { - AccountGroupName string `json:"accountGroupName,omitempty"` - AID int `json:"aid,omitempty"` + AccountGroupName *string `json:"accountGroupName,omitempty"` + AID *int `json:"aid,omitempty"` } // SharedWithAccount describes accounts with which a resource is shared. // This is separate from the AccountGroup above only due to the difference // in JSON object names. type SharedWithAccount struct { - AccountGroupName string `json:"name,omitempty"` - AID int `json:"aid,omitempty"` + AccountGroupName *string `json:"name,omitempty"` + AID *int `json:"aid,omitempty"` } // GetAccountGroups - Get third party and webhook integrations diff --git a/account_groups_test.go b/account_groups_test.go index e1d7bcb..95a698e 100644 --- a/account_groups_test.go +++ b/account_groups_test.go @@ -20,8 +20,8 @@ func TestClient_GetAccountGroups(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := []SharedWithAccount{ { - AccountGroupName: "Test Account", - AID: 1, + AccountGroupName: String("Test Account"), + AID: Int(1), }, } diff --git a/agent.go b/agent.go index 9021164..d310df3 100644 --- a/agent.go +++ b/agent.go @@ -7,47 +7,47 @@ type Agents []Agent // Agent - Agent struct type Agent struct { - AgentID int `json:"agentId,omitempty"` - AgentName string `json:"agentName,omitempty"` - AgentType string `json:"agentType,omitempty"` - CountryID string `json:"countryId,omitempty"` + AgentID *int `json:"agentId,omitempty"` + AgentName *string `json:"agentName,omitempty"` + AgentType *string `json:"agentType,omitempty"` + CountryID *string `json:"countryId,omitempty"` ClusterMembers []ClusterMember `json:"clusterMembers,omitempty"` IPAddresses []string `json:"ipAddresses,omitempty"` Groups GroupLabels `json:"groups,omitempty"` - Location string `json:"location,omitempty"` + Location *string `json:"location,omitempty"` ErrorDetails []AgentErrorDetails `json:"errorDetails,omitempty"` - Hostname string `json:"hostname,omitempty"` - Prefix string `json:"prefix,omitempty"` - Enabled int `json:"enabled,omitempty"` - Network string `json:"network,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - LastSeen string `json:"lastSeen,omitempty"` - AgentState string `json:"agentState,omitempty"` - VerifySslCertificates int `json:"verifySslCertificate,omitempty"` - KeepBrowserCache int `json:"keepBrowserCache,omitempty"` - Utilization int `json:"utilization,omitempty"` - Ipv6Policy string `json:"IPV6Policy,omitempty"` - TargetForTests string `json:"targetForTests,omitempty"` + Hostname *string `json:"hostname,omitempty"` + Prefix *string `json:"prefix,omitempty"` + Enabled *int `json:"enabled,omitempty"` + Network *string `json:"network,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + LastSeen *string `json:"lastSeen,omitempty"` + AgentState *string `json:"agentState,omitempty"` + VerifySslCertificates *int `json:"verifySslCertificate,omitempty"` + KeepBrowserCache *int `json:"keepBrowserCache,omitempty"` + Utilization *int `json:"utilization,omitempty"` + Ipv6Policy *string `json:"IPV6Policy,omitempty"` + TargetForTests *string `json:"targetForTests,omitempty"` } //ClusterMember - ClusterMember struct type ClusterMember struct { - MemberID int `json:"memberId,omitempty"` - Name string `json:"name,omitempty"` + MemberID *int `json:"memberId,omitempty"` + Name *string `json:"name,omitempty"` IPAddresses []string `json:"IPAddresses,omitempty"` PublicIPAddresses []string `json:"PublicIPAddresses,omitempty"` - Prefix string `json:"Prefix,omitempty"` - Network string `json:"network,omitempty"` - LastSeen string `json:"lastSeen,omitempty"` - AgentState string `json:"agentState,omitempty"` - Utilization int `json:"utilization,omitempty"` - TargetForTests string `json:"targetForTests,omitempty"` + Prefix *string `json:"Prefix,omitempty"` + Network *string `json:"network,omitempty"` + LastSeen *string `json:"lastSeen,omitempty"` + AgentState *string `json:"agentState,omitempty"` + Utilization *int `json:"utilization,omitempty"` + TargetForTests *string `json:"targetForTests,omitempty"` } // AgentErrorDetails - Agent error details type AgentErrorDetails struct { - Code string `json:"code,omitempty"` - Description string `json:"description,omitempty"` + Code *string `json:"code,omitempty"` + Description *string `json:"description,omitempty"` } // GetAgents - Get agents diff --git a/agent_agent.go b/agent_agent.go index b0903af..5e4029a 100644 --- a/agent_agent.go +++ b/agent_agent.go @@ -7,54 +7,54 @@ import ( // AgentAgent - test type AgentAgent struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents []Agent `json:"agents,omitempty"` - BGPMeasurements int `json:"bgpMeasurements,omitempty"` + BGPMeasurements *int `json:"bgpMeasurements,omitempty"` BGPMonitors []BGPMonitor `json:"bgpMonitors,omitempty"` - Direction string `json:"direction,omitempty"` - DSCP string `json:"dscp,omitempty"` - DSCPID int `json:"dscpId"` - Interval int `json:"interval,omitempty"` - MSS int `json:"mss,omitempty"` - NetworkMeasurements int `json:"networkMeasurements,omitempty"` - MTUMeasurements int `json:"mtuMeasurements,omitempty"` - NumPathTraces int `json:"numPathTraces,omitempty"` - PathTraceMode string `json:"pathTraceMode,omitempty"` - Port int `json:"port,omitempty"` - Protocol string `json:"protocol,omitempty"` - TargetAgentID int `json:"targetAgentId,omitempty"` - ThroughputDuration int `json:"throughputDuration,omitempty"` - ThroughputMeasurements int `json:"throughputMeasurements,omitempty"` - ThroughputRate int `json:"throughputRate,omitempty"` - UsePublicBGP int `json:"usePublicBgp,omitempty"` + Direction *string `json:"direction,omitempty"` + DSCP *string `json:"dscp,omitempty"` + DSCPID *int `json:"dscpId"` + Interval *int `json:"interval,omitempty"` + MSS *int `json:"mss,omitempty"` + NetworkMeasurements *int `json:"networkMeasurements,omitempty"` + MTUMeasurements *int `json:"mtuMeasurements,omitempty"` + NumPathTraces *int `json:"numPathTraces,omitempty"` + PathTraceMode *string `json:"pathTraceMode,omitempty"` + Port *int `json:"port,omitempty"` + Protocol *string `json:"protocol,omitempty"` + TargetAgentID *int `json:"targetAgentId,omitempty"` + ThroughputDuration *int `json:"throughputDuration,omitempty"` + ThroughputMeasurements *int `json:"throughputMeasurements,omitempty"` + ThroughputRate *int `json:"throughputRate,omitempty"` + UsePublicBGP *int `json:"usePublicBgp,omitempty"` } // AddAgent - Adds an agent to agent test func (t *AgentAgent) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } // AddAlertRule - Adds an alert to agent test func (t *AgentAgent) AddAlertRule(id int) { - alertRule := AlertRule{RuleID: id} + alertRule := AlertRule{RuleID: Int(id)} t.AlertRules = append(t.AlertRules, alertRule) } diff --git a/agent_agent_test.go b/agent_agent_test.go index 1777d3c..46f4516 100644 --- a/agent_agent_test.go +++ b/agent_agent_test.go @@ -8,15 +8,15 @@ import ( ) func TestClient_AddAgentAgentAlertRule(t *testing.T) { - test := AgentAgent{TestName: "test", AlertRules: []AlertRule{}} - expected := AgentAgent{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} + test := AgentAgent{TestName: String("test"), AlertRules: []AlertRule{}} + expected := AgentAgent{TestName: String("test"), AlertRules: []AlertRule{{RuleID: Int(1)}}} test.AddAlertRule(1) assert.Equal(t, expected, test) } func TestClient_AgentAgentAddAgent(t *testing.T) { - test := AgentAgent{TestName: "test", Agents: Agents{}} - expected := AgentAgent{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := AgentAgent{TestName: String("test"), Agents: Agents{}} + expected := AgentAgent{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } @@ -33,19 +33,19 @@ func TestClient_CreateAgentAgent(t *testing.T) { }) expected := AgentAgent{ - TestID: 1, - TestName: "test", - CreatedDate: "2020-02-06 15:28:07", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - Port: 8090, - PathTraceMode: "classic", - ThroughputMeasurements: 1, + TestID: Int64(1), + TestName: String("test"), + CreatedDate: String("2020-02-06 15:28:07"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + Port: Int(8090), + PathTraceMode: String("classic"), + ThroughputMeasurements: Int(1), } create := AgentAgent{ - TestName: "test", - Port: 8090, - PathTraceMode: "classic", + TestName: String("test"), + Port: Int(8090), + PathTraceMode: String("classic"), } res, err := client.CreateAgentAgent(create) assert.Nil(t, err) @@ -66,8 +66,8 @@ func TestClient_GetAgentAgentJsonError(t *testing.T) { } func TestClient_AddAlertRule(t *testing.T) { - test := AgentAgent{TestName: "test", AlertRules: []AlertRule{}} - expected := AgentAgent{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} + test := AgentAgent{TestName: String("test"), AlertRules: []AlertRule{}} + expected := AgentAgent{TestName: String("test"), AlertRules: []AlertRule{{RuleID: Int(1)}}} test.AddAlertRule(1) assert.Equal(t, expected, test) } @@ -84,13 +84,13 @@ func TestClient_GetAgentAgent(t *testing.T) { }) expected := AgentAgent{ - TestID: 1, - TestName: "test", - CreatedDate: "2020-02-06 15:28:07", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - Port: 8090, - ThroughputDuration: 10000, - ThroughputMeasurements: 1, + TestID: Int64(1), + TestName: String("test"), + CreatedDate: String("2020-02-06 15:28:07"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + Port: Int(8090), + ThroughputDuration: Int(10000), + ThroughputMeasurements: Int(1), } res, err := client.GetAgentAgent(1) assert.Nil(t, err) @@ -126,14 +126,14 @@ func TestClient_UpdateAgentAgent(t *testing.T) { }) expected := AgentAgent{ - TestID: 1, - TestName: "test", - CreatedDate: "2020-02-06 15:28:07", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - Port: 8090, + TestID: Int64(1), + TestName: String("test"), + CreatedDate: String("2020-02-06 15:28:07"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + Port: Int(8090), } update := AgentAgent{ - Port: 8090, + Port: Int(8090), } res, err := client.UpdateAgentAgent(1, update) assert.Nil(t, err) @@ -165,7 +165,7 @@ func TestClient_GetAgentAgentStatusCode(t *testing.T) { _, err := client.GetPageLoad(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateAgentAgentStatusCode(t *testing.T) { @@ -178,7 +178,7 @@ func TestClient_CreateAgentAgentStatusCode(t *testing.T) { }) _, err := client.CreateAgentAgent(AgentAgent{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateAgentAgentStatusCode(t *testing.T) { @@ -191,7 +191,7 @@ func TestClient_UpdateAgentAgentStatusCode(t *testing.T) { }) _, err := client.UpdateAgentAgent(1, AgentAgent{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteAgentAgentStatusCode(t *testing.T) { @@ -204,5 +204,5 @@ func TestClient_DeleteAgentAgentStatusCode(t *testing.T) { }) err := client.DeleteAgentAgent(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/agent_server.go b/agent_server.go index f868669..3828769 100644 --- a/agent_server.go +++ b/agent_server.go @@ -9,38 +9,38 @@ import ( // AgentServer - Agent to server test type AgentServer struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents Agents `json:"agents,omitempty"` - BandwidthMeasurements int `json:"bandwidthMeasurements,omitempty"` - BGPMeasurements int `json:"bgpMeasurements,omitempty"` + BandwidthMeasurements *int `json:"bandwidthMeasurements,omitempty"` + BGPMeasurements *int `json:"bgpMeasurements,omitempty"` BGPMonitors []BGPMonitor `json:"bgpMonitors,omitempty"` - Interval int `json:"interval,omitempty"` - MTUMeasurements int `json:"mtuMeasurements,omitempty"` - NetworkMeasurements int `json:"networkMeasurements,omitempty"` - NumPathTraces int `json:"numPathTraces,omitempty"` - PathTraceMode string `json:"pathTraceMode,omitempty"` - Port int `json:"port,omitempty"` - ProbeMode string `json:"probeMode,omitempty"` - Protocol string `json:"protocol,omitempty"` - Server string `json:"server,omitempty"` - UsePublicBGP int `json:"usePublicBgp,omitempty"` + Interval *int `json:"interval,omitempty"` + MTUMeasurements *int `json:"mtuMeasurements,omitempty"` + NetworkMeasurements *int `json:"networkMeasurements,omitempty"` + NumPathTraces *int `json:"numPathTraces,omitempty"` + PathTraceMode *string `json:"pathTraceMode,omitempty"` + Port *int `json:"port,omitempty"` + ProbeMode *string `json:"probeMode,omitempty"` + Protocol *string `json:"protocol,omitempty"` + Server *string `json:"server,omitempty"` + UsePublicBGP *int `json:"usePublicBgp,omitempty"` } // extractPort - Set Server and Port fields if they are combined in the Server field. @@ -48,27 +48,30 @@ func extractPort(test AgentServer) (AgentServer, error) { // Unfortunately, the V6 API returns the server value with the port, // rather than having them in separate values as the API requires for // submissions. Not required for ICMP tests. - var err error - if test.Protocol != "ICMP" && strings.Index(test.Server, ":") != -1 { - serverParts := strings.Split(test.Server, ":") - test.Server = serverParts[0] - test.Port, err = strconv.Atoi(serverParts[1]) + if (test.Protocol == nil || *test.Protocol != "ICMP") && + (test.Server != nil && strings.Index(*test.Server, ":") != -1) { + + serverParts := strings.Split(*test.Server, ":") + *test.Server = serverParts[0] + port, err := strconv.Atoi(serverParts[1]) if err != nil { err = fmt.Errorf("Invalid port in server declaration") + return test, err } + test.Port = Int(port) } return test, nil } // AddAgent - Add agent to server test func (t *AgentServer) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } // AddAlertRule - Adds an alert to agent test func (t *AgentServer) AddAlertRule(id int) { - alertRule := AlertRule{RuleID: id} + alertRule := AlertRule{RuleID: Int(id)} t.AlertRules = append(t.AlertRules, alertRule) } diff --git a/agent_server_test.go b/agent_server_test.go index 2ca7b3c..6c0c48b 100644 --- a/agent_server_test.go +++ b/agent_server_test.go @@ -8,15 +8,15 @@ import ( ) func TestClient_AddAgentSeverAlertRule(t *testing.T) { - test := AgentServer{TestName: "test", AlertRules: []AlertRule{}} - expected := AgentServer{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} + test := AgentServer{TestName: String("test"), AlertRules: []AlertRule{}} + expected := AgentServer{TestName: String("test"), AlertRules: []AlertRule{{RuleID: Int(1)}}} test.AddAlertRule(1) assert.Equal(t, expected, test) } func TestClient_AgentServerAddAgent(t *testing.T) { - test := AgentServer{TestName: "test", Agents: Agents{}} - expected := AgentServer{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := AgentServer{TestName: String("test"), Agents: Agents{}} + expected := AgentServer{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } @@ -33,17 +33,17 @@ func TestClient_CreateAgentServer(t *testing.T) { }) expected := AgentServer{ - TestID: 1, - TestName: "test", - CreatedDate: "2020-02-06 15:28:07", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - Port: 8090, - Server: "grumpysysadm.com", + TestID: Int64(1), + TestName: String("test"), + CreatedDate: String("2020-02-06 15:28:07"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + Port: Int(8090), + Server: String("grumpysysadm.com"), } create := AgentServer{ - TestName: "test", - Port: 8090, - Server: "grumpysysadm.com", + TestName: String("test"), + Port: Int(8090), + Server: String("grumpysysadm.com"), } res, err := client.CreateAgentServer(create) assert.Nil(t, err) @@ -51,8 +51,8 @@ func TestClient_CreateAgentServer(t *testing.T) { } func TestClient_AddAgentServerAlertRule(t *testing.T) { - test := AgentServer{TestName: "test", AlertRules: []AlertRule{}} - expected := AgentServer{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} + test := AgentServer{TestName: String("test"), AlertRules: []AlertRule{}} + expected := AgentServer{TestName: String("test"), AlertRules: []AlertRule{{RuleID: Int(1)}}} test.AddAlertRule(1) assert.Equal(t, expected, test) } @@ -82,11 +82,11 @@ func TestClient_GetAgentServer(t *testing.T) { }) expected := AgentServer{ - TestID: 1, - TestName: "test", - CreatedDate: "2020-02-06 15:28:07", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - Port: 8090, + TestID: Int64(1), + TestName: String("test"), + CreatedDate: String("2020-02-06 15:28:07"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + Port: Int(8090), } res, err := client.GetAgentServer(1) assert.Nil(t, err) @@ -122,14 +122,14 @@ func TestClient_UpdateAgentServer(t *testing.T) { }) expected := AgentServer{ - TestID: 1, - TestName: "test", - CreatedDate: "2020-02-06 15:28:07", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - Port: 8090, + TestID: Int64(1), + TestName: String("test"), + CreatedDate: String("2020-02-06 15:28:07"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + Port: Int(8090), } update := AgentServer{ - Port: 8090, + Port: Int(8090), } res, err := client.UpdateAgentServer(1, update) assert.Nil(t, err) @@ -161,7 +161,7 @@ func TestClient_GetAgentServerStatusCode(t *testing.T) { _, err := client.GetPageLoad(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateAgentServerStatusCode(t *testing.T) { @@ -174,7 +174,7 @@ func TestClient_CreateAgentServerStatusCode(t *testing.T) { }) _, err := client.CreateAgentServer(AgentServer{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateAgentServerStatusCode(t *testing.T) { @@ -187,7 +187,7 @@ func TestClient_UpdateAgentServerStatusCode(t *testing.T) { }) _, err := client.UpdateAgentServer(1, AgentServer{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteAgentServerStatusCode(t *testing.T) { @@ -200,24 +200,24 @@ func TestClient_DeleteAgentServerStatusCode(t *testing.T) { }) err := client.DeleteAgentServer(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestExtractPort(t *testing.T) { test := AgentServer{ Agents: []Agent{ { - AgentID: 75, + AgentID: Int(75), }, }, - Interval: 3600, - Server: "foo.com:8888", + Interval: Int(3600), + Server: String("foo.com:8888"), } result, err := extractPort(test) if err != nil { assert.Error(t, err) } - test.Server = "foo.com" - test.Port = 8888 + test.Server = String("foo.com") + test.Port = Int(8888) assert.Equal(t, test, result) } diff --git a/agent_test.go b/agent_test.go index a0740dd..440e7ac 100644 --- a/agent_test.go +++ b/agent_test.go @@ -19,12 +19,12 @@ func TestClient_GetAgents(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := Agents{ Agent{ - AgentID: 1, - Enabled: 1, + AgentID: Int(1), + Enabled: Int(1), }, Agent{ - AgentID: 2, - Enabled: 0, + AgentID: Int(2), + Enabled: Int(0), }, } res, err := client.GetAgents() @@ -41,7 +41,7 @@ func TestClient_GetAgent(t *testing.T) { assert.Equal(t, "GET", r.Method) _, _ = w.Write([]byte(out)) }) - expected := Agent{AgentID: 1, Enabled: 1} + expected := Agent{AgentID: Int(1), Enabled: Int(1)} res, err := client.GetAgent(1) teardown() assert.Nil(t, err) @@ -99,7 +99,7 @@ func TestClient_GetAgentsStatusCode(t *testing.T) { _, err := client.GetAgents() teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_GetAgentStatusCode(t *testing.T) { @@ -114,7 +114,7 @@ func TestClient_GetAgentStatusCode(t *testing.T) { _, err := client.GetAgent(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_AddAgentToClusterStatusCode(t *testing.T) { @@ -129,7 +129,7 @@ func TestClient_AddAgentToClusterStatusCode(t *testing.T) { _, err := client.AddAgentsToCluster(1, []int{8001}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_RemoveAgentToClusterStatusCode(t *testing.T) { @@ -144,7 +144,7 @@ func TestClient_RemoveAgentToClusterStatusCode(t *testing.T) { _, err := client.RemoveAgentsFromCluster(1, []int{8001}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_AddAgentToClusterJsonError(t *testing.T) { @@ -184,12 +184,12 @@ func TestClient_RemoveAgentFromCluster(t *testing.T) { res, _ := client.RemoveAgentsFromCluster(1, []int{8001}) exp := []Agent{ { - AgentID: 1, - AgentName: "test", + AgentID: Int(1), + AgentName: String("test"), ClusterMembers: []ClusterMember{ { - MemberID: 80002, - Name: "test", + MemberID: Int(80002), + Name: String("test"), }, }, }, @@ -208,12 +208,12 @@ func TestClient_AddAgentToCluster(t *testing.T) { res, _ := client.AddAgentsToCluster(1, []int{8002}) exp := []Agent{ { - AgentID: 1, - AgentName: "test", + AgentID: Int(1), + AgentName: String("test"), ClusterMembers: []ClusterMember{ { - MemberID: 80002, - Name: "test", + MemberID: Int(80002), + Name: String("test"), }, }, }, diff --git a/alert_test.go b/alert_test.go index b899175..9b81f39 100644 --- a/alert_test.go +++ b/alert_test.go @@ -18,7 +18,7 @@ func TestClient_GetAlertRule(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := AlertRules{ - AlertRule{RuleID: 1, RuleName: "test"}, + AlertRule{RuleID: Int(1), RuleName: String("test")}, } res, err := client.GetAlertRules() @@ -67,18 +67,18 @@ func TestClient_UpdateAlertRule(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 1 - u := AlertRule{RoundsViolatingOutOf: 2} + u := AlertRule{RoundsViolatingOutOf: Int(2)} res, err := client.UpdateAlertRule(id, u) if err != nil { t.Fatal(err) } - expected := AlertRule{RuleID: 1, RuleName: "test", RoundsViolatingOutOf: 2, RoundsViolatingRequired: 1} + expected := AlertRule{RuleID: Int(1), RuleName: String("test"), RoundsViolatingOutOf: Int(2), RoundsViolatingRequired: Int(1)} assert.Equal(t, &expected, res) } func TestClient_CreateAlertRule(t *testing.T) { setup() - out := `{"AlertRuleID":1, "ruleName": "test", "roundsViolatingOutOf": 2, "roundsViolatingRequired": 1}` + out := `{"alertRuleId": 1, "ruleName": "test", "roundsViolatingOutOf": 2, "roundsViolatingRequired": 1}` mux.HandleFunc("/alert-rules/new.json", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, "POST", r.Method) w.WriteHeader(http.StatusCreated) @@ -86,12 +86,12 @@ func TestClient_CreateAlertRule(t *testing.T) { }) var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - u := AlertRule{RuleName: "test", RoundsViolatingOutOf: 2, RoundsViolatingRequired: 1} + u := AlertRule{RuleName: String("test"), RoundsViolatingOutOf: Int(2), RoundsViolatingRequired: Int(1)} res, err := client.CreateAlertRule(u) if err != nil { t.Fatal(err) } - expected := AlertRule{RuleID: 1, RuleName: "test", RoundsViolatingOutOf: 2, RoundsViolatingRequired: 1} + expected := AlertRule{RuleID: Int(1), RuleName: String("test"), RoundsViolatingOutOf: Int(2), RoundsViolatingRequired: Int(1)} assert.Equal(t, &expected, res) } @@ -120,7 +120,7 @@ func TestClient_GetAlertStatusCode(t *testing.T) { _, err := client.GetAlertRules() teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateAlertStatusCode(t *testing.T) { @@ -133,7 +133,7 @@ func TestClient_CreateAlertStatusCode(t *testing.T) { }) _, err := client.CreateAlertRule(AlertRule{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateAlertRuleStatusCode(t *testing.T) { @@ -146,7 +146,7 @@ func TestClient_UpdateAlertRuleStatusCode(t *testing.T) { }) _, err := client.UpdateAlertRule(1, AlertRule{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteAlertRuleStatusCode(t *testing.T) { @@ -159,5 +159,5 @@ func TestClient_DeleteAlertRuleStatusCode(t *testing.T) { }) err := client.DeleteAlertRule(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/alerts.go b/alerts.go index cffdbbf..850932b 100644 --- a/alerts.go +++ b/alerts.go @@ -10,17 +10,17 @@ type Alerts []Alert // Alert - An alert type Alert struct { - AlertID int `json:"alertId,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Active int `json:"active,omitempty"` - RuleExpression string `json:"ruleExpression,omitempty"` - DateStart string `json:"dateStart,omitempty"` - DateEnd string `json:"dateEnd,omitempty"` - ViolationCount int `json:"violationCount,omitempty"` - RuleName string `json:"ruleName,omitempty"` - Permalink string `json:"permalink,omitempty"` - Type string `json:"type,omitempty"` + AlertID *int `json:"alertId,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Active *int `json:"active,omitempty"` + RuleExpression *string `json:"ruleExpression,omitempty"` + DateStart *string `json:"dateStart,omitempty"` + DateEnd *string `json:"dateEnd,omitempty"` + ViolationCount *int `json:"violationCount,omitempty"` + RuleName *string `json:"ruleName,omitempty"` + Permalink *string `json:"permalink,omitempty"` + Type *string `json:"type,omitempty"` Agents Agents `json:"agents,omitempty"` Monitors Monitors `json:"monitors,omitempty"` APILinks APILinks `json:"apiLinks,omitempty"` @@ -31,33 +31,33 @@ type AlertRules []AlertRule // NotificationEmail - Alert Rule Notification Email structure type NotificationEmail struct { - Message string `json:"message,omitempty"` - Recipient []string `json:"recipient,omitempty"` + Message *string `json:"message,omitempty"` + Recipient []string `json:"recipient,omitempty"` } // Notification - Alert Rule Notification structure type Notification struct { - Email NotificationEmail `json:"email,omitempty"` + Email NotificationEmail `json:"email,omitempty"` } // AlertRule - An alert rule type AlertRule struct { - AlertRuleID int `json:"alertRuleId,omitempty"` - AlertType string `json:"alertType,omitempty"` - Default int `json:"default,omitempty"` - Direction string `json:"direction,omitempty"` - Expression string `json:"expression,omitempty"` - IncludeCoveredPrefixes int `json:"includeCoveredPrefixes,omitempty"` - MinimumSources int `json:"minimumSources,omitempty"` - MinimumSourcesPct int `json:"minimumSourcesPct,omitempty"` - NotifyOnClear int `json:"notifyOnClear,omitempty"` - RoundsViolatingMode string `json:"roundsViolatingMode,omitempty"` - RoundsViolatingOutOf int `json:"roundsViolatingOutOf,omitempty"` - RoundsViolatingRequired int `json:"roundsViolatingRequired,omitempty"` - RuleID int `json:"ruleId,omitempty"` - RuleName string `json:"ruleName,omitempty"` - TestIds []int `json:"testIds,omitempty"` - Notifications Notification `json:"notifications,omitempty"` + AlertRuleID *int `json:"alertRuleId,omitempty"` + AlertType *string `json:"alertType,omitempty"` + Default *int `json:"default,omitempty"` + Direction *string `json:"direction,omitempty"` + Expression *string `json:"expression,omitempty"` + IncludeCoveredPrefixes *int `json:"includeCoveredPrefixes,omitempty"` + MinimumSources *int `json:"minimumSources,omitempty"` + MinimumSourcesPct *int `json:"minimumSourcesPct,omitempty"` + NotifyOnClear *int `json:"notifyOnClear,omitempty"` + RoundsViolatingMode *string `json:"roundsViolatingMode,omitempty"` + RoundsViolatingOutOf *int `json:"roundsViolatingOutOf,omitempty"` + RoundsViolatingRequired *int `json:"roundsViolatingRequired,omitempty"` + RuleID *int `json:"ruleId,omitempty"` + RuleName *string `json:"ruleName,omitempty"` + TestIds []int `json:"testIds,omitempty"` + Notifications Notification `json:"notifications,omitempty"` } // CreateAlertRule - Create alert rule @@ -78,7 +78,7 @@ func (c Client) CreateAlertRule(a AlertRule) (*AlertRule, error) { // We'll also UNset AlertRuleID so that it isn't seen as a change when it isn't // present in other API calls. target.RuleID = target.AlertRuleID - target.AlertRuleID = 0 + target.AlertRuleID = nil return &target, nil } diff --git a/bgp.go b/bgp.go index dbbf719..a7568b2 100644 --- a/bgp.go +++ b/bgp.go @@ -7,33 +7,33 @@ import ( // BGP - BGP trace test type BGP struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test BGPMonitors []BGPMonitor `json:"bgpMonitors,omitempty"` - IncludeCoveredPrefixes int `json:"includeCoveredPrefixes,omitempty"` - Prefix string `json:"prefix,omitempty"` - UsePublicBGP int `json:"usePublicBgp,omitempty"` + IncludeCoveredPrefixes *int `json:"includeCoveredPrefixes,omitempty"` + Prefix *string `json:"prefix,omitempty"` + UsePublicBGP *int `json:"usePublicBgp,omitempty"` } // AddAlertRule - Adds an alert to agent test func (t *BGP) AddAlertRule(id int) { - alertRule := AlertRule{RuleID: id} + alertRule := AlertRule{RuleID: Int(id)} t.AlertRules = append(t.AlertRules, alertRule) } diff --git a/bgp_monitor.go b/bgp_monitor.go index f451fe5..ab68fae 100644 --- a/bgp_monitor.go +++ b/bgp_monitor.go @@ -7,11 +7,11 @@ type BGPMonitors []BGPMonitor // BGPMonitor - BGPMonitor struct type BGPMonitor struct { - MonitorID int `json:"monitorId,omitempty"` - IPAddress string `json:"ipAddress,omitempty"` - Network string `json:"network,omitempty"` - MonitorType string `json:"monitorType,omitempty"` - MonitorName string `json:"monitorName,omitempty"` + MonitorID *int `json:"monitorId,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + Network *string `json:"network,omitempty"` + MonitorType *string `json:"monitorType,omitempty"` + MonitorName *string `json:"monitorName,omitempty"` } // GetBPGMonitors - Get bgp monitors diff --git a/bgp_monitor_test.go b/bgp_monitor_test.go index ef1eaef..d85fb02 100644 --- a/bgp_monitor_test.go +++ b/bgp_monitor_test.go @@ -19,7 +19,7 @@ func TestClient_GetBGPMonitors(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := BGPMonitors{ - BGPMonitor{MonitorID: 1, MonitorName: "test", MonitorType: "bgp", IPAddress: "1.2.3.4"}, + BGPMonitor{MonitorID: Int(1), MonitorName: String("test"), MonitorType: String("bgp"), IPAddress: String("1.2.3.4")}, } res, err := client.GetBPGMonitors() diff --git a/bgp_test.go b/bgp_test.go index 5e55bc1..83f6a59 100644 --- a/bgp_test.go +++ b/bgp_test.go @@ -8,8 +8,8 @@ import ( ) func TestClient_AddBGPAlertRule(t *testing.T) { - test := BGP{TestName: "test", AlertRules: []AlertRule{}} - expected := BGP{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} + test := BGP{TestName: String("test"), AlertRules: []AlertRule{}} + expected := BGP{TestName: String("test"), AlertRules: []AlertRule{{RuleID: Int(1)}}} test.AddAlertRule(1) assert.Equal(t, expected, test) } @@ -25,41 +25,42 @@ func TestClient_GetBGP(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := BGP{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - AlertsEnabled: 1, - TestName: "test123", - Type: "bgp", - Prefix: "1.2.3.0/20", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + AlertsEnabled: Int(1), + TestName: String("test123"), + Type: String("bgp"), + LiveShare: Int(0), + Prefix: String("1.2.3.0/20"), SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/dns-trace/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/dns-trace/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } @@ -95,49 +96,49 @@ func TestClient_CreateBGP(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := BGP{ - - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "bgp", - Prefix: "1.2.3.0/20", - AlertsEnabled: 1, + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + TestName: String("test123"), + Type: String("bgp"), + LiveShare: Int(0), + Prefix: String("1.2.3.0/20"), + AlertsEnabled: Int(1), SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/dns-trace/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/dns-trace/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } create := BGP{ - TestName: "test1", - Prefix: "1.2.3.0/20", + TestName: String("test1"), + Prefix: String("1.2.3.0/20"), } res, err := client.CreateBGP(create) teardown() @@ -177,7 +178,12 @@ func TestClient_UpdateBGP(t *testing.T) { if err != nil { t.Fatal(err) } - expected := BGP{TestID: 1, TestName: "test123", Type: "bgp", Prefix: "1.2.3.0/20"} + expected := BGP{ + TestID: Int64(1), + TestName: String("test123"), + Type: String("bgp"), + Prefix: String("1.2.3.0/20"), + } assert.Equal(t, &expected, res) } @@ -207,7 +213,7 @@ func TestClient_GetBGPStatusCode(t *testing.T) { _, err := client.GetBGP(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateBGPStatusCode(t *testing.T) { @@ -220,7 +226,7 @@ func TestClient_CreateBGPStatusCode(t *testing.T) { }) _, err := client.CreateBGP(BGP{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateBGPStatusCode(t *testing.T) { @@ -233,7 +239,7 @@ func TestClient_UpdateBGPStatusCode(t *testing.T) { }) _, err := client.UpdateBGP(1, BGP{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteBGPStatusCode(t *testing.T) { @@ -246,5 +252,5 @@ func TestClient_DeleteBGPStatusCode(t *testing.T) { }) err := client.DeleteBGP(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/client.go b/client.go index 34ab62d..71e5149 100644 --- a/client.go +++ b/client.go @@ -35,12 +35,12 @@ type APILinks []APILink // APILink - an api link type APILink struct { - Href string `json:"href,omitempty"` - Rel string `json:"rel,omitempty"` + Href *string `json:"href,omitempty"` + Rel *string `json:"rel,omitempty"` } type errorObject struct { - ErrorMessage string `json:"errorMessage,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` } // Limiter - Rate limiter interface diff --git a/dns_dnssec.go b/dns_dnssec.go index d21e6e5..2c12fb7 100644 --- a/dns_dnssec.go +++ b/dns_dnssec.go @@ -5,38 +5,38 @@ import "fmt" // DNSSec - DNSSec test type DNSSec struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents []Agent `json:"agents,omitempty"` - Domain string `json:"domain,omitempty"` - Interval int `json:"interval,omitempty"` + Domain *string `json:"domain,omitempty"` + Interval *int `json:"interval,omitempty"` } // AddAgent - Add agent to DNSSec test func (t *DNSSec) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } // AddAlertRule - Adds an alert to agent test func (t *DNSSec) AddAlertRule(id int) { - alertRule := AlertRule{RuleID: id} + alertRule := AlertRule{RuleID: Int(id)} t.AlertRules = append(t.AlertRules, alertRule) } diff --git a/dns_dnssec_test.go b/dns_dnssec_test.go index 46aa070..dfa434f 100644 --- a/dns_dnssec_test.go +++ b/dns_dnssec_test.go @@ -17,54 +17,55 @@ func TestClient_GetDNSSec(t *testing.T) { }) expected := DNSSec{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - AlertsEnabled: 1, - TestName: "test123", - Type: "dns-dnssec", - Interval: 300, - Domain: "webex.com", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + AlertsEnabled: Int(1), + TestName: String("test123"), + Type: String("dns-dnssec"), + Interval: Int(300), + LiveShare: Int(0), + Domain: String("webex.com"), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, APILinks: []APILink{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/dns-dnssec/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/dns-dnssec/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } @@ -99,62 +100,63 @@ func TestClient_CreateDNSSec(t *testing.T) { }) expected := DNSSec{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "dns-dnssec", - Interval: 300, - AlertsEnabled: 1, - Domain: "webex.com", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + TestName: String("test123"), + Type: String("dns-dnssec"), + Interval: Int(300), + LiveShare: Int(0), + AlertsEnabled: Int(1), + Domain: String("webex.com"), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, APILinks: []APILink{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/dns-dnssec/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/dns-dnssec/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } create := DNSSec{ - TestName: "test123", - Domain: "webex.com", - Interval: 300, + TestName: String("test123"), + Domain: String("webex.com"), + Interval: Int(300), } res, err := client.CreateDNSSec(create) teardown() @@ -179,8 +181,8 @@ func TestClient_DeleteDNSSec(t *testing.T) { } func TestClient_AddDNSSecAlertRule(t *testing.T) { - test := DNSSec{TestName: "test", AlertRules: []AlertRule{}} - expected := DNSSec{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} + test := DNSSec{TestName: String("test"), AlertRules: []AlertRule{}} + expected := DNSSec{TestName: String("test"), AlertRules: []AlertRule{{RuleID: Int(1)}}} test.AddAlertRule(1) assert.Equal(t, expected, test) } @@ -195,19 +197,19 @@ func TestClient_UpdateDNSSec(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 1 - dnsp := DNSSec{Domain: "webex.com"} + dnsp := DNSSec{Domain: String("webex.com")} res, err := client.UpdateDNSSec(id, dnsp) if err != nil { t.Fatal(err) } - expected := DNSSec{TestID: 1, TestName: "test123", Type: "dns-dnssec", Domain: "webex.com"} + expected := DNSSec{TestID: Int64(1), TestName: String("test123"), Type: String("dns-dnssec"), Domain: String("webex.com")} assert.Equal(t, &expected, res) } func TestDNSSec_AddAgent(t *testing.T) { - test := DNSSec{TestName: "test", Agents: Agents{}} - expected := DNSSec{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := DNSSec{TestName: String("test"), Agents: Agents{}} + expected := DNSSec{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } @@ -237,7 +239,7 @@ func TestClient_GetDNSSecStatusCode(t *testing.T) { _, err := client.GetDNSSec(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateDNSSecStatusCode(t *testing.T) { @@ -250,7 +252,7 @@ func TestClient_CreateDNSSecStatusCode(t *testing.T) { }) _, err := client.CreateDNSSec(DNSSec{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateDNSSecStatusCode(t *testing.T) { @@ -263,7 +265,7 @@ func TestClient_UpdateDNSSecStatusCode(t *testing.T) { }) _, err := client.UpdateDNSSec(1, DNSSec{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteDNSSecStatusCode(t *testing.T) { @@ -276,5 +278,5 @@ func TestClient_DeleteDNSSecStatusCode(t *testing.T) { }) err := client.DeleteDNSSec(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/dns_server.go b/dns_server.go index 4df20c8..a8c845b 100644 --- a/dns_server.go +++ b/dns_server.go @@ -6,58 +6,58 @@ import ( // Server - a server ? type Server struct { - ServerID int `json:"serverId,omitempty"` - ServerName string `json:"serverName,omitempty"` + ServerID *int `json:"serverId,omitempty"` + ServerName *string `json:"serverName,omitempty"` } // DNSServer - dns server test type DNSServer struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents Agents `json:"agents,omitempty"` - BandwidthMeasurements int `json:"bandwidthMeasurements,omitempty"` - BGPMeasurements int `json:"bgpMeasurements,omitempty"` + BandwidthMeasurements *int `json:"bandwidthMeasurements,omitempty"` + BGPMeasurements *int `json:"bgpMeasurements,omitempty"` BGPMonitors []BGPMonitor `json:"bgpMonitors,omitempty"` DNSServers []Server `json:"dnsServers,omitempty"` - DNSTransportProtocol string `json:"dnsTransportProtocol,omitempty"` - Domain string `json:"domain,omitempty"` - Interval int `json:"interval,omitempty"` - MTUMeasurements int `json:"mtuMeasurements,omitempty"` - NetworkMeasurements int `json:"networkMeasurements,omitempty"` - NumPathTraces int `json:"numPathTraces,omitempty"` - PathTraceMode string `json:"pathTraceMode,omitempty"` - ProbeMode string `json:"probeMode,omitempty"` - Protocol string `json:"protocol,omitempty"` - RecursiveQueries int `json:"recursiveQueries,omitempty"` - UsePublicBGP int `json:"usePublicBgp,omitempty"` + DNSTransportProtocol *string `json:"dnsTransportProtocol,omitempty"` + Domain *string `json:"domain,omitempty"` + Interval *int `json:"interval,omitempty"` + MTUMeasurements *int `json:"mtuMeasurements,omitempty"` + NetworkMeasurements *int `json:"networkMeasurements,omitempty"` + NumPathTraces *int `json:"numPathTraces,omitempty"` + PathTraceMode *string `json:"pathTraceMode,omitempty"` + ProbeMode *string `json:"probeMode,omitempty"` + Protocol *string `json:"protocol,omitempty"` + RecursiveQueries *int `json:"recursiveQueries,omitempty"` + UsePublicBGP *int `json:"usePublicBgp,omitempty"` } // AddAgent - Add dns server test func (t *DNSServer) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } // AddAlertRule - Adds an alert to agent test func (t *DNSServer) AddAlertRule(id int) { - alertRule := AlertRule{RuleID: id} + alertRule := AlertRule{RuleID: Int(id)} t.AlertRules = append(t.AlertRules, alertRule) } diff --git a/dns_server_test.go b/dns_server_test.go index 5012f05..4fcb05e 100644 --- a/dns_server_test.go +++ b/dns_server_test.go @@ -8,7 +8,7 @@ import ( ) func TestClient_GetDNSServer(t *testing.T) { - out := `{"test":[{"createdDate":"2020-02-06 15:28:07","createdBy":"William Fleming (wfleming@grumpysysadm.com)","numPathTraces":3,"pathTraceMode": "classic", "enabled":1,"savedEvent":0,"testId":122621,"testName":"test123","type":"dns-server","interval":300,"protocol":"UDP","networkMeasurements":1,"mtuMeasurements":1,"bandwidthMeasurements":0,"bgpMeasurements":1,"usePublicBGP":1,"alertsEnabled":1,"liveShare":0,"probeMode":"AUTO","agents":[{"agentId":48620,"agentName":"Seattle, WA (Trial) - IPv6","agentType":"Cloud","countryId":"US","ipAddresses":["135.84.184.153"],"location":"Seattle Area","network":"Astute Hosting Inc. (AS 54527)","prefix":"135.84.184.0/22"}],"sharedWithAccounts":[{"aid":176592,"name":"Cloudreach"}],"bgpMonitors":[{"monitorId":64,"ipAddress":"2001:240:100:ff::2497:2","countryId":"JP","monitorName":"Tokyo-3","network":"IIJ Internet Initiative Japan Inc. (AS 2497)","monitorType":"Public"}],"numPathTraces":3,"domain": "webex.com","dnsTransportProtocol": "UDP", "dnsServers" : [{"serverId": 123,"serverName":"1.1.1.1"}],"apiLinks":[{"rel":"self","href":"https://api.thousandeyes.com/v6/tests/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/web/dns-server/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/metrics/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/path-vis/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"}]}]}` + out := `{"test":[{"createdDate":"2020-02-06 15:28:07","createdBy":"William Fleming (wfleming@grumpysysadm.com)","numPathTraces":3,"pathTraceMode": "classic", "enabled":1,"savedEvent":0,"testId":122621,"testName":"test123","type":"dns-server","interval":300,"protocol":"UDP","networkMeasurements":1,"mtuMeasurements":1,"bandwidthMeasurements":0,"bgpMeasurements":1,"usePublicBGP":1,"alertsEnabled":1,"liveShare":0,"probeMode":"AUTO","recursiveQueries":0,"agents":[{"agentId":48620,"agentName":"Seattle, WA (Trial) - IPv6","agentType":"Cloud","countryId":"US","ipAddresses":["135.84.184.153"],"location":"Seattle Area","network":"Astute Hosting Inc. (AS 54527)","prefix":"135.84.184.0/22"}],"sharedWithAccounts":[{"aid":176592,"name":"Cloudreach"}],"bgpMonitors":[{"monitorId":64,"ipAddress":"2001:240:100:ff::2497:2","countryId":"JP","monitorName":"Tokyo-3","network":"IIJ Internet Initiative Japan Inc. (AS 2497)","monitorType":"Public"}],"numPathTraces":3,"domain": "webex.com","dnsTransportProtocol": "UDP", "dnsServers" : [{"serverId": 123,"serverName":"1.1.1.1"}],"apiLinks":[{"rel":"self","href":"https://api.thousandeyes.com/v6/tests/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/web/dns-server/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/metrics/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/path-vis/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"}]}]}` setup() var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} mux.HandleFunc("/tests/122621.json", func(w http.ResponseWriter, r *http.Request) { @@ -19,80 +19,81 @@ func TestClient_GetDNSServer(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := DNSServer{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "dns-server", - Interval: 300, - Protocol: "UDP", - NetworkMeasurements: 1, - MTUMeasurements: 1, - BandwidthMeasurements: 0, - NumPathTraces: 3, - PathTraceMode: "classic", - AlertsEnabled: 1, - RecursiveQueries: 0, - BGPMeasurements: 1, - UsePublicBGP: 1, - Domain: "webex.com", - ProbeMode: "AUTO", - DNSTransportProtocol: "UDP", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + TestName: String("test123"), + Type: String("dns-server"), + Interval: Int(300), + LiveShare: Int(0), + Protocol: String("UDP"), + NetworkMeasurements: Int(1), + MTUMeasurements: Int(1), + BandwidthMeasurements: Int(0), + NumPathTraces: Int(3), + PathTraceMode: String("classic"), + AlertsEnabled: Int(1), + RecursiveQueries: Int(0), + BGPMeasurements: Int(1), + UsePublicBGP: Int(1), + Domain: String("webex.com"), + ProbeMode: String("AUTO"), + DNSTransportProtocol: String("UDP"), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, DNSServers: []Server{ { - ServerID: 123, - ServerName: "1.1.1.1", + ServerID: Int(123), + ServerName: String("1.1.1.1"), }, }, BGPMonitors: []BGPMonitor{ { - MonitorID: 64, - IPAddress: "2001:240:100:ff::2497:2", - MonitorName: "Tokyo-3", - Network: "IIJ Internet Initiative Japan Inc. (AS 2497)", - MonitorType: "Public", + MonitorID: Int(64), + IPAddress: String("2001:240:100:ff::2497:2"), + MonitorName: String("Tokyo-3"), + Network: String("IIJ Internet Initiative Japan Inc. (AS 2497)"), + MonitorType: String("Public"), }, }, APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/dns-server/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/dns-server/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } @@ -104,8 +105,8 @@ func TestClient_GetDNSServer(t *testing.T) { } func TestClient_AddDnsserverAlertRule(t *testing.T) { - test := DNSServer{TestName: "test", AlertRules: []AlertRule{}} - expected := DNSServer{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} + test := DNSServer{TestName: String("test"), AlertRules: []AlertRule{}} + expected := DNSServer{TestName: String("test"), AlertRules: []AlertRule{{RuleID: Int(1)}}} test.AddAlertRule(1) assert.Equal(t, expected, test) } @@ -124,7 +125,7 @@ func TestClient_GetDNSServerJsonError(t *testing.T) { } func TestClient_CreateDNSServer(t *testing.T) { - out := `{"test":[{"createdDate":"2020-02-06 15:28:07","createdBy":"William Fleming (wfleming@grumpysysadm.com)","numPathTraces": 3,"enabled":1,"savedEvent":0,"testId":122621,"testName":"test123","type":"dns-server","interval":300,"protocol":"UDP","networkMeasurements":1,"mtuMeasurements":1,"bandwidthMeasurements":0,"bgpMeasurements":1,"usePublicBGP":1,"alertsEnabled":1,"liveShare":0,"probeMode":"AUTO","agents":[{"agentId":48620,"agentName":"Seattle, WA (Trial) - IPv6","agentType":"Cloud","countryId":"US","ipAddresses":["135.84.184.153"],"location":"Seattle Area","network":"Astute Hosting Inc. (AS 54527)","prefix":"135.84.184.0/22"}],"sharedWithAccounts":[{"aid":176592,"name":"Cloudreach"}],"bgpMonitors":[{"monitorId":64,"ipAddress":"2001:240:100:ff::2497:2","countryId":"JP","monitorName":"Tokyo-3","network":"IIJ Internet Initiative Japan Inc. (AS 2497)","monitorType":"Public"}],"numPathTraces":3,"domain": "webex.com","dnsTransportProtocol": "UDP", "dnsServers" : [{"serverId": 123,"serverName":"1.1.1.1"}],"apiLinks":[{"rel":"self","href":"https://api.thousandeyes.com/v6/tests/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/web/dns-server/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/metrics/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/path-vis/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"}]}]}` + out := `{"test":[{"createdDate":"2020-02-06 15:28:07","createdBy":"William Fleming (wfleming@grumpysysadm.com)","numPathTraces": 3,"enabled":1,"savedEvent":0,"testId":122621,"testName":"test123","type":"dns-server","interval":300,"protocol":"UDP","networkMeasurements":1,"mtuMeasurements":1,"bandwidthMeasurements":0,"bgpMeasurements":1,"usePublicBGP":1,"alertsEnabled":1,"liveShare":0,"probeMode":"AUTO","recursiveQueries":0,"agents":[{"agentId":48620,"agentName":"Seattle, WA (Trial) - IPv6","agentType":"Cloud","countryId":"US","ipAddresses":["135.84.184.153"],"location":"Seattle Area","network":"Astute Hosting Inc. (AS 54527)","prefix":"135.84.184.0/22"}],"sharedWithAccounts":[{"aid":176592,"name":"Cloudreach"}],"bgpMonitors":[{"monitorId":64,"ipAddress":"2001:240:100:ff::2497:2","countryId":"JP","monitorName":"Tokyo-3","network":"IIJ Internet Initiative Japan Inc. (AS 2497)","monitorType":"Public"}],"numPathTraces":3,"domain": "webex.com","dnsTransportProtocol": "UDP", "dnsServers" : [{"serverId": 123,"serverName":"1.1.1.1"}],"apiLinks":[{"rel":"self","href":"https://api.thousandeyes.com/v6/tests/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/web/dns-server/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/metrics/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/path-vis/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"}]}]}` setup() var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} mux.HandleFunc("/tests/dns-server/new.json", func(w http.ResponseWriter, r *http.Request) { @@ -137,87 +138,88 @@ func TestClient_CreateDNSServer(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := DNSServer{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "dns-server", - Interval: 300, - Protocol: "UDP", - NetworkMeasurements: 1, - MTUMeasurements: 1, - BandwidthMeasurements: 0, - NumPathTraces: 3, - RecursiveQueries: 0, - AlertsEnabled: 1, - BGPMeasurements: 1, - UsePublicBGP: 1, - Domain: "webex.com", - ProbeMode: "AUTO", - DNSTransportProtocol: "UDP", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + TestName: String("test123"), + Type: String("dns-server"), + Interval: Int(300), + LiveShare: Int(0), + Protocol: String("UDP"), + NetworkMeasurements: Int(1), + MTUMeasurements: Int(1), + BandwidthMeasurements: Int(0), + NumPathTraces: Int(3), + RecursiveQueries: Int(0), + AlertsEnabled: Int(1), + BGPMeasurements: Int(1), + UsePublicBGP: Int(1), + Domain: String("webex.com"), + ProbeMode: String("AUTO"), + DNSTransportProtocol: String("UDP"), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, DNSServers: []Server{ { - ServerID: 123, - ServerName: "1.1.1.1", + ServerID: Int(123), + ServerName: String("1.1.1.1"), }, }, BGPMonitors: []BGPMonitor{ { - MonitorID: 64, - IPAddress: "2001:240:100:ff::2497:2", - MonitorName: "Tokyo-3", - Network: "IIJ Internet Initiative Japan Inc. (AS 2497)", - MonitorType: "Public", + MonitorID: Int(64), + IPAddress: String("2001:240:100:ff::2497:2"), + MonitorName: String("Tokyo-3"), + Network: String("IIJ Internet Initiative Japan Inc. (AS 2497)"), + MonitorType: String("Public"), }, }, APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/dns-server/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/dns-server/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } create := DNSServer{ - TestName: "test1", - Domain: "1.1.1.1", - Interval: 300, - NumPathTraces: 3, + TestName: String("test1"), + Domain: String("1.1.1.1"), + Interval: Int(300), + NumPathTraces: Int(3), } res, err := client.CreateDNSServer(create) teardown() @@ -252,19 +254,19 @@ func TestClient_UpdateDNSServer(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 1 - dnsS := DNSServer{Domain: "webex.com"} + dnsS := DNSServer{Domain: String("webex.com")} res, err := client.UpdateDNSServer(id, dnsS) if err != nil { t.Fatal(err) } - expected := DNSServer{TestID: 1, TestName: "test123", Type: "dns-server", Domain: "webex.com"} + expected := DNSServer{TestID: Int64(1), TestName: String("test123"), Type: String("dns-server"), Domain: String("webex.com")} assert.Equal(t, &expected, res) } func TestDNSServer_AddAgent(t *testing.T) { - test := DNSServer{TestName: "test", Agents: Agents{}} - expected := DNSServer{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := DNSServer{TestName: String("test"), Agents: Agents{}} + expected := DNSServer{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } @@ -294,7 +296,7 @@ func TestClient_GetDNSServerStatusCode(t *testing.T) { _, err := client.GetDNSServer(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateDNSServerStatusCode(t *testing.T) { @@ -307,7 +309,7 @@ func TestClient_CreateDNSServerStatusCode(t *testing.T) { }) _, err := client.CreateDNSServer(DNSServer{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateDNSServerStatusCode(t *testing.T) { @@ -320,7 +322,7 @@ func TestClient_UpdateDNSServerStatusCode(t *testing.T) { }) _, err := client.UpdateDNSServer(1, DNSServer{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteDNSServerStatusCode(t *testing.T) { @@ -333,5 +335,5 @@ func TestClient_DeleteDNSServerStatusCode(t *testing.T) { }) err := client.DeleteDNSServer(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/dns_trace.go b/dns_trace.go index a41cf22..edeed5c 100644 --- a/dns_trace.go +++ b/dns_trace.go @@ -7,39 +7,39 @@ import ( // DNSTrace - DNS trace test type DNSTrace struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents []Agent `json:"agents,omitempty"` - DNSTransportProtocol string `json:"dnsTransportProtocol,omitempty"` - Domain string `json:"domain,omitempty"` - Interval int `json:"interval,omitempty"` + DNSTransportProtocol *string `json:"dnsTransportProtocol,omitempty"` + Domain *string `json:"domain,omitempty"` + Interval *int `json:"interval,omitempty"` } // AddAgent - Add agent to DNS Trace test func (t *DNSTrace) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } // AddAlertRule - Adds an alert to agent test func (t *DNSTrace) AddAlertRule(id int) { - alertRule := AlertRule{RuleID: id} + alertRule := AlertRule{RuleID: Int(id)} t.AlertRules = append(t.AlertRules, alertRule) } diff --git a/dns_trace_test.go b/dns_trace_test.go index 3762914..3afe1dd 100644 --- a/dns_trace_test.go +++ b/dns_trace_test.go @@ -18,55 +18,56 @@ func TestClient_GetDNSTrace(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := DNSTrace{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - AlertsEnabled: 1, - TestName: "test123", - Type: "dns-trace", - Interval: 300, - Domain: "webex.com", - DNSTransportProtocol: "UDP", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + AlertsEnabled: Int(1), + TestName: String("test123"), + Type: String("dns-trace"), + Interval: Int(300), + LiveShare: Int(0), + Domain: String("webex.com"), + DNSTransportProtocol: String("UDP"), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/dns-trace/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/dns-trace/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } @@ -104,63 +105,64 @@ func TestClient_CreateDNSTrace(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := DNSTrace{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "dns-trace", - Interval: 300, - AlertsEnabled: 1, - Domain: "webex.com", - DNSTransportProtocol: "UDP", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + TestName: String("test123"), + Type: String("dns-trace"), + Interval: Int(300), + AlertsEnabled: Int(1), + LiveShare: Int(0), + Domain: String("webex.com"), + DNSTransportProtocol: String("UDP"), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/dns-trace/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/dns-trace/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } create := DNSTrace{ - TestName: "test1", - Domain: "1.1.1.1", - Interval: 300, + TestName: String("test1"), + Domain: String("1.1.1.1"), + Interval: Int(300), } res, err := client.CreateDNSTrace(create) teardown() @@ -186,8 +188,8 @@ func TestClient_DeleteDNSTrace(t *testing.T) { } func TestClient_AddDnstraceAlertRule(t *testing.T) { - test := DNSTrace{TestName: "test", AlertRules: []AlertRule{}} - expected := DNSTrace{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} + test := DNSTrace{TestName: String("test"), AlertRules: []AlertRule{}} + expected := DNSTrace{TestName: String("test"), AlertRules: []AlertRule{{RuleID: Int(1)}}} test.AddAlertRule(1) assert.Equal(t, expected, test) } @@ -202,19 +204,19 @@ func TestClient_UpdateDNSTrace(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 1 - dnsS := DNSTrace{Domain: "webex.com"} + dnsS := DNSTrace{Domain: String("webex.com")} res, err := client.UpdateDNSTrace(id, dnsS) if err != nil { t.Fatal(err) } - expected := DNSTrace{TestID: 1, TestName: "test123", Type: "dns-trace", Domain: "webex.com"} + expected := DNSTrace{TestID: Int64(1), TestName: String("test123"), Type: String("dns-trace"), Domain: String("webex.com")} assert.Equal(t, &expected, res) } func TestDNSTrace_AddAgent(t *testing.T) { - test := DNSTrace{TestName: "test", Agents: Agents{}} - expected := DNSTrace{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := DNSTrace{TestName: String("test"), Agents: Agents{}} + expected := DNSTrace{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } @@ -244,7 +246,7 @@ func TestClient_GetDNSTraceStatusCode(t *testing.T) { _, err := client.GetDNSTrace(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateDNSTraceStatusCode(t *testing.T) { @@ -257,7 +259,7 @@ func TestClient_CreateDNSTraceStatusCode(t *testing.T) { }) _, err := client.CreateDNSTrace(DNSTrace{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateDNSTraceStatusCode(t *testing.T) { @@ -270,7 +272,7 @@ func TestClient_UpdateDNSTraceStatusCode(t *testing.T) { }) _, err := client.UpdateDNSTrace(1, DNSTrace{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteDNSTraceStatusCode(t *testing.T) { @@ -283,5 +285,5 @@ func TestClient_DeleteDNSTraceStatusCode(t *testing.T) { }) err := client.DeleteDNSTrace(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/dnsp_domain.go b/dnsp_domain.go deleted file mode 100644 index 92dc737..0000000 --- a/dnsp_domain.go +++ /dev/null @@ -1,89 +0,0 @@ -package thousandeyes - -import "fmt" - -// DNSPDomain - DNSP domain test -type DNSPDomain struct { - // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` - APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` - Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` - SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // Fields unique to this test - Domain string `json:"domain,omitempty"` - Interval int `json:"interval,omitempty"` -} - -// AddAlertRule - Adds an alert to agent test -func (t *DNSPDomain) AddAlertRule(id int) { - alertRule := AlertRule{RuleID: id} - t.AlertRules = append(t.AlertRules, alertRule) -} - -// GetDNSPDomain - get dnsp domain test -func (c *Client) GetDNSPDomain(id int) (*DNSPDomain, error) { - resp, err := c.get(fmt.Sprintf("/tests/%d", id)) - if err != nil { - return &DNSPDomain{}, err - } - var target map[string][]DNSPDomain - if dErr := c.decodeJSON(resp, &target); dErr != nil { - return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) - } - return &target["test"][0], nil -} - -// CreateDNSPDomain - Create dnsp domain test -func (c Client) CreateDNSPDomain(t DNSPDomain) (*DNSPDomain, error) { - resp, err := c.post("/tests/dnsp-domain/new", t, nil) - if err != nil { - return &t, err - } - if resp.StatusCode != 201 { - return &t, fmt.Errorf("failed to dnsp domain create test, response code %d", resp.StatusCode) - } - var target map[string][]DNSPDomain - if dErr := c.decodeJSON(resp, &target); dErr != nil { - return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) - } - return &target["test"][0], nil -} - -//DeleteDNSPDomain - delete dnsp domain test -func (c *Client) DeleteDNSPDomain(id int) error { - resp, err := c.post(fmt.Sprintf("/tests/dnsp-domain/%d/delete", id), nil, nil) - if err != nil { - return err - } - if resp.StatusCode != 204 { - return fmt.Errorf("failed to delete dnsp domain test, response code %d", resp.StatusCode) - } - return nil -} - -//UpdateDNSPDomain - update dnsp domain test -func (c *Client) UpdateDNSPDomain(id int, t DNSPDomain) (*DNSPDomain, error) { - resp, err := c.post(fmt.Sprintf("/tests/dnsp-domain/%d/update", id), t, nil) - if err != nil { - return &t, err - } - if resp.StatusCode != 200 { - return &t, fmt.Errorf("failed to update test, response code %d", resp.StatusCode) - } - var target map[string][]DNSPDomain - if dErr := c.decodeJSON(resp, &target); dErr != nil { - return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) - } - return &target["test"][0], nil -} diff --git a/dnsp_domain_test.go b/dnsp_domain_test.go deleted file mode 100644 index d8ef224..0000000 --- a/dnsp_domain_test.go +++ /dev/null @@ -1,249 +0,0 @@ -package thousandeyes - -import ( - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestClient_GetDNSPDomain(t *testing.T) { - out := `{"test":[{"createdDate":"2020-02-06 15:28:07","createdBy":"William Fleming (wfleming@grumpysysadm.com)","enabled":1,"savedEvent":0,"testId":122621,"testName":"test123","type":"dnsp-domain","interval":300,"alertsEnabled":1,"liveShare":0,"agents":[{"agentId":48620,"agentName":"Seattle, WA (Trial) - IPv6","agentType":"Cloud","countryId":"US","ipAddresses":["135.84.184.153"],"location":"Seattle Area","network":"Astute Hosting Inc. (AS 54527)","prefix":"135.84.184.0/22"}],"sharedWithAccounts":[{"aid":176592,"name":"Cloudreach"}],"domain": "webex.com","dnsTransportProtocol": "UDP","apiLinks":[{"rel":"self","href":"https://api.thousandeyes.com/v6/tests/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/web/dnsp-domain/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/metrics/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/path-vis/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"}]}]}` - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/122621.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "GET", r.Method) - _, _ = w.Write([]byte(out)) - }) - - expected := DNSPDomain{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - AlertsEnabled: 1, - TestName: "test123", - Type: "dnsp-domain", - Interval: 300, - Domain: "webex.com", - SharedWithAccounts: []SharedWithAccount{ - { - AID: 176592, - AccountGroupName: "Cloudreach", - }, - }, - APILinks: APILinks{ - { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", - }, - { - Href: "https://api.thousandeyes.com/v6/web/dnsp-domain/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", - }, - }, - } - - res, err := client.GetDNSPDomain(122621) - teardown() - assert.Nil(t, err) - assert.Equal(t, &expected, res) -} - -func TestClient_GetDNSPDomainJsonError(t *testing.T) { - out := `{"test":[{"createdDate":"2020-02-06 15:28:07",createdBy":"William Fleming (wfleming@grumpysysadm.com)","enabled":1,"savedEvent":0,"testId":122621,"testName":"test123","type":"dnsp-domain","interval":300,"alertsEnabled":1,"liveShare":0,"probeMode":"AUTO","agents":[{"agentId":48620,"agentName":"Seattle, WA (Trial) - IPv6","agentType":"Cloud","countryId":"US","ipAddresses":["135.84.184.153"],"location":"Seattle Area","network":"Astute Hosting Inc. (AS 54527)","prefix":"135.84.184.0/22"}],"sharedWithAccounts":[{"aid":176592,"name":"Cloudreach"}],"domain": "webex.com","dnsTransportProtocol": "UDP"}]"apiLinks":[{"rel":"self","href":"https://api.thousandeyes.com/v6/tests/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/web/dnsp-domain/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/metrics/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/path-vis/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"}]}]}` - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/122621.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "GET", r.Method) - _, _ = w.Write([]byte(out)) - }) - _, err := client.GetDNSPDomain(122621) - assert.Error(t, err) - assert.EqualError(t, err, "Could not decode JSON response: invalid character 'c' looking for beginning of object key string") -} - -func TestClient_CreateDNSPDomain(t *testing.T) { - out := `{"test":[{"createdDate":"2020-02-06 15:28:07","createdBy":"William Fleming (wfleming@grumpysysadm.com)","enabled":1,"savedEvent":0,"testId":122621,"testName":"test123","type":"dnsp-domain","interval":300,"alertsEnabled":1,"liveShare":0,"agents":[{"agentId":48620,"agentName":"Seattle, WA (Trial) - IPv6","agentType":"Cloud","countryId":"US","ipAddresses":["135.84.184.153"],"location":"Seattle Area","network":"Astute Hosting Inc. (AS 54527)","prefix":"135.84.184.0/22"}],"sharedWithAccounts":[{"aid":176592,"name":"Cloudreach"}],"domain": "webex.com","apiLinks":[{"rel":"self","href":"https://api.thousandeyes.com/v6/tests/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/web/dnsp-domain/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/metrics/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/path-vis/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"}]}]}` - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/dnsp-domain/new.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "POST", r.Method) - w.WriteHeader(http.StatusCreated) - _, _ = w.Write([]byte(out)) - }) - - expected := DNSPDomain{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "dnsp-domain", - Interval: 300, - AlertsEnabled: 1, - Domain: "webex.com", - SharedWithAccounts: []SharedWithAccount{ - { - AID: 176592, - AccountGroupName: "Cloudreach", - }, - }, - - APILinks: APILinks{ - { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", - }, - { - Href: "https://api.thousandeyes.com/v6/web/dnsp-domain/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", - }, - }, - } - create := DNSPDomain{ - TestName: "test123", - Domain: "webex.com", - Interval: 300, - } - res, err := client.CreateDNSPDomain(create) - teardown() - assert.Nil(t, err) - assert.Equal(t, &expected, res) -} - -func TestClient_DeleteDNSPDomain(t *testing.T) { - setup() - mux.HandleFunc("/tests/dnsp-domain/1/delete.json", func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusNoContent) - assert.Equal(t, "POST", r.Method) - }) - - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - id := 1 - err := client.DeleteDNSPDomain(id) - - if err != nil { - t.Fatal(err) - } -} - -func TestClient_AddDNSPDomainAlertRule(t *testing.T) { - test := DNSPDomain{TestName: "test", AlertRules: []AlertRule{}} - expected := DNSPDomain{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} - test.AddAlertRule(1) - assert.Equal(t, expected, test) -} - -func TestClient_UpdateDNSPDomain(t *testing.T) { - setup() - out := `{"test":[{"testId":1,"testName":"test123","type":"dnsp-domain","domain":"webex.com" }]}` - mux.HandleFunc("/tests/dnsp-domain/1/update.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "POST", r.Method) - _, _ = w.Write([]byte(out)) - }) - - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - id := 1 - dnsp := DNSPDomain{Domain: "webex.com"} - res, err := client.UpdateDNSPDomain(id, dnsp) - if err != nil { - t.Fatal(err) - } - expected := DNSPDomain{TestID: 1, TestName: "test123", Type: "dnsp-domain", Domain: "webex.com"} - assert.Equal(t, &expected, res) - -} - -func TestClient_GetDNSPDomainError(t *testing.T) { - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/dnsp-domain/1.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "GET", r.Method) - w.WriteHeader(http.StatusBadRequest) - }) - - _, err := client.GetDNSPDomain(1) - teardown() - assert.Error(t, err) -} - -func TestClient_GetDNSPDomainStatusCode(t *testing.T) { - setup() - out := `{"test":[{"testId":1,"testName":"test123","type":"dnsp-trace"}]}` - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/1.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "GET", r.Method) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(out)) - }) - - _, err := client.GetDNSPDomain(1) - teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") -} - -func TestClient_CreateDNSPDomainStatusCode(t *testing.T) { - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/dnsp-domain/new.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "POST", r.Method) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{}`)) - }) - _, err := client.CreateDNSPDomain(DNSPDomain{}) - teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") -} - -func TestClient_UpdateDNSPDomainStatusCode(t *testing.T) { - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/dnsp-domain/1/update.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "POST", r.Method) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{}`)) - }) - _, err := client.UpdateDNSPDomain(1, DNSPDomain{}) - teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") -} - -func TestClient_DeleteDNSPDomainStatusCode(t *testing.T) { - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/dnsp-domain/1/delete.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "POST", r.Method) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{}`)) - }) - err := client.DeleteDNSPDomain(1) - teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") -} diff --git a/dnsp_server.go b/dnsp_server.go deleted file mode 100644 index 7e1adb8..0000000 --- a/dnsp_server.go +++ /dev/null @@ -1,89 +0,0 @@ -package thousandeyes - -import "fmt" - -// DNSPServer - DNSP server test -type DNSPServer struct { - // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` - APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` - Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` - SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // Fields unique to this test - Interval int `json:"interval,omitempty"` - Server string `json:"server,omitempty"` -} - -// AddAlertRule - Adds an alert to agent test -func (t *DNSPServer) AddAlertRule(id int) { - alertRule := AlertRule{RuleID: id} - t.AlertRules = append(t.AlertRules, alertRule) -} - -// GetDNSPServer - get dnsp server test -func (c *Client) GetDNSPServer(id int) (*DNSPServer, error) { - resp, err := c.get(fmt.Sprintf("/tests/%d", id)) - if err != nil { - return &DNSPServer{}, err - } - var target map[string][]DNSPServer - if dErr := c.decodeJSON(resp, &target); dErr != nil { - return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) - } - return &target["test"][0], nil -} - -// CreateDNSPServer - Create dnsp server test -func (c Client) CreateDNSPServer(t DNSPServer) (*DNSPServer, error) { - resp, err := c.post("/tests/dnsp-server/new", t, nil) - if err != nil { - return &t, err - } - if resp.StatusCode != 201 { - return &t, fmt.Errorf("failed to dnsp server create test, response code %d", resp.StatusCode) - } - var target map[string][]DNSPServer - if dErr := c.decodeJSON(resp, &target); dErr != nil { - return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) - } - return &target["test"][0], nil -} - -//DeleteDNSPServer - delete dnsp server test -func (c *Client) DeleteDNSPServer(id int) error { - resp, err := c.post(fmt.Sprintf("/tests/dnsp-server/%d/delete", id), nil, nil) - if err != nil { - return err - } - if resp.StatusCode != 204 { - return fmt.Errorf("failed to delete dnsp server test, response code %d", resp.StatusCode) - } - return nil -} - -//UpdateDNSPServer - update dnsp server test -func (c *Client) UpdateDNSPServer(id int, t DNSPServer) (*DNSPServer, error) { - resp, err := c.post(fmt.Sprintf("/tests/dnsp-server/%d/update", id), t, nil) - if err != nil { - return &t, err - } - if resp.StatusCode != 200 { - return &t, fmt.Errorf("failed to update test, response code %d", resp.StatusCode) - } - var target map[string][]DNSPServer - if dErr := c.decodeJSON(resp, &target); dErr != nil { - return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) - } - return &target["test"][0], nil -} diff --git a/dnsp_server_test.go b/dnsp_server_test.go deleted file mode 100644 index 69f641b..0000000 --- a/dnsp_server_test.go +++ /dev/null @@ -1,249 +0,0 @@ -package thousandeyes - -import ( - "net/http" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestClient_GetDNSPServer(t *testing.T) { - out := `{"test":[{"createdDate":"2020-02-06 15:28:07","createdBy":"William Fleming (wfleming@grumpysysadm.com)","enabled":1,"savedEvent":0,"testId":122621,"testName":"test123","type":"dnsp-server","interval":300,"alertsEnabled":1,"liveShare":0,"agents":[{"agentId":48620,"agentName":"Seattle, WA (Trial) - IPv6","agentType":"Cloud","countryId":"US","ipAddresses":["135.84.184.153"],"location":"Seattle Area","network":"Astute Hosting Inc. (AS 54527)","prefix":"135.84.184.0/22"}],"sharedWithAccounts":[{"aid":176592,"name":"Cloudreach"}],"server": "webex.com","apiLinks":[{"rel":"self","href":"https://api.thousandeyes.com/v6/tests/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/web/dnsp-server/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/metrics/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/path-vis/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"}]}]}` - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/122621.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "GET", r.Method) - _, _ = w.Write([]byte(out)) - }) - - expected := DNSPServer{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - AlertsEnabled: 1, - TestName: "test123", - Type: "dnsp-server", - Interval: 300, - Server: "webex.com", - SharedWithAccounts: []SharedWithAccount{ - { - AID: 176592, - AccountGroupName: "Cloudreach", - }, - }, - APILinks: APILinks{ - { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", - }, - { - Href: "https://api.thousandeyes.com/v6/web/dnsp-server/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", - }, - }, - } - - res, err := client.GetDNSPServer(122621) - teardown() - assert.Nil(t, err) - assert.Equal(t, &expected, res) -} - -func TestClient_GetDNSPServerJsonError(t *testing.T) { - out := `{"test":[{"createdDate":"2020-02-06 15:28:07",createdBy":"William Fleming (wfleming@grumpysysadm.com)","enabled":1,"savedEvent":0,"testId":122621,"testName":"test123","type":"dnsp-server","interval":300,"alertsEnabled":1,"liveShare":0,"probeMode":"AUTO","agents":[{"agentId":48620,"agentName":"Seattle, WA (Trial) - IPv6","agentType":"Cloud","countryId":"US","ipAddresses":["135.84.184.153"],"location":"Seattle Area","network":"Astute Hosting Inc. (AS 54527)","prefix":"135.84.184.0/22"}],"sharedWithAccounts":[{"aid":176592,"name":"Cloudreach"}],"server": "webex.com","dnsTransportProtocol": "UDP"}]"apiLinks":[{"rel":"self","href":"https://api.thousandeyes.com/v6/tests/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/web/dnsp-server/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/metrics/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/path-vis/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"}]}]}` - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/122621.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "GET", r.Method) - _, _ = w.Write([]byte(out)) - }) - _, err := client.GetDNSPServer(122621) - assert.Error(t, err) - assert.EqualError(t, err, "Could not decode JSON response: invalid character 'c' looking for beginning of object key string") -} - -func TestClient_CreateDNSPServer(t *testing.T) { - out := `{"test":[{"createdDate":"2020-02-06 15:28:07","createdBy":"William Fleming (wfleming@grumpysysadm.com)","enabled":1,"savedEvent":0,"testId":122621,"testName":"test123","type":"dnsp-server","interval":300,"alertsEnabled":1,"liveShare":0,"agents":[{"agentId":48620,"agentName":"Seattle, WA (Trial) - IPv6","agentType":"Cloud","countryId":"US","ipAddresses":["135.84.184.153"],"location":"Seattle Area","network":"Astute Hosting Inc. (AS 54527)","prefix":"135.84.184.0/22"}],"sharedWithAccounts":[{"aid":176592,"name":"Cloudreach"}],"server": "webex.com","apiLinks":[{"rel":"self","href":"https://api.thousandeyes.com/v6/tests/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/web/dnsp-server/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/metrics/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/path-vis/1226221"},{"rel":"data","href":"https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"}]}]}` - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/dnsp-server/new.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "POST", r.Method) - w.WriteHeader(http.StatusCreated) - _, _ = w.Write([]byte(out)) - }) - - expected := DNSPServer{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "dnsp-server", - Interval: 300, - AlertsEnabled: 1, - Server: "webex.com", - SharedWithAccounts: []SharedWithAccount{ - { - AID: 176592, - AccountGroupName: "Cloudreach", - }, - }, - - APILinks: APILinks{ - { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", - }, - { - Href: "https://api.thousandeyes.com/v6/web/dnsp-server/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", - }, - { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", - }, - }, - } - create := DNSPServer{ - TestName: "test123", - Server: "webex.com", - Interval: 300, - } - res, err := client.CreateDNSPServer(create) - teardown() - assert.Nil(t, err) - assert.Equal(t, &expected, res) -} - -func TestClient_DeleteDNSPServer(t *testing.T) { - setup() - mux.HandleFunc("/tests/dnsp-server/1/delete.json", func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusNoContent) - assert.Equal(t, "POST", r.Method) - }) - - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - id := 1 - err := client.DeleteDNSPServer(id) - - if err != nil { - t.Fatal(err) - } -} - -func TestClient_AddDNSPServerAlertRule(t *testing.T) { - test := DNSPServer{TestName: "test", AlertRules: []AlertRule{}} - expected := DNSPServer{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} - test.AddAlertRule(1) - assert.Equal(t, expected, test) -} - -func TestClient_UpdateDNSPServer(t *testing.T) { - setup() - out := `{"test":[{"testId":1,"testName":"test123","type":"dnsp-server","server":"webex.com" }]}` - mux.HandleFunc("/tests/dnsp-server/1/update.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "POST", r.Method) - _, _ = w.Write([]byte(out)) - }) - - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - id := 1 - dnsp := DNSPServer{Server: "webex.com"} - res, err := client.UpdateDNSPServer(id, dnsp) - if err != nil { - t.Fatal(err) - } - expected := DNSPServer{TestID: 1, TestName: "test123", Type: "dnsp-server", Server: "webex.com"} - assert.Equal(t, &expected, res) - -} - -func TestClient_GetDNSPServerError(t *testing.T) { - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/dnsp-server/1.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "GET", r.Method) - w.WriteHeader(http.StatusBadRequest) - }) - - _, err := client.GetDNSPServer(1) - teardown() - assert.Error(t, err) -} - -func TestClient_GetDNSPServernStatusCode(t *testing.T) { - setup() - out := `{"test":[{"testId":1,"testName":"test123","type":"dnsp-trace"}]}` - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/1.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "GET", r.Method) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(out)) - }) - - _, err := client.GetDNSPServer(1) - teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") -} - -func TestClient_CreateDNSPServerStatusCode(t *testing.T) { - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/dnsp-server/new.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "POST", r.Method) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{}`)) - }) - _, err := client.CreateDNSPServer(DNSPServer{}) - teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") -} - -func TestClient_UpdateDNSPServerStatusCode(t *testing.T) { - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/dnsp-server/1/update.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "POST", r.Method) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{}`)) - }) - _, err := client.UpdateDNSPServer(1, DNSPServer{}) - teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") -} - -func TestClient_DeleteDNSPServerStatusCode(t *testing.T) { - setup() - var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - mux.HandleFunc("/tests/dnsp-server/1/delete.json", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, "POST", r.Method) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{}`)) - }) - err := client.DeleteDNSPServer(1) - teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") -} diff --git a/ftp_server.go b/ftp_server.go index 7457e57..46292ab 100644 --- a/ftp_server.go +++ b/ftp_server.go @@ -5,53 +5,53 @@ import "fmt" // FTPServer - ftp server test type FTPServer struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveSVhare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents []Agent `json:"agents,omitempty"` - BGPMeasurements int `json:"bgpMeasurements,omitempty"` - DownloadLimit int `json:"downloadLimit,omitempty"` - FTPTargetTime int `json:"ftpTargetTime,omitempty"` - FTPTimeLimit int `json:"ftpTimeLimit,omitempty"` - Interval int `json:"interval,omitempty"` - MTUMeasurements int `json:"mtuMeasurements,omitempty"` - NetworkMeasurements int `json:"networkMeasurements,omitempty"` - NumPathTraces int `json:"numPathTraces,omitempty"` - Password string `json:"password,omitempty"` - PathTraceMode string `json:"pathTraceMode,omitempty"` - ProbeMode string `json:"probeMode,omitempty"` - Protocol string `json:"protocol,omitempty"` - RequestType string `json:"requestType,omitempty"` - URL string `json:"url,omitempty"` - UseActiveFTP int `json:"useActiveFtp,omitempty"` - UseExplicitFTPS int `json:"useExplicitFtps,omitempty"` - Username string `json:"username,omitempty"` + BGPMeasurements *int `json:"bgpMeasurements,omitempty"` + DownloadLimit *int `json:"downloadLimit,omitempty"` + FTPTargetTime *int `json:"ftpTargetTime,omitempty"` + FTPTimeLimit *int `json:"ftpTimeLimit,omitempty"` + Interval *int `json:"interval,omitempty"` + MTUMeasurements *int `json:"mtuMeasurements,omitempty"` + NetworkMeasurements *int `json:"networkMeasurements,omitempty"` + NumPathTraces *int `json:"numPathTraces,omitempty"` + Password *string `json:"password,omitempty"` + PathTraceMode *string `json:"pathTraceMode,omitempty"` + ProbeMode *string `json:"probeMode,omitempty"` + Protocol *string `json:"protocol,omitempty"` + RequestType *string `json:"requestType,omitempty"` + URL *string `json:"url,omitempty"` + UseActiveFTP *int `json:"useActiveFtp,omitempty"` + UseExplicitFTPS *int `json:"useExplicitFtps,omitempty"` + Username *string `json:"username,omitempty"` } // AddAgent - Add ftp server test func (t *FTPServer) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } // AddAlertRule - Adds an alert to agent test func (t *FTPServer) AddAlertRule(id int) { - alertRule := AlertRule{RuleID: id} + alertRule := AlertRule{RuleID: Int(id)} t.AlertRules = append(t.AlertRules, alertRule) } diff --git a/ftp_server_test.go b/ftp_server_test.go index 70841f6..4eb8607 100644 --- a/ftp_server_test.go +++ b/ftp_server_test.go @@ -18,55 +18,56 @@ func TestClient_GetFTPServer(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := FTPServer{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - AlertsEnabled: 1, - TestName: "test123", - Type: "ftp-server", - Interval: 300, - URL: "webex.com", - ProbeMode: "AUTO", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + AlertsEnabled: Int(1), + TestName: String("test123"), + Type: String("ftp-server"), + LiveShare: Int(0), + Interval: Int(300), + URL: String("webex.com"), + ProbeMode: String("AUTO"), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, APILinks: []APILink{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/ftp-server/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/ftp-server/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, } @@ -102,65 +103,66 @@ func TestClient_CreateFTPServer(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := FTPServer{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "ftp-server", - AlertsEnabled: 1, - Interval: 300, - URL: "webex.com", - Protocol: "TCP", - ProbeMode: "AUTO", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + TestName: String("test123"), + Type: String("ftp-server"), + AlertsEnabled: Int(1), + Interval: Int(300), + LiveShare: Int(0), + URL: String("webex.com"), + Protocol: String("TCP"), + ProbeMode: String("AUTO"), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, APILinks: []APILink{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/ftp-server/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/ftp-server/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } create := FTPServer{ - TestName: "test123", - URL: "webex.com", - Protocol: "TCP", - ProbeMode: "AUTO", + TestName: String("test123"), + URL: String("webex.com"), + Protocol: String("TCP"), + ProbeMode: String("AUTO"), } res, err := client.CreateFTPServer(create) teardown() @@ -186,8 +188,8 @@ func TestClient_DeleteFTPServer(t *testing.T) { } func TestClient_AddFTPServerAlertRule(t *testing.T) { - test := FTPServer{TestName: "test", AlertRules: []AlertRule{}} - expected := FTPServer{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} + test := FTPServer{TestName: String("test"), AlertRules: []AlertRule{}} + expected := FTPServer{TestName: String("test"), AlertRules: []AlertRule{{RuleID: Int(1)}}} test.AddAlertRule(1) assert.Equal(t, expected, test) } @@ -202,19 +204,19 @@ func TestClient_UpdateFTPServer(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 1 - ftpServer := FTPServer{URL: "webex.com"} + ftpServer := FTPServer{URL: String("webex.com")} res, err := client.UpdateFTPServer(id, ftpServer) if err != nil { t.Fatal(err) } - expected := FTPServer{TestID: 1, TestName: "test123", Type: "ftp-server", URL: "webex.com"} + expected := FTPServer{TestID: Int64(1), TestName: String("test123"), Type: String("ftp-server"), URL: String("webex.com")} assert.Equal(t, &expected, res) } func TestFTPServer_AddAgent(t *testing.T) { - test := FTPServer{TestName: "test", Agents: Agents{}} - expected := FTPServer{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := FTPServer{TestName: String("test"), Agents: Agents{}} + expected := FTPServer{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } @@ -244,7 +246,7 @@ func TestClient_GetFTPServerStatusCode(t *testing.T) { _, err := client.GetFTPServer(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateFTPServerStatusCode(t *testing.T) { @@ -257,7 +259,7 @@ func TestClient_CreateFTPServerStatusCode(t *testing.T) { }) _, err := client.CreateFTPServer(FTPServer{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateFTPServerStatusCode(t *testing.T) { @@ -270,7 +272,7 @@ func TestClient_UpdateFTPServerStatusCode(t *testing.T) { }) _, err := client.UpdateFTPServer(1, FTPServer{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteFTPServerCode(t *testing.T) { @@ -283,5 +285,5 @@ func TestClient_DeleteFTPServerCode(t *testing.T) { }) err := client.DeleteFTPServer(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/group_label.go b/group_label.go index 7d68d09..118a952 100644 --- a/group_label.go +++ b/group_label.go @@ -9,10 +9,10 @@ type GroupLabels []GroupLabel // GroupLabel - label type GroupLabel struct { - Name string `json:"name,omitempty"` - GroupID int `json:"groupId,omitempty"` - BuiltIn int `json:"builtin,omitempty"` - Type string `json:"type,omitempty"` + Name *string `json:"name,omitempty"` + GroupID *int64 `json:"groupId,omitempty"` + BuiltIn *int `json:"builtin,omitempty"` + Type *string `json:"type,omitempty"` Agents []Agent `json:"agents,omitempty"` Tests []GenericTest `json:"tests,omitempty"` } @@ -60,10 +60,13 @@ func (c *Client) GetGroupLabel(id int) (*GroupLabel, error) { // CreateGroupLabel - Create label func (c Client) CreateGroupLabel(a GroupLabel) (*GroupLabel, error) { - path := fmt.Sprintf("/groups/%s/new", a.Type) + if a.Type == nil { + a.Type = String("") + } + path := fmt.Sprintf("/groups/%s/new", *a.Type) // Now we must set Type to blank. Because even though it's required to know the submit path, // TE will return an error if we also submit it a part of the object. - a.Type = "" + a.Type = String("") resp, err := c.post(path, a, nil) if err != nil { return nil, err diff --git a/group_label_test.go b/group_label_test.go index 6999e5c..3e4bcb4 100644 --- a/group_label_test.go +++ b/group_label_test.go @@ -18,7 +18,7 @@ func TestClient_GetGroupLabels(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := GroupLabels{ - GroupLabel{GroupID: 1, Type: "tests", Name: "exampleName"}, + GroupLabel{GroupID: Int64(1), Type: String("tests"), Name: String("exampleName")}, } res, err := client.GetGroupLabels() @@ -29,7 +29,7 @@ func TestClient_GetGroupLabels(t *testing.T) { } func TestClient_GetGroupLabelsByType(t *testing.T) { - out := `{"groups" : [ {"groupId":1, "type" : "tests", "name": "test-agent" }]}` + out := `{"groups" : [ {"groupId":1, "type" : "tests", "name": "test-agent", "builtIn": 0 }]}` setup() var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} mux.HandleFunc("/groups/tests.json", func(w http.ResponseWriter, r *http.Request) { @@ -39,7 +39,7 @@ func TestClient_GetGroupLabelsByType(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := GroupLabels{ - GroupLabel{GroupID: 1, BuiltIn: 0, Type: "tests", Name: "test-agent"}, + GroupLabel{GroupID: Int64(1), BuiltIn: Int(0), Type: String("tests"), Name: String("test-agent")}, } res, err := client.GetGroupLabelsByType("tests") @@ -52,7 +52,7 @@ func TestClient_GetGroupLabel(t *testing.T) { out := `{ "groups" : [ { - "groupId" : 222, "type" : "tests", "name" : "test-agent" + "groupId" : 222, "type" : "tests", "name" : "test-agent", "builtIn": 0 } ] }` @@ -65,7 +65,7 @@ func TestClient_GetGroupLabel(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := GroupLabel{ - GroupID: 222, BuiltIn: 0, Type: "tests", Name: "test-agent", + GroupID: Int64(222), BuiltIn: Int(0), Type: String("tests"), Name: String("test-agent"), } res, err := client.GetGroupLabel(222) @@ -153,12 +153,12 @@ func TestClient_UpdateGroupLabel(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 222 - u := GroupLabel{Type: "tests"} + u := GroupLabel{Type: String("tests")} res, err := client.UpdateGroupLabel(id, u) if err != nil { t.Fatal(err) } - expected := GroupLabels{GroupLabel{GroupID: 222, Type: "tests", Name: "test-agent"}} + expected := GroupLabels{GroupLabel{GroupID: Int64(222), Type: String("tests"), Name: String("test-agent")}} assert.Equal(t, &expected, res) } @@ -172,12 +172,12 @@ func TestClient_CreateGroupLabel(t *testing.T) { }) var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} - u := GroupLabel{Name: "test", Type: "tests", GroupID: 1} + u := GroupLabel{Name: String("test"), Type: String("tests"), GroupID: Int64(1)} res, err := client.CreateGroupLabel(u) if err != nil { t.Fatal(err) } - expected := GroupLabel{GroupID: 1, Name: "test"} + expected := GroupLabel{GroupID: Int64(1), Name: String("test")} assert.Equal(t, &expected, res) } @@ -232,7 +232,7 @@ func TestClient_GetGroupLabelsStatusCode(t *testing.T) { _, err := client.GetGroupLabels() teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateGroupLabelJsonError(t *testing.T) { @@ -245,7 +245,7 @@ func TestClient_CreateGroupLabelJsonError(t *testing.T) { _, _ = w.Write([]byte(out)) }) - _, err := client.CreateGroupLabel(GroupLabel{Type: "tests"}) + _, err := client.CreateGroupLabel(GroupLabel{Type: String("tests")}) assert.Error(t, err) assert.EqualError(t, err, "Could not decode JSON response: invalid character 'e' in literal true (expecting 'r')") } @@ -284,9 +284,9 @@ func TestClient_CreateGroupLabelStatusCode(t *testing.T) { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(`{}`)) }) - _, err := client.CreateGroupLabel(GroupLabel{Type: "tests"}) + _, err := client.CreateGroupLabel(GroupLabel{Type: String("tests")}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateGroupLabelStatusCode(t *testing.T) { @@ -299,7 +299,7 @@ func TestClient_UpdateGroupLabelStatusCode(t *testing.T) { }) _, err := client.UpdateGroupLabel(1, GroupLabel{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteGroupLabelStatusCode(t *testing.T) { @@ -312,5 +312,5 @@ func TestClient_DeleteGroupLabelStatusCode(t *testing.T) { }) err := client.DeleteGroupLabel(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/http_server.go b/http_server.go index fa0b394..f46de2a 100644 --- a/http_server.go +++ b/http_server.go @@ -20,62 +20,61 @@ type CustomHeaders struct { // HTTPServer - a http server test type HTTPServer struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test - Agents Agents `json:"agents,omitempty"` - AuthType string `json:"authType,omitempty"` - BandwidthMeasurements int `json:"bandwidthMeasurements,omitempty"` - BGPMeasurements int `json:"bgpMeasurements,omitempty"` - BGPMonitors []Monitor `json:"bgpMonitors,omitempty"` - ClientCertificate string `json:"clientCertificate,omitempty"` - ContentRegex string `json:"contentRegex,omitempty"` - CustomHeaders CustomHeaders `json:"customHeaders,omitempty"` - DesiredStatusCode string `json:"desiredStatusCode,omitempty"` - DownloadLimit string `json:"downloadLimit,omitempty"` - DNSOverride string `json:"dnsOverride,omitempty"` - FollowRedirects int `json:"followRedirects,omitempty"` - Headers []string `json:"headers,omitempty"` - HTTPVersion int `json:"httpVersion,omitempty"` - HTTPTargetTime int `json:"httpTargetTime,omitempty"` - HTTPTimeLimit int `json:"httpTimeLimit,omitempty"` - Interval int `json:"interval,omitempty"` - MTUMeasurements int `json:"mtuMeasurements,omitempty"` - NetworkMeasurements int `json:"networkMeasurements,omitempty"` - NumPathTraces int `json:"numPathTraces,omitempty"` - Password string `json:"password,omitempty"` - PathTraceMode string `json:"pathTraceMode,omitempty"` - PostBody string `json:"postBody,omitempty"` - ProbeMode string `json:"probeMode,omitempty"` - Protocol string `json:"protocol,omitempty"` - SSLVersion string `json:"sslVersion,omitempty"` - SSLVersionID int `json:"sslVersionId,omitempty"` - URL string `json:"url,omitempty"` - UseNTLM int `json:"useNtlm,omitempty"` - UsePublicBGP int `json:"usePublicBgp,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Username string `json:"username,omitempty"` - VerifyCertificate int `json:"verifyCertificate,omitempty"` + Agents Agents `json:"agents,omitempty"` + AuthType *string `json:"authType,omitempty"` + BandwidthMeasurements *int `json:"bandwidthMeasurements,omitempty"` + BGPMeasurements *int `json:"bgpMeasurements,omitempty"` + BGPMonitors []Monitor `json:"bgpMonitors,omitempty"` + ClientCertificate *string `json:"clientCertificate,omitempty"` + ContentRegex *string `json:"contentRegex,omitempty"` + CustomHeaders *CustomHeaders `json:"customHeaders,omitempty"` + DesiredStatusCode *string `json:"desiredStatusCode,omitempty"` + DownloadLimit *string `json:"downloadLimit,omitempty"` + DNSOverride *string `json:"dnsOverride,omitempty"` + FollowRedirects *int `json:"followRedirects,omitempty"` + Headers []string `json:"headers,omitempty"` + HTTPVersion *int `json:"httpVersion,omitempty"` + HTTPTargetTime *int `json:"httpTargetTime,omitempty"` + HTTPTimeLimit *int `json:"httpTimeLimit,omitempty"` + Interval *int `json:"interval,omitempty"` + MTUMeasurements *int `json:"mtuMeasurements,omitempty"` + NetworkMeasurements *int `json:"networkMeasurements,omitempty"` + NumPathTraces *int `json:"numPathTraces,omitempty"` + Password *string `json:"password,omitempty"` + PathTraceMode *string `json:"pathTraceMode,omitempty"` + PostBody *string `json:"postBody,omitempty"` + ProbeMode *string `json:"probeMode,omitempty"` + Protocol *string `json:"protocol,omitempty"` + SSLVersion *string `json:"sslVersion,omitempty"` + SSLVersionID *int `json:"sslVersionId,omitempty"` + URL *string `json:"url,omitempty"` + UseNTLM *int `json:"useNtlm,omitempty"` // TODO: BasicAuth not working + UserAgent *string `json:"userAgent,omitempty"` + Username *string `json:"username,omitempty"` + VerifyCertificate *int `json:"verifyCertificate,omitempty"` } // AddAgent - add an agent func (t *HTTPServer) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } diff --git a/http_server_test.go b/http_server_test.go index 7f1f728..fa99e64 100644 --- a/http_server_test.go +++ b/http_server_test.go @@ -18,83 +18,82 @@ func TestClient_GetHTTPServer(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := HTTPServer{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "http-server", - Interval: 300, - URL: "https://test.com", - Protocol: "TCP", - NetworkMeasurements: 1, - MTUMeasurements: 1, - BandwidthMeasurements: 0, - BGPMeasurements: 1, - UsePublicBGP: 1, - AlertsEnabled: 1, - LiveShare: 0, - HTTPTimeLimit: 5, - HTTPTargetTime: 1000, - HTTPVersion: 2, - FollowRedirects: 1, - NumPathTraces: 3, - SSLVersionID: 0, - VerifyCertificate: 1, - UseNTLM: 0, - AuthType: "NONE", - ContentRegex: "", - ProbeMode: "AUTO", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + TestName: String("test123"), + Type: String("http-server"), + Interval: Int(300), + URL: String("https://test.com"), + Protocol: String("TCP"), + NetworkMeasurements: Int(1), + MTUMeasurements: Int(1), + BandwidthMeasurements: Int(0), + BGPMeasurements: Int(1), + AlertsEnabled: Int(1), + LiveShare: Int(0), + HTTPTimeLimit: Int(5), + HTTPTargetTime: Int(1000), + HTTPVersion: Int(2), + FollowRedirects: Int(1), + NumPathTraces: Int(3), + SSLVersionID: Int(0), + VerifyCertificate: Int(1), + UseNTLM: Int(0), + AuthType: String("NONE"), + ContentRegex: String(""), + ProbeMode: String("AUTO"), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, BGPMonitors: []Monitor{ { - MonitorID: 64, - IPAddress: "2001:240:100:ff::2497:2", - CountryID: "JP", - MonitorName: "Tokyo-3", - Network: "IIJ Internet Initiative Japan Inc. (AS 2497)", - MonitorType: "Public", + MonitorID: Int(64), + IPAddress: String("2001:240:100:ff::2497:2"), + CountryID: String("JP"), + MonitorName: String("Tokyo-3"), + Network: String("IIJ Internet Initiative Japan Inc. (AS 2497)"), + MonitorType: String("Public"), }, }, - SSLVersion: "Auto", + SSLVersion: String("Auto"), APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/http-server/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/http-server/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } @@ -130,90 +129,89 @@ func TestClient_CreateHTTPServer(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := HTTPServer{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "http-server", - Interval: 300, - URL: "https://test.com", - Protocol: "TCP", - NetworkMeasurements: 1, - MTUMeasurements: 1, - BandwidthMeasurements: 0, - BGPMeasurements: 1, - UsePublicBGP: 1, - AlertsEnabled: 1, - LiveShare: 0, - HTTPTimeLimit: 5, - HTTPTargetTime: 1000, - HTTPVersion: 2, - FollowRedirects: 1, - NumPathTraces: 3, - SSLVersionID: 0, - VerifyCertificate: 1, - UseNTLM: 0, - AuthType: "NONE", - ContentRegex: "", - ProbeMode: "AUTO", + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + TestName: String("test123"), + Type: String("http-server"), + Interval: Int(300), + URL: String("https://test.com"), + Protocol: String("TCP"), + NetworkMeasurements: Int(1), + MTUMeasurements: Int(1), + BandwidthMeasurements: Int(0), + BGPMeasurements: Int(1), + AlertsEnabled: Int(1), + LiveShare: Int(0), + HTTPTimeLimit: Int(5), + HTTPTargetTime: Int(1000), + HTTPVersion: Int(2), + FollowRedirects: Int(1), + NumPathTraces: Int(3), + SSLVersionID: Int(0), + VerifyCertificate: Int(1), + UseNTLM: Int(0), + AuthType: String("NONE"), + ContentRegex: String(""), + ProbeMode: String("AUTO"), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, BGPMonitors: []Monitor{ { - MonitorID: 64, - IPAddress: "2001:240:100:ff::2497:2", - CountryID: "JP", - MonitorName: "Tokyo-3", - Network: "IIJ Internet Initiative Japan Inc. (AS 2497)", - MonitorType: "Public", + MonitorID: Int(64), + IPAddress: String("2001:240:100:ff::2497:2"), + CountryID: String("JP"), + MonitorName: String("Tokyo-3"), + Network: String("IIJ Internet Initiative Japan Inc. (AS 2497)"), + MonitorType: String("Public"), }, }, - SSLVersion: "Auto", + SSLVersion: String("Auto"), APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/http-server/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/http-server/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } create := HTTPServer{ - TestName: "test1", - URL: "https://test.com", - Interval: 300, + TestName: String("test1"), + URL: String("https://test.com"), + Interval: Int(300), } res, err := client.CreateHTTPServer(create) teardown() @@ -248,19 +246,19 @@ func TestClient_UpdateHTTPServer(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 1 - httpS := HTTPServer{URL: "https://test.com"} + httpS := HTTPServer{URL: String("https://test.com")} res, err := client.UpdateHTTPServer(id, httpS) if err != nil { t.Fatal(err) } - expected := HTTPServer{TestID: 1, TestName: "test123", Type: "http-server", URL: "https://test.com"} + expected := HTTPServer{TestID: Int64(1), TestName: String("test123"), Type: String("http-server"), URL: String("https://test.com")} assert.Equal(t, &expected, res) } func TestHTTPServer_AddAgent(t *testing.T) { - test := HTTPServer{TestName: "test", Agents: Agents{}} - expected := HTTPServer{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := HTTPServer{TestName: String("test"), Agents: Agents{}} + expected := HTTPServer{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } @@ -290,7 +288,7 @@ func TestClient_GetHTTPServerStatusCode(t *testing.T) { _, err := client.GetHTTPServer(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateHTTPServerStatusCode(t *testing.T) { @@ -303,7 +301,7 @@ func TestClient_CreateHTTPServerStatusCode(t *testing.T) { }) _, err := client.CreateHTTPServer(HTTPServer{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateHTTPServerStatusCode(t *testing.T) { @@ -316,7 +314,7 @@ func TestClient_UpdateHTTPServerStatusCode(t *testing.T) { }) _, err := client.UpdateHTTPServer(1, HTTPServer{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteHTTPServerStatusCode(t *testing.T) { @@ -329,5 +327,5 @@ func TestClient_DeleteHTTPServerStatusCode(t *testing.T) { }) err := client.DeleteHTTPServer(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/integration.go b/integration.go index 2591af8..a51065e 100644 --- a/integration.go +++ b/integration.go @@ -4,14 +4,14 @@ import "fmt" // Integration - Integration struct type Integration struct { - AuthMethod string `json:"authMethod,omitempty"` - AuthUser string `json:"authUser,omitempty"` - AuthToken string `json:"authToken,omitempty"` - Channel string `json:"channel,omitempty"` - IntegrationID string `json:"integrationId,omitempty"` - IntegrationName string `json:"integrationName,omitempty"` - IntegrationType string `json:"integrationType,omitempty"` - Target string `json:"target,omitempty"` + AuthMethod *string `json:"authMethod,omitempty"` + AuthUser *string `json:"authUser,omitempty"` + AuthToken *string `json:"authToken,omitempty"` + Channel *string `json:"channel,omitempty"` + IntegrationID *string `json:"integrationId,omitempty"` + IntegrationName *string `json:"integrationName,omitempty"` + IntegrationType *string `json:"integrationType,omitempty"` + Target *string `json:"target,omitempty"` } // GetIntegrations - Get third party and webhook integrations diff --git a/integration_test.go b/integration_test.go index 07d538c..db83ace 100644 --- a/integration_test.go +++ b/integration_test.go @@ -20,17 +20,17 @@ func TestClient_GetIntegrations(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := []Integration{ { - AuthMethod: "Auth Token", - IntegrationID: "pgd-9999", - IntegrationName: "Test PD Integration", - IntegrationType: "PAGER_DUTY", + AuthMethod: String("Auth Token"), + IntegrationID: String("pgd-9999"), + IntegrationName: String("Test PD Integration"), + IntegrationType: String("PAGER_DUTY"), }, { - AuthMethod: "Basic", - IntegrationID: "wb-999", - IntegrationName: "Test Webhook Integration", - IntegrationType: "WEBHOOK", - Target: "https://grumpysysadm.com/", + AuthMethod: String("Basic"), + IntegrationID: String("wb-999"), + IntegrationName: String("Test Webhook Integration"), + IntegrationType: String("WEBHOOK"), + Target: String("https://grumpysysadm.com/"), }, } diff --git a/monitors.go b/monitors.go index bd0fdd2..3c018ec 100644 --- a/monitors.go +++ b/monitors.go @@ -5,10 +5,10 @@ type Monitors []Monitor // Monitor - A monitor type Monitor struct { - MonitorID int `json:"monitorId,omitempty"` - IPAddress string `json:"ipAddress,omitempty"` - CountryID string `json:"countryId,omitempty"` - MonitorName string `json:"monitorName,omitempty"` - Network string `json:"network,omitempty"` - MonitorType string `json:"monitorType,omitempty"` + MonitorID *int `json:"monitorId,omitempty"` + IPAddress *string `json:"ipAddress,omitempty"` + CountryID *string `json:"countryId,omitempty"` + MonitorName *string `json:"monitorName,omitempty"` + Network *string `json:"network,omitempty"` + MonitorType *string `json:"monitorType,omitempty"` } diff --git a/page_load.go b/page_load.go index 647d1a9..e2d6e0a 100644 --- a/page_load.go +++ b/page_load.go @@ -7,61 +7,61 @@ import ( // PageLoad - a page log struct type PageLoad struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents Agents `json:"agents,omitempty"` - AuthType string `json:"authType,omitempty"` - BandwidthMeasurements int `json:"bandwidthMeasurements,omitempty"` - BGPMeasurements int `json:"bgpMeasurements,omitempty"` + AuthType *string `json:"authType,omitempty"` + BandwidthMeasurements *int `json:"bandwidthMeasurements,omitempty"` + BGPMeasurements *int `json:"bgpMeasurements,omitempty"` BGPMonitors []BGPMonitor `json:"bgpMonitors,omitempty"` - ContentRegex string `json:"contentRegex,omitempty"` + ContentRegex *string `json:"contentRegex,omitempty"` CustomHeaders CustomHeaders `json:"customHeaders,omitempty"` - FollowRedirects int `json:"followRedirects,omitempty"` - HTTPInterval int `json:"httpInterval,omitempty"` - HTTPTargetTime int `json:"httpTargetTime,omitempty"` - HTTPTimeLimit int `json:"httpTimeLimit,omitempty"` - HTTPVersion int `json:"httpVersion,omitempty"` - IncludeHeaders int `json:"includeHeaders,omitempty"` - Interval int `json:"interval,omitempty"` - MTUMeasurements int `json:"mtuMeasurements,omitempty"` - NetworkMeasurements int `json:"networkMeasurements,omitempty"` - NumPathTraces int `json:"numPathTraces,omitempty"` - PageLoadTargetTime int `json:"pageLoadTargetTime,omitempty"` - PageLoadTimeLimit int `json:"pageLoadTimeLimit,omitempty"` - Password string `json:"password,omitempty"` - PathTraceMode string `json:"pathTraceMode,omitempty"` - ProbeMode string `json:"probeMode,omitempty"` - Protocol string `json:"protocol,omitempty"` - SSLVersion string `json:"sslVersion,omitempty"` - SSLVersionID int `json:"sslVersionId,omitempty"` - Subinterval int `json:"subinterval,omitempty"` - URL string `json:"url,omitempty"` - UseNTLM int `json:"useNtlm,omitempty"` - UsePublicBGP int `json:"usePublicBgp,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Username string `json:"username,omitempty"` - VerifyCertificate int `json:"verifyCertificate,omitempty"` + FollowRedirects *int `json:"followRedirects,omitempty"` + HTTPInterval *int `json:"httpInterval,omitempty"` + HTTPTargetTime *int `json:"httpTargetTime,omitempty"` + HTTPTimeLimit *int `json:"httpTimeLimit,omitempty"` + HTTPVersion *int `json:"httpVersion,omitempty"` + IncludeHeaders *int `json:"includeHeaders,omitempty"` + Interval *int `json:"interval,omitempty"` + MTUMeasurements *int `json:"mtuMeasurements,omitempty"` + NetworkMeasurements *int `json:"networkMeasurements,omitempty"` + NumPathTraces *int `json:"numPathTraces,omitempty"` + PageLoadTargetTime *int `json:"pageLoadTargetTime,omitempty"` + PageLoadTimeLimit *int `json:"pageLoadTimeLimit,omitempty"` + Password *string `json:"password,omitempty"` + PathTraceMode *string `json:"pathTraceMode,omitempty"` + ProbeMode *string `json:"probeMode,omitempty"` + Protocol *string `json:"protocol,omitempty"` + SSLVersion *string `json:"sslVersion,omitempty"` + SSLVersionID *int `json:"sslVersionId,omitempty"` + Subinterval *int `json:"subinterval,omitempty"` + URL *string `json:"url,omitempty"` + UseNTLM *int `json:"useNtlm,omitempty"` + UsePublicBGP *int `json:"usePublicBgp,omitempty"` + UserAgent *string `json:"userAgent,omitempty"` + Username *string `json:"username,omitempty"` + VerifyCertificate *int `json:"verifyCertificate,omitempty"` } // AddAgent - add an aget func (t *PageLoad) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } diff --git a/page_load_test.go b/page_load_test.go index 1c06b9f..6a9f080 100644 --- a/page_load_test.go +++ b/page_load_test.go @@ -20,94 +20,95 @@ func TestClient_CreatePageLoad(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := PageLoad{ - CreatedDate: "2020-02-06 19:15:36", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - Enabled: 1, - SavedEvent: 0, - TestID: 1226422, - TestName: "test1", - Type: "page-load", - Interval: 300, - HTTPInterval: 300, - URL: "https://test.com", - Protocol: "TCP", - FollowRedirects: 1, - NetworkMeasurements: 1, - MTUMeasurements: 1, - BandwidthMeasurements: 0, - BGPMeasurements: 1, - UsePublicBGP: 1, - AlertsEnabled: 1, - LiveShare: 0, - HTTPTimeLimit: 5, - HTTPTargetTime: 1000, - HTTPVersion: 2, - PageLoadTimeLimit: 10, - PageLoadTargetTime: 6, - IncludeHeaders: 1, - SSLVersionID: 0, - VerifyCertificate: 1, - UseNTLM: 0, - AuthType: "NONE", - ProbeMode: "AUTO", + CreatedDate: String("2020-02-06 19:15:36"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + Enabled: Int(1), + SavedEvent: Int(0), + TestID: Int64(1226422), + TestName: String("test1"), + Type: String("page-load"), + Interval: Int(300), + HTTPInterval: Int(300), + URL: String("https://test.com"), + Protocol: String("TCP"), + FollowRedirects: Int(1), + NetworkMeasurements: Int(1), + MTUMeasurements: Int(1), + BandwidthMeasurements: Int(0), + BGPMeasurements: Int(1), + UsePublicBGP: Int(1), + AlertsEnabled: Int(1), + LiveShare: Int(0), + HTTPTimeLimit: Int(5), + HTTPTargetTime: Int(1000), + HTTPVersion: Int(2), + PageLoadTimeLimit: Int(10), + PageLoadTargetTime: Int(6), + IncludeHeaders: Int(1), + SSLVersionID: Int(0), + VerifyCertificate: Int(1), + UseNTLM: Int(0), + AuthType: String("NONE"), + ProbeMode: String("AUTO"), + ContentRegex: String(""), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, BGPMonitors: []BGPMonitor{ { - MonitorID: 62, - IPAddress: "2001:1890:111d:1::63", - MonitorName: "New York, NY-6", - Network: "AT&T Services, Inc. (AS 7018)", - MonitorType: "Public", + MonitorID: Int(62), + IPAddress: String("2001:1890:111d:1::63"), + MonitorName: String("New York, NY-6"), + Network: String("AT&T Services, Inc. (AS 7018)"), + MonitorType: String("Public"), }, }, - NumPathTraces: 3, + NumPathTraces: Int(3), APILinks: APILinks{ { - Rel: "self", - Href: "https://api.thousandeyes.com/v6/tests/1226422", + Rel: String("self"), + Href: String("https://api.thousandeyes.com/v6/tests/1226422"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/web/http-server/1226422", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/web/http-server/1226422"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/web/page-load/1226422"}, + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/web/page-load/1226422")}, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/net/metrics/1226422", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226422"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226422", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226422"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226422", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226422"), }, }, - SSLVersion: "Auto", + SSLVersion: String("Auto"), } create := PageLoad{ - TestName: "test1", - URL: "https://test.com", - Interval: 300, - HTTPInterval: 300, + TestName: String("test1"), + URL: String("https://test.com"), + Interval: Int(300), + HTTPInterval: Int(300), } res, err := client.CreatePageLoad(create) teardown() @@ -126,88 +127,89 @@ func TestClient_GetPageLoad(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := PageLoad{ - CreatedDate: "2020-02-06 19:15:36", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - Enabled: 1, - SavedEvent: 0, - TestID: 1226422, - TestName: "test1", - Type: "page-load", - Interval: 300, - HTTPInterval: 300, - URL: "https://test.com", - Protocol: "TCP", - FollowRedirects: 1, - NetworkMeasurements: 1, - MTUMeasurements: 1, - BandwidthMeasurements: 0, - BGPMeasurements: 1, - UsePublicBGP: 1, - AlertsEnabled: 1, - LiveShare: 0, - HTTPTimeLimit: 5, - HTTPTargetTime: 1000, - HTTPVersion: 2, - PageLoadTimeLimit: 10, - PageLoadTargetTime: 6, - IncludeHeaders: 1, - SSLVersionID: 0, - VerifyCertificate: 1, - UseNTLM: 0, - AuthType: "NONE", - ProbeMode: "AUTO", + CreatedDate: String("2020-02-06 19:15:36"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + Enabled: Int(1), + SavedEvent: Int(0), + TestID: Int64(1226422), + TestName: String("test1"), + Type: String("page-load"), + Interval: Int(300), + HTTPInterval: Int(300), + URL: String("https://test.com"), + Protocol: String("TCP"), + FollowRedirects: Int(1), + NetworkMeasurements: Int(1), + MTUMeasurements: Int(1), + BandwidthMeasurements: Int(0), + BGPMeasurements: Int(1), + UsePublicBGP: Int(1), + AlertsEnabled: Int(1), + LiveShare: Int(0), + HTTPTimeLimit: Int(5), + HTTPTargetTime: Int(1000), + HTTPVersion: Int(2), + PageLoadTimeLimit: Int(10), + PageLoadTargetTime: Int(6), + IncludeHeaders: Int(1), + SSLVersionID: Int(0), + VerifyCertificate: Int(1), + UseNTLM: Int(0), + AuthType: String("NONE"), + ProbeMode: String("AUTO"), + ContentRegex: String(""), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, BGPMonitors: []BGPMonitor{ { - MonitorID: 62, - IPAddress: "2001:1890:111d:1::63", - MonitorName: "New York, NY-6", - Network: "AT&T Services, Inc. (AS 7018)", - MonitorType: "Public", + MonitorID: Int(62), + IPAddress: String("2001:1890:111d:1::63"), + MonitorName: String("New York, NY-6"), + Network: String("AT&T Services, Inc. (AS 7018)"), + MonitorType: String("Public"), }, }, - NumPathTraces: 3, + NumPathTraces: Int(3), APILinks: APILinks{ { - Rel: "self", - Href: "https://api.thousandeyes.com/v6/tests/1226422", + Rel: String("self"), + Href: String("https://api.thousandeyes.com/v6/tests/1226422"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/web/http-server/1226422", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/web/http-server/1226422"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/web/page-load/1226422"}, + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/web/page-load/1226422")}, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/net/metrics/1226422", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226422"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226422", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226422"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226422", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226422"), }, }, - SSLVersion: "Auto", + SSLVersion: String("Auto"), } res, err := client.GetPageLoad(1226422) @@ -244,19 +246,19 @@ func TestClient_UpdatePageLoad(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 1 - httpS := PageLoad{URL: "https://test.com"} + httpS := PageLoad{URL: String("https://test.com")} res, err := client.UpdatePageLoad(id, httpS) if err != nil { t.Fatal(err) } - expected := PageLoad{TestID: 1, TestName: "test123", Type: "page-load", URL: "https://test.com"} + expected := PageLoad{TestID: Int64(1), TestName: String("test123"), Type: String("page-load"), URL: String("https://test.com")} assert.Equal(t, &expected, res) } func TestPageLoad_AddAgent(t *testing.T) { - test := PageLoad{TestName: "test", Agents: Agents{}} - expected := PageLoad{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := PageLoad{TestName: String("test"), Agents: Agents{}} + expected := PageLoad{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } @@ -299,7 +301,7 @@ func TestClient_GetPageLoadStatusCode(t *testing.T) { _, err := client.GetPageLoad(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreatePageLoadStatusCode(t *testing.T) { @@ -312,7 +314,7 @@ func TestClient_CreatePageLoadStatusCode(t *testing.T) { }) _, err := client.CreatePageLoad(PageLoad{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdatePageLoadStatusCode(t *testing.T) { @@ -325,7 +327,7 @@ func TestClient_UpdatePageLoadStatusCode(t *testing.T) { }) _, err := client.UpdatePageLoad(1, PageLoad{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeletePageLoadStatusCode(t *testing.T) { @@ -338,5 +340,5 @@ func TestClient_DeletePageLoadStatusCode(t *testing.T) { }) err := client.DeletePageLoad(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/role.go b/role.go index a45b502..a8c15ab 100644 --- a/role.go +++ b/role.go @@ -4,18 +4,18 @@ import "fmt" // AccountGroupRole - an account group role type AccountGroupRole struct { - RoleName string `json:"roleName,omitempty"` - RoleID int `json:"roleId,omitempty"` - HasManagementPermissions int `json:"hasManagementPermissions,omitempty"` - Builtin int `json:"builtin,omitempty"` + RoleName *string `json:"roleName,omitempty"` + RoleID *int `json:"roleId,omitempty"` + HasManagementPermissions *int `json:"hasManagementPermissions,omitempty"` + Builtin *int `json:"builtin,omitempty"` Permissions []Permission `json:"permissions,omitempty"` } // Permission - permission attached to roles type Permission struct { - IsManagementPermission int `json:"isManagementPermission"` - Label string `json:"label"` - PermissionID int `json:"permissionId"` + IsManagementPermission *int `json:"isManagementPermission"` + Label *string `json:"label"` + PermissionID *int `json:"permissionId"` } // GetRoles - get roles diff --git a/role_test.go b/role_test.go index 2f876b7..79d0b53 100644 --- a/role_test.go +++ b/role_test.go @@ -23,16 +23,16 @@ func TestClient_GetRoles(t *testing.T) { } expected := []AccountGroupRole{ { - RoleName: "admin", - RoleID: 2, - HasManagementPermissions: 0, - Builtin: 0, + RoleName: String("admin"), + RoleID: Int(2), + HasManagementPermissions: Int(0), + Builtin: Int(0), }, { - RoleName: "user1", - RoleID: 1, - HasManagementPermissions: 1, - Builtin: 1, + RoleName: String("user1"), + RoleID: Int(1), + HasManagementPermissions: Int(1), + Builtin: Int(1), }, } assert.Equal(t, &expected, res) @@ -54,10 +54,10 @@ func TestClient_GetRole(t *testing.T) { t.Fatal(err) } expected := AccountGroupRole{ - RoleName: "admin", - RoleID: 1, - HasManagementPermissions: 0, - Builtin: 0, + RoleName: String("admin"), + RoleID: Int(1), + HasManagementPermissions: Int(0), + Builtin: Int(0), } assert.Equal(t, &expected, res) } @@ -73,8 +73,8 @@ func TestClient_CreateRole(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} create := AccountGroupRole{ - RoleName: "William Test", - HasManagementPermissions: 1, + RoleName: String("William Test"), + HasManagementPermissions: Int(1), } res, err := client.CreateRole(create) if err != nil { @@ -82,10 +82,10 @@ func TestClient_CreateRole(t *testing.T) { } expected := AccountGroupRole{ - RoleName: "William Test", - HasManagementPermissions: 1, - Builtin: 0, - RoleID: 1000, + RoleName: String("William Test"), + HasManagementPermissions: Int(1), + Builtin: Int(0), + RoleID: Int(1000), } assert.Equal(t, &expected, res) } @@ -113,8 +113,8 @@ func TestClient_UpdateRole(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} update := AccountGroupRole{ - RoleName: "William Test", - HasManagementPermissions: 1, + RoleName: String("William Test"), + HasManagementPermissions: Int(1), } res, err := client.UpdateRole(1, update) if err != nil { @@ -122,10 +122,10 @@ func TestClient_UpdateRole(t *testing.T) { } expected := AccountGroupRole{ - RoleName: "William Test", - RoleID: 1000, - HasManagementPermissions: 1, - Builtin: 0, + RoleName: String("William Test"), + RoleID: Int(1000), + HasManagementPermissions: Int(1), + Builtin: Int(0), } assert.Equal(t, &expected, res) } @@ -142,7 +142,7 @@ func TestClient_GetRoleStatusCode(t *testing.T) { _, err := client.GetRoles() teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateRoleStatusCode(t *testing.T) { @@ -155,7 +155,7 @@ func TestClient_CreateRoleStatusCode(t *testing.T) { }) _, err := client.CreateRole(AccountGroupRole{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateRoleStatusCode(t *testing.T) { @@ -168,7 +168,7 @@ func TestClient_UpdateRoleStatusCode(t *testing.T) { }) _, err := client.UpdateRole(1, AccountGroupRole{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteRoleStatusCode(t *testing.T) { @@ -181,7 +181,7 @@ func TestClient_DeleteRoleStatusCode(t *testing.T) { }) err := client.DeleteRole(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_GetRolesJsonError(t *testing.T) { diff --git a/sip_server.go b/sip_server.go index 41a4cc5..4a25c0c 100644 --- a/sip_server.go +++ b/sip_server.go @@ -9,50 +9,50 @@ import ( // SIPServer - SIPServer trace test type SIPServer struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents []Agent `json:"agents,omitempty"` - BandwidthMeasurements int `json:"bandwidthMeasurements,omitempty"` - BGPMeasurements int `json:"bgpMeasurements,omitempty"` - Interval int `json:"interval,omitempty"` - MTUMeasurements int `json:"mtuMeasurements,omitempty"` - NetworkMeasurements int `json:"networkMeasurements,omitempty"` - NumPathTraces int `json:"numPathTraces,omitempty"` - OptionsRegex string `json:"options_regex,omitempty"` - PathTraceMode string `json:"pathTraceMode,omitempty"` - ProbeMode string `json:"probeMode,omitempty"` - RegisterEnabled int `json:"registerEnabled,omitempty"` - SIPTargetTime int `json:"sipTargetTime,omitempty"` - SIPTimeLimit int `json:"sipTimeLimit,omitempty"` + BandwidthMeasurements *int `json:"bandwidthMeasurements,omitempty"` + BGPMeasurements *int `json:"bgpMeasurements,omitempty"` + Interval *int `json:"interval,omitempty"` + MTUMeasurements *int `json:"mtuMeasurements,omitempty"` + NetworkMeasurements *int `json:"networkMeasurements,omitempty"` + NumPathTraces *int `json:"numPathTraces,omitempty"` + OptionsRegex *string `json:"options_regex,omitempty"` + PathTraceMode *string `json:"pathTraceMode,omitempty"` + ProbeMode *string `json:"probeMode,omitempty"` + RegisterEnabled *int `json:"registerEnabled,omitempty"` + SIPTargetTime *int `json:"sipTargetTime,omitempty"` + SIPTimeLimit *int `json:"sipTimeLimit,omitempty"` TargetSIPCredentials SIPAuthData `json:"targetSipCredentials,omitempty"` - UsePublicBGP int `json:"usePublicBgp,omitempty"` + UsePublicBGP *int `json:"usePublicBgp,omitempty"` } // AddAgent - Add agemt to sip server test func (t *SIPServer) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } // AddAlertRule - Adds an alert to agent test func (t *SIPServer) AddAlertRule(id int) { - alertRule := AlertRule{RuleID: id} + alertRule := AlertRule{RuleID: Int(id)} t.AlertRules = append(t.AlertRules, alertRule) } diff --git a/sip_server_test.go b/sip_server_test.go index 3daf9a6..41e5424 100644 --- a/sip_server_test.go +++ b/sip_server_test.go @@ -18,53 +18,54 @@ func TestClient_GetSIPServer(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := SIPServer{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - AlertsEnabled: 1, - TestName: "test123", - Type: "sip-server", - Interval: 300, + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + AlertsEnabled: Int(1), + TestName: String("test123"), + Type: String("sip-server"), + Interval: Int(300), + LiveShare: Int(0), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/dns-trace/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/dns-trace/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } @@ -101,60 +102,61 @@ func TestClient_CreateSIPServer(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := SIPServer{ - TestID: 122621, - Enabled: 1, - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - CreatedDate: "2020-02-06 15:28:07", - SavedEvent: 0, - TestName: "test123", - Type: "sip-server", - Interval: 300, - AlertsEnabled: 1, + TestID: Int64(122621), + Enabled: Int(1), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + CreatedDate: String("2020-02-06 15:28:07"), + SavedEvent: Int(0), + TestName: String("test123"), + Type: String("sip-server"), + Interval: Int(300), + AlertsEnabled: Int(1), + LiveShare: Int(0), Agents: []Agent{ { - AgentID: 48620, - AgentType: "Cloud", - AgentName: "Seattle, WA (Trial) - IPv6", - CountryID: "US", + AgentID: Int(48620), + AgentType: String("Cloud"), + AgentName: String("Seattle, WA (Trial) - IPv6"), + CountryID: String("US"), IPAddresses: []string{"135.84.184.153"}, - Location: "Seattle Area", - Network: "Astute Hosting Inc. (AS 54527)", - Prefix: "135.84.184.0/22", + Location: String("Seattle Area"), + Network: String("Astute Hosting Inc. (AS 54527)"), + Prefix: String("135.84.184.0/22"), }, }, SharedWithAccounts: []SharedWithAccount{ { - AID: 176592, - AccountGroupName: "Cloudreach", + AID: Int(176592), + AccountGroupName: String("Cloudreach"), }, }, APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/1226221", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/1226221"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/web/dns-trace/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/web/dns-trace/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/metrics/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/path-vis/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/path-vis/1226221"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/1226221", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/1226221"), + Rel: String("data"), }, }, } create := SIPServer{ - TestName: "test1", - Interval: 300, + TestName: String("test1"), + Interval: Int(300), } res, err := client.CreateSIPServer(create) teardown() @@ -190,26 +192,26 @@ func TestClient_UpdateSIPServer(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 1 sipS := SIPServer{ - TestName: "test1", + TestName: String("test1"), } res, err := client.UpdateSIPServer(id, sipS) if err != nil { t.Fatal(err) } - expected := SIPServer{TestID: 1, TestName: "test123", Type: "sip-server"} + expected := SIPServer{TestID: Int64(1), TestName: String("test123"), Type: String("sip-server")} assert.Equal(t, &expected, res) } func TestSIPServer_AddAgent(t *testing.T) { - test := SIPServer{TestName: "test", Agents: Agents{}} - expected := SIPServer{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := SIPServer{TestName: String("test"), Agents: Agents{}} + expected := SIPServer{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } func TestClient_AddSIPServerAlertRule(t *testing.T) { - test := SIPServer{TestName: "test", AlertRules: []AlertRule{}} - expected := SIPServer{TestName: "test", AlertRules: []AlertRule{{RuleID: 1}}} + test := SIPServer{TestName: String("test"), AlertRules: []AlertRule{}} + expected := SIPServer{TestName: String("test"), AlertRules: []AlertRule{{RuleID: Int(1)}}} test.AddAlertRule(1) assert.Equal(t, expected, test) } @@ -239,7 +241,7 @@ func TestClient_GetSIPServerStatusCode(t *testing.T) { _, err := client.GetSIPServer(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateSIPServerStatusCode(t *testing.T) { @@ -252,7 +254,7 @@ func TestClient_CreateSIPServerStatusCode(t *testing.T) { }) _, err := client.CreateSIPServer(SIPServer{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateSIPServerStatusCode(t *testing.T) { @@ -265,7 +267,7 @@ func TestClient_UpdateSIPServerStatusCode(t *testing.T) { }) _, err := client.UpdateSIPServer(1, SIPServer{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteSIPServerStatusCode(t *testing.T) { @@ -278,5 +280,5 @@ func TestClient_DeleteSIPServerStatusCode(t *testing.T) { }) err := client.DeleteSIPServer(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/tests.go b/tests.go index 6c31a3d..79ad382 100644 --- a/tests.go +++ b/tests.go @@ -5,21 +5,21 @@ import "fmt" // GenericTest - GenericTest struct to represent all test types type GenericTest struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` // Fields unique to this test Agents []Agent `json:"agents,omitempty"` } diff --git a/tests_test.go b/tests_test.go index a823ed6..076c10a 100644 --- a/tests_test.go +++ b/tests_test.go @@ -18,7 +18,7 @@ func TestClient_GetTestStatusCode(t *testing.T) { _, err := client.GetTest(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_GetTestsStatusCode(t *testing.T) { @@ -33,7 +33,7 @@ func TestClient_GetTestsStatusCode(t *testing.T) { _, err := client.GetTests() teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_GetGenericTestsJsonError(t *testing.T) { diff --git a/users.go b/users.go index dba8239..33f3406 100644 --- a/users.go +++ b/users.go @@ -7,9 +7,9 @@ import ( // User - a user type User struct { - Name string `json:"name,omitempty"` - Email string `json:"email,omitempty"` - UID int `json:"uid,omitempty"` + Name *string `json:"name,omitempty"` + Email *string `json:"email,omitempty"` + UID *int `json:"uid,omitempty"` LastLogin *time.Time `json:"lastLogin,omitempty"` DateRegistered *time.Time `json:"dateRegistered,omitempty"` LoginAccountGroup AccountGroup `json:"loginAccountGroup,omitempty"` diff --git a/users_test.go b/users_test.go index 58cbba8..23011a6 100644 --- a/users_test.go +++ b/users_test.go @@ -23,14 +23,14 @@ func TestClient_GetUsers(t *testing.T) { } expected := []User{ { - Name: "William Fleming", - Email: "wfleming@grumpysysadm.com", - UID: 1, + Name: String("William Fleming"), + Email: String("wfleming@grumpysysadm.com"), + UID: Int(1), }, { - Name: "Test User 2", - Email: "wfleming@grumpysysadm.com", - UID: 2, + Name: String("Test User 2"), + Email: String("wfleming@grumpysysadm.com"), + UID: Int(2), }, } assert.Equal(t, &expected, res) @@ -52,9 +52,9 @@ func TestClient_GetUser(t *testing.T) { t.Fatal(err) } expected := User{ - Name: "William Fleming", - Email: "wfleming@grumpysysadm.com", - UID: 1, + Name: String("William Fleming"), + Email: String("wfleming@grumpysysadm.com"), + UID: Int(1), } assert.Equal(t, &expected, res) } @@ -70,8 +70,8 @@ func TestClient_CreateUser(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} create := User{ - Name: "William Fleming", - Email: "wfleming@grumpysysadm.com", + Name: String("William Fleming"), + Email: String("wfleming@grumpysysadm.com"), } res, err := client.CreateUser(create) if err != nil { @@ -79,9 +79,9 @@ func TestClient_CreateUser(t *testing.T) { } expected := User{ - Name: "William Fleming", - Email: "wfleming@grumpysysadm.com", - UID: 1, + Name: String("William Fleming"), + Email: String("wfleming@grumpysysadm.com"), + UID: Int(1), } assert.Equal(t, &expected, res) } @@ -109,7 +109,7 @@ func TestClient_UpdateUser(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} update := User{ - Email: "william@grumpysysadm.com", + Email: String("william@grumpysysadm.com"), } res, err := client.UpdateUser(1, update) if err != nil { @@ -117,9 +117,9 @@ func TestClient_UpdateUser(t *testing.T) { } expected := User{ - Name: "William Fleming", - Email: "william@grumpysysadm.com", - UID: 1, + Name: String("William Fleming"), + Email: String("william@grumpysysadm.com"), + UID: Int(1), } assert.Equal(t, &expected, res) } @@ -136,7 +136,7 @@ func TestClient_GetUserStatusCode(t *testing.T) { _, err := client.GetUsers() teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateUserStatusCode(t *testing.T) { @@ -149,7 +149,7 @@ func TestClient_CreateUserStatusCode(t *testing.T) { }) _, err := client.CreateUser(User{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateUserStatusCode(t *testing.T) { @@ -162,7 +162,7 @@ func TestClient_UpdateUserStatusCode(t *testing.T) { }) _, err := client.UpdateUser(1, User{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteUserStatusCode(t *testing.T) { @@ -175,7 +175,7 @@ func TestClient_DeleteUserStatusCode(t *testing.T) { }) err := client.DeleteUser(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_GetUsersJsonError(t *testing.T) { diff --git a/utils.go b/utils.go new file mode 100644 index 0000000..e65775b --- /dev/null +++ b/utils.go @@ -0,0 +1,17 @@ +package thousandeyes + +// Bool is a helper routine that allocates a new bool value +// to store v and returns a pointer to it. +func Bool(v bool) *bool { return &v } + +// Int is a helper routine that allocates a new int value +// to store v and returns a pointer to it. +func Int(v int) *int { return &v } + +// Int64 is a helper routine that allocates a new int64 value +// to store v and returns a pointer to it. +func Int64(v int64) *int64 { return &v } + +// String is a helper routine that allocates a new string value +// to store v and returns a pointer to it. +func String(v string) *string { return &v } diff --git a/voice.go b/voice.go index 155bdc5..7222661 100644 --- a/voice.go +++ b/voice.go @@ -9,45 +9,45 @@ import ( // RTPStream - RTPStream trace test type RTPStream struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents []Agent `json:"agents,omitempty"` - BGPMeasurements int `json:"bgpMeasurements,omitempty"` + BGPMeasurements *int `json:"bgpMeasurements,omitempty"` BGPMonitors []BGPMonitor `json:"bgpMonitors,omitempty"` - Codec string `json:"codec,omitempty"` - CodecID int `json:"codecId,omitempty"` - DSCP string `json:"dscp,omitempty"` - DSCPID int `json:"dscpId,omitempty"` - Duration int `json:"duration,omitempty"` - Interval int `json:"interval,omitempty"` - JitterBuffer int `json:"jitterBuffer,omitempty"` - MTUMeasurements int `json:"mtuMeasurements,omitempty"` - NumPathTraces int `json:"numPathTraces,omitempty"` - TargetAgentID int `json:"targetAgentId,omitempty"` - UsePublicBGP int `json:"usePublicBgp,omitempty"` + Codec *string `json:"codec,omitempty"` + CodecID *int `json:"codecId,omitempty"` + DSCP *string `json:"dscp,omitempty"` + DSCPID *int `json:"dscpId,omitempty"` + Duration *int `json:"duration,omitempty"` + Interval *int `json:"interval,omitempty"` + JitterBuffer *int `json:"jitterBuffer,omitempty"` + MTUMeasurements *int `json:"mtuMeasurements,omitempty"` + NumPathTraces *int `json:"numPathTraces,omitempty"` + TargetAgentID *int `json:"targetAgentId,omitempty"` + UsePublicBGP *int `json:"usePublicBgp,omitempty"` // server field is present in response, but we should not track it. - //Server string `json:"server,omitempty"` + //Server *string `json:"server,omitempty"` } // AddAgent - Add agent to voice call test func (t *RTPStream) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } diff --git a/voice_call.go b/voice_call.go index 70344a4..167035a 100644 --- a/voice_call.go +++ b/voice_call.go @@ -6,57 +6,57 @@ import ( // SIPAuthData - Authentication fields for SIP tests type SIPAuthData struct { - AuthUser string `json:"authUser,omitempty"` - Password string `json:"password,omitempty"` - Port int `json:"port,omitempty"` - Protocol string `json:"protocol,omitempty"` - SIPProxy string `json:"sipProxy,omitempty"` - SIPRegistrar string `json:"sipRegistrar,omitempty"` - User string `json:"user,omitempty"` + AuthUser *string `json:"authUser,omitempty"` + Password *string `json:"password,omitempty"` + Port *int `json:"port,omitempty"` + Protocol *string `json:"protocol,omitempty"` + SIPProxy *string `json:"sipProxy,omitempty"` + SIPRegistrar *string `json:"sipRegistrar,omitempty"` + User *string `json:"user,omitempty"` } // VoiceCall - VoiceCall trace test type VoiceCall struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents []Agent `json:"agents,omitempty"` - BGPMeasurements int `json:"bgpMeasurements,omitempty"` - Codec string `json:"codec,omitempty"` - CodecID int `json:"codecId,omitempty"` - DSCP string `json:"dscp,omitempty"` - DSCPID int `json:"dscpId,omitempty"` - Duration int `json:"duration,omitempty"` - Interval int `json:"interval,omitempty"` - JitterBuffer int `json:"jitterBuffer,omitempty"` - NumPathTraces int `json:"numPathTraces,omitempty"` - SIPTargetTime int `json:"sipTargetTime,omitempty"` - SIPTimeLimit int `json:"sipTimeLimit,omitempty"` + BGPMeasurements *int `json:"bgpMeasurements,omitempty"` + Codec *string `json:"codec,omitempty"` + CodecID *int `json:"codecId,omitempty"` + DSCP *string `json:"dscp,omitempty"` + DSCPID *int `json:"dscpId,omitempty"` + Duration *int `json:"duration,omitempty"` + Interval *int `json:"interval,omitempty"` + JitterBuffer *int `json:"jitterBuffer,omitempty"` + NumPathTraces *int `json:"numPathTraces,omitempty"` + SIPTargetTime *int `json:"sipTargetTime,omitempty"` + SIPTimeLimit *int `json:"sipTimeLimit,omitempty"` SourceSIPCredentials SIPAuthData `json:"sourceSipCredentials,omitempty"` - TargetAgentID int `json:"targetAgentId,omitempty"` + TargetAgentID *int `json:"targetAgentId,omitempty"` TargetSIPCredentials SIPAuthData `json:"targetSipCredentials,omitempty"` - UsePublicBGP int `json:"usePublicBgp,omitempty"` + UsePublicBGP *int `json:"usePublicBgp,omitempty"` } // AddAgent - Add agent to voice call test func (t *VoiceCall) AddAgent(id int) { - agent := Agent{AgentID: id} + agent := Agent{AgentID: Int(id)} t.Agents = append(t.Agents, agent) } diff --git a/voice_call_test.go b/voice_call_test.go index 3222f81..dadee21 100644 --- a/voice_call_test.go +++ b/voice_call_test.go @@ -18,60 +18,64 @@ func TestClient_GetVoiceCall(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := VoiceCall{ - TestID: 814641, - Enabled: 1, - CreatedBy: "ThousandEyes (support@thousandeyes.com)", - CreatedDate: "2018-11-03 19:09:42", - SavedEvent: 0, - AlertsEnabled: 0, - TestName: "Voice Call - AWS SIP server", - Interval: 120, - Duration: 5, - JitterBuffer: 40, - SIPTargetTime: 1000, - SIPTimeLimit: 5, - ModifiedDate: "2019-02-06 01:09:56", - ModifiedBy: "ThousandEyes (support@thousandeyes.com)", - TargetAgentID: 69, - Codec: "G.711 @ 64 Kbps", - BGPMeasurements: 1, - UsePublicBGP: 1, - NumPathTraces: 3, - DSCP: "EF (DSCP 46)", - DSCPID: 46, + TestID: Int64(814641), + Enabled: Int(1), + CreatedBy: String("ThousandEyes (support@thousandeyes.com)"), + CreatedDate: String("2018-11-03 19:09:42"), + SavedEvent: Int(0), + AlertsEnabled: Int(0), + TestName: String("Voice Call - AWS SIP server"), + Interval: Int(120), + LiveShare: Int(0), + Duration: Int(5), + JitterBuffer: Int(40), + SIPTargetTime: Int(1000), + SIPTimeLimit: Int(5), + ModifiedDate: String("2019-02-06 01:09:56"), + ModifiedBy: String("ThousandEyes (support@thousandeyes.com)"), + TargetAgentID: Int(69), + Codec: String("G.711 @ 64 Kbps"), + CodecID: Int(0), + BGPMeasurements: Int(1), + UsePublicBGP: Int(1), + NumPathTraces: Int(3), + DSCP: String("EF (DSCP 46)"), + DSCPID: Int(46), TargetSIPCredentials: SIPAuthData{ - Protocol: "UDP", - AuthUser: "1005", - Password: "", - Port: 5060, - SIPRegistrar: "18.234.180.66", - User: "1005", + Protocol: String("UDP"), + AuthUser: String("1005"), + Password: nil, + Port: Int(5060), + SIPProxy: String(""), + SIPRegistrar: String("18.234.180.66"), + User: String("1005"), }, SourceSIPCredentials: SIPAuthData{ - Protocol: "UDP", - AuthUser: "1006", - Password: "", - Port: 5060, - SIPRegistrar: "18.234.180.66", - User: "1006", + Protocol: String("UDP"), + AuthUser: String("1006"), + Password: nil, + Port: Int(5060), + SIPProxy: String(""), + SIPRegistrar: String("18.234.180.66"), + User: String("1006"), }, APILinks: APILinks{ { - Rel: "self", - Href: "https://api.thousandeyes.com/v6/tests/814641", + Rel: String("self"), + Href: String("https://api.thousandeyes.com/v6/tests/814641"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/voice/sip-server/814641", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/voice/sip-server/814641"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/voice/rtp-stream/814641", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/voice/rtp-stream/814641"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/814641", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/814641"), }, }, } @@ -107,47 +111,48 @@ func TestClient_CreateVoiceCall(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := VoiceCall{ - TestID: 814641, - Enabled: 1, - ModifiedBy: "ThousandEyes (support@thousandeyes.com)", - ModifiedDate: "2019-02-06 01:09:56", - CreatedBy: "ThousandEyes (support@thousandeyes.com)", - CreatedDate: "2018-11-03 19:09:42", - SavedEvent: 0, - TestName: "Voice Call - AWS SIP server", - Interval: 120, - AlertsEnabled: 0, - DSCPID: 46, - Duration: 5, - BGPMeasurements: 1, - UsePublicBGP: 1, - NumPathTraces: 3, - Codec: "G.711 @ 64 Kbps", + TestID: Int64(814641), + Enabled: Int(1), + ModifiedBy: String("ThousandEyes (support@thousandeyes.com)"), + ModifiedDate: String("2019-02-06 01:09:56"), + CreatedBy: String("ThousandEyes (support@thousandeyes.com)"), + CreatedDate: String("2018-11-03 19:09:42"), + SavedEvent: Int(0), + TestName: String("Voice Call - AWS SIP server"), + Interval: Int(120), + AlertsEnabled: Int(0), + DSCPID: Int(46), + Duration: Int(5), + BGPMeasurements: Int(1), + UsePublicBGP: Int(1), + NumPathTraces: Int(3), + Codec: String("G.711 @ 64 Kbps"), + CodecID: Int(0), APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/814641", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/814641"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/voice/sip-server/814641", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/voice/sip-server/814641"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/voice/rtp-stream/814641", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/voice/rtp-stream/814641"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/814641", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/814641"), + Rel: String("data"), }, }, } create := VoiceCall{ - TestName: "test1", - DSCPID: 46, - Duration: 5, - Interval: 120, - Codec: "G.711 @ 64 Kbps", + TestName: String("test1"), + DSCPID: Int(46), + Duration: Int(5), + Interval: Int(120), + Codec: String("G.711 @ 64 Kbps"), } res, err := client.CreateVoiceCall(create) teardown() @@ -183,23 +188,23 @@ func TestClient_UpdateVoiceCall(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 1 sipS := VoiceCall{ - TestName: "Voice Call - AWS SIP server", - CodecID: 0, - Codec: "G.711 @ 64 Kbps", - JitterBuffer: 40, + TestName: String("Voice Call - AWS SIP server"), + CodecID: Int(0), + Codec: String("G.711 @ 64 Kbps"), + JitterBuffer: Int(40), } res, err := client.UpdateVoiceCall(id, sipS) if err != nil { t.Fatal(err) } - expected := VoiceCall{Interval: 120, TestID: 1234, Codec: "G.711 @ 64 Kbps", TestName: "Voice Call - AWS SIP server", CodecID: 0, JitterBuffer: 40} + expected := VoiceCall{AlertsEnabled: Int(0), Interval: Int(120), TestID: Int64(1234), Codec: String("G.711 @ 64 Kbps"), TestName: String("Voice Call - AWS SIP server"), CodecID: Int(0), JitterBuffer: Int(40)} assert.Equal(t, &expected, res) } func TestVoiceCall_AddAgent(t *testing.T) { - test := VoiceCall{TestName: "test", Agents: Agents{}} - expected := VoiceCall{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := VoiceCall{TestName: String("test"), Agents: Agents{}} + expected := VoiceCall{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } @@ -229,7 +234,7 @@ func TestClient_GetVoiceCallStatusCode(t *testing.T) { _, err := client.GetVoiceCall(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateVoiceCallStatusCode(t *testing.T) { @@ -242,7 +247,7 @@ func TestClient_CreateVoiceCallStatusCode(t *testing.T) { }) _, err := client.CreateVoiceCall(VoiceCall{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateVoiceCallStatusCode(t *testing.T) { @@ -255,7 +260,7 @@ func TestClient_UpdateVoiceCallStatusCode(t *testing.T) { }) _, err := client.UpdateVoiceCall(1, VoiceCall{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteVoiceCallStatusCode(t *testing.T) { @@ -268,5 +273,5 @@ func TestClient_DeleteVoiceCallStatusCode(t *testing.T) { }) err := client.DeleteVoiceCall(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/voice_test.go b/voice_test.go index bde88d5..14ff129 100644 --- a/voice_test.go +++ b/voice_test.go @@ -18,42 +18,44 @@ func TestClient_GetRTPStream(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := RTPStream{ - TestID: 814641, - Enabled: 1, - CreatedBy: "ThousandEyes (support@thousandeyes.com)", - CreatedDate: "2018-11-03 19:09:42", - SavedEvent: 0, - AlertsEnabled: 0, - TestName: "RTP Stream - AWS RTP server", - Interval: 120, - Duration: 5, - JitterBuffer: 40, - ModifiedDate: "2019-02-06 01:09:56", - ModifiedBy: "ThousandEyes (support@thousandeyes.com)", - TargetAgentID: 69, - Codec: "G.711 @ 64 Kbps", - BGPMeasurements: 1, - UsePublicBGP: 1, - DSCP: "EF (DSCP 46)", - DSCPID: 46, - NumPathTraces: 3, + TestID: Int64(814641), + Enabled: Int(1), + CreatedBy: String("ThousandEyes (support@thousandeyes.com)"), + CreatedDate: String("2018-11-03 19:09:42"), + SavedEvent: Int(0), + AlertsEnabled: Int(0), + TestName: String("RTP Stream - AWS RTP server"), + Interval: Int(120), + LiveShare: Int(0), + Duration: Int(5), + JitterBuffer: Int(40), + ModifiedDate: String("2019-02-06 01:09:56"), + ModifiedBy: String("ThousandEyes (support@thousandeyes.com)"), + TargetAgentID: Int(69), + Codec: String("G.711 @ 64 Kbps"), + CodecID: Int(0), + BGPMeasurements: Int(1), + UsePublicBGP: Int(1), + DSCP: String("EF (DSCP 46)"), + DSCPID: Int(46), + NumPathTraces: Int(3), APILinks: APILinks{ { - Rel: "self", - Href: "https://api.thousandeyes.com/v6/tests/814641", + Rel: String("self"), + Href: String("https://api.thousandeyes.com/v6/tests/814641"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/voice/sip-server/814641", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/voice/sip-server/814641"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/voice/rtp-stream/814641", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/voice/rtp-stream/814641"), }, { - Rel: "data", - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/814641", + Rel: String("data"), + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/814641"), }, }, } @@ -89,47 +91,48 @@ func TestClient_CreateRTPStream(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := RTPStream{ - TestID: 814641, - Enabled: 1, - ModifiedBy: "ThousandEyes (support@thousandeyes.com)", - ModifiedDate: "2019-02-06 01:09:56", - CreatedBy: "ThousandEyes (support@thousandeyes.com)", - CreatedDate: "2018-11-03 19:09:42", - SavedEvent: 0, - TestName: "RTP Stream - AWS RTP server", - Interval: 120, - AlertsEnabled: 0, - DSCPID: 46, - Duration: 5, - BGPMeasurements: 1, - UsePublicBGP: 1, - NumPathTraces: 3, - Codec: "G.711 @ 64 Kbps", + TestID: Int64(814641), + Enabled: Int(1), + ModifiedBy: String("ThousandEyes (support@thousandeyes.com)"), + ModifiedDate: String("2019-02-06 01:09:56"), + CreatedBy: String("ThousandEyes (support@thousandeyes.com)"), + CreatedDate: String("2018-11-03 19:09:42"), + SavedEvent: Int(0), + TestName: String("RTP Stream - AWS RTP server"), + Interval: Int(120), + AlertsEnabled: Int(0), + DSCPID: Int(46), + Duration: Int(5), + BGPMeasurements: Int(1), + UsePublicBGP: Int(1), + NumPathTraces: Int(3), + Codec: String("G.711 @ 64 Kbps"), + CodecID: Int(0), APILinks: APILinks{ { - Href: "https://api.thousandeyes.com/v6/tests/814641", - Rel: "self", + Href: String("https://api.thousandeyes.com/v6/tests/814641"), + Rel: String("self"), }, { - Href: "https://api.thousandeyes.com/v6/voice/sip-server/814641", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/voice/sip-server/814641"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/voice/rtp-stream/814641", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/voice/rtp-stream/814641"), + Rel: String("data"), }, { - Href: "https://api.thousandeyes.com/v6/net/bgp-metrics/814641", - Rel: "data", + Href: String("https://api.thousandeyes.com/v6/net/bgp-metrics/814641"), + Rel: String("data"), }, }, } create := RTPStream{ - TestName: "test1", - DSCPID: 46, - Duration: 5, - Interval: 120, - Codec: "G.711 @ 64 Kbps", + TestName: String("test1"), + DSCPID: Int(46), + Duration: Int(5), + Interval: Int(120), + Codec: String("G.711 @ 64 Kbps"), } res, err := client.CreateRTPStream(create) teardown() @@ -165,23 +168,23 @@ func TestClient_UpdateRTPStream(t *testing.T) { var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"} id := 1 sipS := RTPStream{ - TestName: "RTP Stream - AWS RTP server", - CodecID: 0, - Codec: "G.711 @ 64 Kbps", - JitterBuffer: 40, + TestName: String("RTP Stream - AWS RTP server"), + CodecID: Int(0), + Codec: String("G.711 @ 64 Kbps"), + JitterBuffer: Int(40), } res, err := client.UpdateRTPStream(id, sipS) if err != nil { t.Fatal(err) } - expected := RTPStream{Interval: 120, TestID: 1234, Codec: "G.711 @ 64 Kbps", TestName: "RTP Stream - AWS RTP server", CodecID: 0, JitterBuffer: 40} + expected := RTPStream{AlertsEnabled: Int(0), Interval: Int(120), TestID: Int64(1234), Codec: String("G.711 @ 64 Kbps"), TestName: String("RTP Stream - AWS RTP server"), CodecID: Int(0), JitterBuffer: Int(40)} assert.Equal(t, &expected, res) } func TestRTPStream_AddAgent(t *testing.T) { - test := RTPStream{TestName: "test", Agents: Agents{}} - expected := RTPStream{TestName: "test", Agents: []Agent{{AgentID: 1}}} + test := RTPStream{TestName: String("test"), Agents: Agents{}} + expected := RTPStream{TestName: String("test"), Agents: []Agent{{AgentID: Int(1)}}} test.AddAgent(1) assert.Equal(t, expected, test) } @@ -211,7 +214,7 @@ func TestClient_GetRTPStreamStatusCode(t *testing.T) { _, err := client.GetRTPStream(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateRTPStreamStatusCode(t *testing.T) { @@ -224,7 +227,7 @@ func TestClient_CreateRTPStreamStatusCode(t *testing.T) { }) _, err := client.CreateRTPStream(RTPStream{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateRTPStreamStatusCode(t *testing.T) { @@ -237,7 +240,7 @@ func TestClient_UpdateRTPStreamStatusCode(t *testing.T) { }) _, err := client.UpdateRTPStream(1, RTPStream{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteRTPStreamStatusCode(t *testing.T) { @@ -250,5 +253,5 @@ func TestClient_DeleteRTPStreamStatusCode(t *testing.T) { }) err := client.DeleteRTPStream(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } diff --git a/web_transaction.go b/web_transaction.go index 13f1eab..0d25f82 100644 --- a/web_transaction.go +++ b/web_transaction.go @@ -7,53 +7,53 @@ import ( // WebTransaction - a web transcation test type WebTransaction struct { // Common test fields - AlertsEnabled int `json:"alertsEnabled,omitempty"` - AlertRules []AlertRule `json:"alertRules,omitempty"` + AlertsEnabled *int `json:"alertsEnabled,omitempty"` + AlertRules []AlertRule `json:"alertRules"` APILinks []APILink `json:"apiLinks,omitempty"` - CreatedBy string `json:"createdBy,omitempty"` - CreatedDate string `json:"createdDate,omitempty"` - Description string `json:"description,omitempty"` - Enabled int `json:"enabled,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Enabled *int `json:"enabled,omitempty"` Groups []GroupLabel `json:"groups,omitempty"` - ModifiedBy string `json:"modifiedBy,omitempty"` - ModifiedDate string `json:"modifiedDate,omitempty"` - SavedEvent int `json:"savedEvent,omitempty"` + ModifiedBy *string `json:"modifiedBy,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + SavedEvent *int `json:"savedEvent,omitempty"` SharedWithAccounts []SharedWithAccount `json:"sharedWithAccounts,omitempty"` - TestID int `json:"testId,omitempty"` - TestName string `json:"testName,omitempty"` - Type string `json:"type,omitempty"` - // LiveShare is common to all tests except DNS+ - LiveShare int `json:"liveShare,omitempty"` + TestID *int64 `json:"testId,omitempty"` + TestName *string `json:"testName,omitempty"` + Type *string `json:"type,omitempty"` + LiveShare *int `json:"liveShare,omitempty"` + // Fields unique to this test Agents Agents `json:"agents,omitempty"` - AuthType string `json:"authType,omitempty"` - BandwidthMeasurements int `json:"bandwidthMeasurements,omitempty"` - ContentRegex string `json:"contentRegex,omitempty"` + AuthType *string `json:"authType,omitempty"` + BandwidthMeasurements *int `json:"bandwidthMeasurements,omitempty"` + ContentRegex *string `json:"contentRegex,omitempty"` Credentials []int `json:"credentials,omitempty"` CustomHeaders CustomHeaders `json:"customHeaders,omitempty"` - DesiredStatusCode string `json:"desiredStatusCode,omitempty"` - HTTPTargetTime int `json:"httpTargetTime,omitempty"` - HTTPTimeLimit int `json:"httpTimeLimit,omitempty"` - HTTPVersion int `json:"httpVersion,omitempty"` - IncludeHeaders int `json:"includeHeaders,omitempty"` - Interval int `json:"interval,omitempty"` - MTUMeasurements int `json:"mtuMeasurements,omitempty"` - NetworkMeasurements int `json:"networkMeasurements,omitempty"` - NumPathTraces int `json:"numPathTraces,omitempty"` - Password string `json:"password,omitempty"` - PathTraceMode string `json:"pathTraceMode,omitempty"` - ProbeMode string `json:"probeMode,omitempty"` - Protocol string `json:"protocol,omitempty"` - SSLVersionID int `json:"sslVersionId,omitempty"` - SubInterval int `json:"subinterval,omitempty"` - TargetTime int `json:"targetTime,omitempty"` - TimeLimit int `json:"timeLimit,omitempty"` - TransactionScript string `json:"transactionScript,omitempty"` - URL string `json:"url,omitempty"` - UseNTLM int `json:"useNtlm,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Username string `json:"username,omitempty"` - VerifyCertificate int `json:"verifyCertificate,omitempty"` + DesiredStatusCode *string `json:"desiredStatusCode,omitempty"` + HTTPTargetTime *int `json:"httpTargetTime,omitempty"` + HTTPTimeLimit *int `json:"httpTimeLimit,omitempty"` + HTTPVersion *int `json:"httpVersion,omitempty"` + IncludeHeaders *int `json:"includeHeaders,omitempty"` + Interval *int `json:"interval,omitempty"` + MTUMeasurements *int `json:"mtuMeasurements,omitempty"` + NetworkMeasurements *int `json:"networkMeasurements,omitempty"` + NumPathTraces *int `json:"numPathTraces,omitempty"` + Password *string `json:"password,omitempty"` + PathTraceMode *string `json:"pathTraceMode,omitempty"` + ProbeMode *string `json:"probeMode,omitempty"` + Protocol *string `json:"protocol,omitempty"` + SSLVersionID *int `json:"sslVersionId,omitempty"` + SubInterval *int `json:"subinterval,omitempty"` + TargetTime *int `json:"targetTime,omitempty"` + TimeLimit *int `json:"timeLimit,omitempty"` + TransactionScript *string `json:"transactionScript,omitempty"` + URL *string `json:"url,omitempty"` + UseNTLM *int `json:"useNtlm,omitempty"` + UserAgent *string `json:"userAgent,omitempty"` + Username *string `json:"username,omitempty"` + VerifyCertificate *int `json:"verifyCertificate,omitempty"` } // CreateWebTransaction - Create a web transaction test diff --git a/web_transaction_test.go b/web_transaction_test.go index 09905cc..c6c1fec 100644 --- a/web_transaction_test.go +++ b/web_transaction_test.go @@ -20,15 +20,15 @@ func TestClient_CreateWebTransaction(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := WebTransaction{ - TestID: 1, - TestName: "test", - CreatedDate: "2020-02-06 15:28:07", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - TransactionScript: "script here", + TestID: Int64(1), + TestName: String("test"), + CreatedDate: String("2020-02-06 15:28:07"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + TransactionScript: String("script here"), } create := WebTransaction{ - TestName: "test", - TransactionScript: "script here", + TestName: String("test"), + TransactionScript: String("script here"), } res, err := client.CreateWebTransaction(create) teardown() @@ -49,11 +49,11 @@ func TestClient_GetWebTransaction(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := WebTransaction{ - TestID: 1, - TestName: "test", - CreatedDate: "2020-02-06 15:28:07", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - TransactionScript: "script here", + TestID: Int64(1), + TestName: String("test"), + CreatedDate: String("2020-02-06 15:28:07"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + TransactionScript: String("script here"), } res, err := client.GetWebTransaction(1) teardown() @@ -91,14 +91,14 @@ func TestClient_UpdateWebTransaction(t *testing.T) { // Define expected values from the API (based on the JSON we print out above) expected := WebTransaction{ - TestID: 1, - TestName: "test", - CreatedDate: "2020-02-06 15:28:07", - CreatedBy: "William Fleming (wfleming@grumpysysadm.com)", - TransactionScript: "new script here", + TestID: Int64(1), + TestName: String("test"), + CreatedDate: String("2020-02-06 15:28:07"), + CreatedBy: String("William Fleming (wfleming@grumpysysadm.com)"), + TransactionScript: String("new script here"), } update := WebTransaction{ - TransactionScript: "new script here", + TransactionScript: String("new script here"), } res, err := client.UpdateWebTransaction(1, update) teardown() @@ -144,7 +144,7 @@ func TestClient_GetWebTransactionStatusCode(t *testing.T) { _, err := client.GetWebTransaction(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_CreateWebTransactionStatusCode(t *testing.T) { @@ -157,7 +157,7 @@ func TestClient_CreateWebTransactionStatusCode(t *testing.T) { }) _, err := client.CreateWebTransaction(WebTransaction{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_UpdateWebTransactionStatusCode(t *testing.T) { @@ -170,7 +170,7 @@ func TestClient_UpdateWebTransactionStatusCode(t *testing.T) { }) _, err := client.UpdateWebTransaction(1, WebTransaction{}) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") } func TestClient_DeleteWebTransactionStatusCode(t *testing.T) { @@ -183,5 +183,5 @@ func TestClient_DeleteWebTransactionStatusCode(t *testing.T) { }) err := client.DeleteWebTransaction(1) teardown() - assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") + assert.EqualError(t, err, "Failed call API endpoint. HTTP response code: 400. Error: &{}") }