Skip to content

Commit

Permalink
internal/civisibility/utils/net: changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyredondo committed Sep 18, 2024
1 parent 27ffcdc commit 7c60549
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 59 deletions.
7 changes: 3 additions & 4 deletions internal/civisibility/utils/net/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type (
}
)

var _ Client = &client{}

func NewClient() Client {
ciTags := utils.GetCITags()

Expand Down Expand Up @@ -118,10 +120,7 @@ func NewClient() Client {
defaultHeaders["dd-api-key"] = APIKeyValue

// Check for a custom agentless URL.
agentlessURL := ""
if v := os.Getenv(constants.CIVisibilityAgentlessURLEnvironmentVariable); v != "" {
agentlessURL = v
}
agentlessURL := os.Getenv(constants.CIVisibilityAgentlessURLEnvironmentVariable)

if agentlessURL == "" {
// Use the standard agentless URL format.
Expand Down
4 changes: 2 additions & 2 deletions internal/civisibility/utils/net/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ func TestNewClient_CustomAgentlessURL(t *testing.T) {
func TestClient_getUrlPath_Agentless(t *testing.T) {
c := &client{
agentless: true,
baseUrl: "https://api.datadoghq.com",
baseUrl: "https://api.customhost.com",
}

urlPath := c.getUrlPath("some/path")
expected := "https://api.datadoghq.com/some/path"
expected := "https://api.customhost.com/some/path"
if urlPath != expected {
t.Errorf("Expected urlPath '%s', got '%s'", expected, urlPath)
}
Expand Down
26 changes: 13 additions & 13 deletions internal/civisibility/utils/net/efd_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ const (

type (
efdRequest struct {
Data efdRequestHeader `json:"data,omitempty"`
Data efdRequestHeader `json:"data"`
}

efdRequestHeader struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Attributes EfdRequestData `json:"attributes,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
Attributes EfdRequestData `json:"attributes"`
}

EfdRequestData struct {
Service string `json:"service,omitempty"`
Env string `json:"env,omitempty"`
RepositoryURL string `json:"repository_url,omitempty"`
Configurations testConfigurations `json:"configurations,omitempty"`
Service string `json:"service"`
Env string `json:"env"`
RepositoryURL string `json:"repository_url"`
Configurations testConfigurations `json:"configurations"`
}

efdResponse struct {
Data struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Attributes EfdResponseData `json:"attributes,omitempty"`
} `json:"data,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
Attributes EfdResponseData `json:"attributes"`
} `json:"data"`
}

EfdResponseData struct {
Tests EfdResponseDataModules `json:"tests,omitempty"`
Tests EfdResponseDataModules `json:"tests"`
}

EfdResponseDataModules map[string]EfdResponseDataSuites
Expand Down
2 changes: 1 addition & 1 deletion internal/civisibility/utils/net/efd_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestEfdApiRequestFailToUnmarshal(t *testing.T) {

func TestEfdApiRequestFailToGet(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "failed to read body", http.StatusInternalServerError)
http.Error(w, "internal processing error", http.StatusInternalServerError)
}))
defer server.Close()

Expand Down
4 changes: 2 additions & 2 deletions internal/civisibility/utils/net/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func NewRequestHandlerWithClient(client *http.Client) *RequestHandler {
// SendRequest sends an HTTP request based on the provided configuration.
func (rh *RequestHandler) SendRequest(config RequestConfig) (*Response, error) {
if config.MaxRetries <= 0 {
config.MaxRetries = 3 // Default retries
config.MaxRetries = DefaultMaxRetries // Default retries
}
if config.Backoff <= 0 {
config.Backoff = 1 * time.Second // Default backoff
config.Backoff = DefaultBackoff // Default backoff
}
if config.Method == "" {
return nil, errors.New("HTTP method is required")
Expand Down
10 changes: 5 additions & 5 deletions internal/civisibility/utils/net/searchcommits_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const (

type (
searchCommits struct {
Data []searchCommitsData `json:"data,omitempty"`
Meta searchCommitsMeta `json:"meta,omitempty"`
Data []searchCommitsData `json:"data"`
Meta searchCommitsMeta `json:"meta"`
}
searchCommitsData struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
}
searchCommitsMeta struct {
RepositoryURL string `json:"repository_url,omitempty"`
RepositoryURL string `json:"repository_url"`
}
)

Expand Down
2 changes: 1 addition & 1 deletion internal/civisibility/utils/net/searchcommits_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestSearchCommitsApiRequestFailToUnmarshal(t *testing.T) {

func TestSearchCommitsApiRequestFailToGet(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "failed to read body", http.StatusInternalServerError)
http.Error(w, "internal processing error", http.StatusInternalServerError)
}))
defer server.Close()

Expand Down
10 changes: 5 additions & 5 deletions internal/civisibility/utils/net/sendpackfiles_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ const (

type (
pushedShaBody struct {
Data pushedShaData `json:"data,omitempty"`
Meta pushedShaMeta `json:"meta,omitempty"`
Data pushedShaData `json:"data"`
Meta pushedShaMeta `json:"meta"`
}
pushedShaData struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
}
pushedShaMeta struct {
RepositoryURL string `json:"repository_url,omitempty"`
RepositoryURL string `json:"repository_url"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions internal/civisibility/utils/net/sendpackfiles_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestSendPackFilesApiRequestFailToUnmarshal(t *testing.T) {

func TestSendPackFilesApiRequestFailToGet(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "failed to read body", http.StatusInternalServerError)
http.Error(w, "internal processing error", http.StatusInternalServerError)
}))
defer server.Close()

Expand All @@ -114,7 +114,7 @@ func TestSendPackFilesApiRequestFailToGet(t *testing.T) {

func TestSendPackFilesApiRequestFileError(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "failed to read body", http.StatusInternalServerError)
http.Error(w, "internal processing error", http.StatusInternalServerError)
}))
defer server.Close()

Expand All @@ -135,7 +135,7 @@ func TestSendPackFilesApiRequestFileError(t *testing.T) {

func TestSendPackFilesApiRequestNoFile(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "failed to read body", http.StatusInternalServerError)
http.Error(w, "internal processing error", http.StatusInternalServerError)
}))
defer server.Close()

Expand Down
40 changes: 20 additions & 20 deletions internal/civisibility/utils/net/settings_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ const (

type (
settingsRequest struct {
Data settingsRequestHeader `json:"data,omitempty"`
Data settingsRequestHeader `json:"data"`
}

settingsRequestHeader struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Attributes SettingsRequestData `json:"attributes,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
Attributes SettingsRequestData `json:"attributes"`
}

SettingsRequestData struct {
Expand All @@ -36,28 +36,28 @@ type (

settingsResponse struct {
Data struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Attributes SettingsResponseData `json:"attributes,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
Attributes SettingsResponseData `json:"attributes"`
} `json:"data,omitempty"`
}

SettingsResponseData struct {
CodeCoverage bool `json:"code_coverage,omitempty"`
CodeCoverage bool `json:"code_coverage"`
EarlyFlakeDetection struct {
Enabled bool `json:"enabled,omitempty"`
Enabled bool `json:"enabled"`
SlowTestRetries struct {
One0S int `json:"10s,omitempty"`
Three0S int `json:"30s,omitempty"`
FiveM int `json:"5m,omitempty"`
FiveS int `json:"5s,omitempty"`
} `json:"slow_test_retries,omitempty"`
FaultySessionThreshold int `json:"faulty_session_threshold,omitempty"`
} `json:"early_flake_detection,omitempty"`
FlakyTestRetriesEnabled bool `json:"flaky_test_retries_enabled,omitempty"`
ItrEnabled bool `json:"itr_enabled,omitempty"`
RequireGit bool `json:"require_git,omitempty"`
TestsSkipping bool `json:"tests_skipping,omitempty"`
TenS int `json:"10s"`
ThirtyS int `json:"30s"`
FiveM int `json:"5m"`
FiveS int `json:"5s"`
} `json:"slow_test_retries"`
FaultySessionThreshold int `json:"faulty_session_threshold"`
} `json:"early_flake_detection"`
FlakyTestRetriesEnabled bool `json:"flaky_test_retries_enabled"`
ItrEnabled bool `json:"itr_enabled"`
RequireGit bool `json:"require_git"`
TestsSkipping bool `json:"tests_skipping"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions internal/civisibility/utils/net/settings_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func TestSettingsApiRequest(t *testing.T) {
expectedResponse.Data.Attributes.EarlyFlakeDetection.FaultySessionThreshold = 30
expectedResponse.Data.Attributes.EarlyFlakeDetection.Enabled = true
expectedResponse.Data.Attributes.EarlyFlakeDetection.SlowTestRetries.FiveS = 25
expectedResponse.Data.Attributes.EarlyFlakeDetection.SlowTestRetries.One0S = 20
expectedResponse.Data.Attributes.EarlyFlakeDetection.SlowTestRetries.Three0S = 10
expectedResponse.Data.Attributes.EarlyFlakeDetection.SlowTestRetries.TenS = 20
expectedResponse.Data.Attributes.EarlyFlakeDetection.SlowTestRetries.ThirtyS = 10
expectedResponse.Data.Attributes.EarlyFlakeDetection.SlowTestRetries.FiveM = 5

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestSettingsApiRequestFailToUnmarshal(t *testing.T) {

func TestSettingsApiRequestFailToGet(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "failed to read body", http.StatusInternalServerError)
http.Error(w, "internal processing error", http.StatusInternalServerError)
}))
defer server.Close()

Expand Down

0 comments on commit 7c60549

Please sign in to comment.