-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SYN-3922: add support for downtime configurations
- Loading branch information
1 parent
bf6a9b5
commit 1288938
Showing
11 changed files
with
737 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mode: set | ||
mode: set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2024 Splunk, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package syntheticsclientv2 | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
) | ||
|
||
func parseCreateDowntimeConfigurationV2Response(response string) (*DowntimeConfigurationV2Response, error) { | ||
|
||
var createDowntimeConfigurationV2 DowntimeConfigurationV2Response | ||
JSONResponse := []byte(response) | ||
err := json.Unmarshal(JSONResponse, &createDowntimeConfigurationV2) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &createDowntimeConfigurationV2, err | ||
} | ||
|
||
func (c Client) CreateDowntimeConfigurationV2(DowntimeConfigurationV2Details *DowntimeConfigurationV2Input) (*DowntimeConfigurationV2Response, *RequestDetails, error) { | ||
|
||
body, err := json.Marshal(DowntimeConfigurationV2Details) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
details, err := c.makePublicAPICall("POST", "/downtime_configurations", bytes.NewBuffer(body), nil) | ||
if err != nil { | ||
return nil, details, err | ||
} | ||
|
||
newDowntimeConfigurationV2, err := parseCreateDowntimeConfigurationV2Response(details.ResponseBody) | ||
if err != nil { | ||
return newDowntimeConfigurationV2, details, err | ||
} | ||
|
||
return newDowntimeConfigurationV2, details, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//go:build unit_tests | ||
// +build unit_tests | ||
|
||
// Copyright 2024 Splunk, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package syntheticsclientv2 | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
var ( | ||
createDowntimeConfigurationV2Body = `{"downtimeConfiguration":{"name":"dc test","description":"My super awesome test downtimeConfiguration","rule":"augment_data","testIds":[482],"startTime":"2024-05-16T20:23:00.000Z","endTime":"2024-05-16T20:38:00.000Z"}}` | ||
inputDowntimeConfigurationV2Data = DowntimeConfigurationV2Input{} | ||
) | ||
|
||
func TestCreateDowntimeConfigurationV2(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
testMux.HandleFunc("/downtime_configurations", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "POST") | ||
_, err := w.Write([]byte(createDowntimeConfigurationV2Body)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
|
||
err := json.Unmarshal([]byte(createDowntimeConfigurationV2Body), &inputDowntimeConfigurationV2Data) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
resp, _, err := testClient.CreateDowntimeConfigurationV2(&inputDowntimeConfigurationV2Data) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
fmt.Println(resp) | ||
|
||
if !reflect.DeepEqual(resp.DowntimeConfiguration.ID, inputDowntimeConfigurationV2Data.DowntimeConfiguration.ID) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp.DowntimeConfiguration.ID, inputDowntimeConfigurationV2Data.DowntimeConfiguration.ID) | ||
} | ||
|
||
if !reflect.DeepEqual(resp.DowntimeConfiguration.Name, inputDowntimeConfigurationV2Data.DowntimeConfiguration.Name) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp.DowntimeConfiguration.Name, inputDowntimeConfigurationV2Data.DowntimeConfiguration.Name) | ||
} | ||
|
||
if !reflect.DeepEqual(resp.DowntimeConfiguration.Description, inputDowntimeConfigurationV2Data.DowntimeConfiguration.Description) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp.DowntimeConfiguration.Description, inputDowntimeConfigurationV2Data.DowntimeConfiguration.Description) | ||
} | ||
|
||
if !reflect.DeepEqual(resp.DowntimeConfiguration.Rule, inputDowntimeConfigurationV2Data.DowntimeConfiguration.Rule) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp.DowntimeConfiguration.Rule, inputDowntimeConfigurationV2Data.DowntimeConfiguration.Rule) | ||
} | ||
|
||
if !reflect.DeepEqual(resp.DowntimeConfiguration.Starttime, inputDowntimeConfigurationV2Data.DowntimeConfiguration.Starttime) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp.DowntimeConfiguration.Starttime, inputDowntimeConfigurationV2Data.DowntimeConfiguration.Starttime) | ||
} | ||
|
||
if !reflect.DeepEqual(resp.DowntimeConfiguration.Endtime, inputDowntimeConfigurationV2Data.DowntimeConfiguration.Endtime) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp.DowntimeConfiguration.Endtime, inputDowntimeConfigurationV2Data.DowntimeConfiguration.Endtime) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 Splunk, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package syntheticsclientv2 | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
func (c Client) DeleteDowntimeConfigurationV2(id int) (int, error) { | ||
requestDetails, err := c.makePublicAPICall("DELETE", fmt.Sprintf("/downtime_configurations/%d", id), bytes.NewBufferString("{}"), nil) | ||
if err != nil { | ||
return 1, err | ||
} | ||
var status = requestDetails.StatusCode | ||
|
||
fmt.Println(status) | ||
|
||
if status >= 300 || status < 200 { | ||
errorMsg := fmt.Sprintf("error: Response code %v. Expecting 2XX.", strconv.Itoa(status)) | ||
return status, errors.New(errorMsg) | ||
} | ||
|
||
return status, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//go:build unit_tests | ||
// +build unit_tests | ||
|
||
// Copyright 2024 Splunk, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package syntheticsclientv2 | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
var ( | ||
deleteDowntimeConfigurationV2RespBody = `` | ||
) | ||
|
||
func TestDeleteDowntimeConfigurationV2(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
testMux.HandleFunc("/downtime_configurations/19", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "DELETE") | ||
_, err := w.Write([]byte(deleteDowntimeConfigurationV2RespBody)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
|
||
resp, err := testClient.DeleteDowntimeConfigurationV2(19) | ||
if err != nil { | ||
fmt.Println(resp) | ||
t.Fatal(err) | ||
} | ||
fmt.Println(resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2024 Splunk, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package syntheticsclientv2 | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
func parseDowntimeConfigurationV2Response(response string) (*DowntimeConfigurationV2Response, error) { | ||
// Parse the response and return the check object | ||
var check DowntimeConfigurationV2Response | ||
err := json.Unmarshal([]byte(response), &check) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &check, err | ||
} | ||
|
||
func (c Client) GetDowntimeConfigurationV2(id int) (*DowntimeConfigurationV2Response, *RequestDetails, error) { | ||
|
||
details, err := c.makePublicAPICall("GET", | ||
fmt.Sprintf("/downtime_configurations/%d", id), | ||
bytes.NewBufferString("{}"), | ||
nil) | ||
|
||
if err != nil { | ||
return nil, details, err | ||
} | ||
|
||
check, err := parseDowntimeConfigurationV2Response(details.ResponseBody) | ||
if err != nil { | ||
return check, details, err | ||
} | ||
|
||
return check, details, nil | ||
} | ||
|
||
func parseDowntimeConfigurationsV2Response(response string) (*DowntimeConfigurationsV2Response, error) { | ||
// Parse the response and return the check object | ||
var check DowntimeConfigurationsV2Response | ||
err := json.Unmarshal([]byte(response), &check) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &check, err | ||
} | ||
|
||
func (c Client) GetDowntimeConfigurationsV2() (*DowntimeConfigurationsV2Response, *RequestDetails, error) { | ||
|
||
details, err := c.makePublicAPICall("GET", | ||
"/downtime_configurations", | ||
bytes.NewBufferString("{}"), | ||
nil) | ||
|
||
if err != nil { | ||
return nil, details, err | ||
} | ||
|
||
check, err := parseDowntimeConfigurationsV2Response(details.ResponseBody) | ||
if err != nil { | ||
return check, details, err | ||
} | ||
|
||
return check, details, nil | ||
} |
Oops, something went wrong.