Skip to content

Commit

Permalink
tests: added test for httpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-cardenas-coding committed Dec 28, 2024
1 parent b8961d0 commit 34d9ede
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ time=05/23/22 level=info msg="124 MB of storage space will be removed in an actu
time=05/23/22 level=info msg="Job Duration Time: 1.454406s"
```

### Nightly Release

A nightly release is available as a Docker image. The nightly release is a snapshot of the main branch and automatically updated with the latest minor depedencies updates.

```shell
docker pull ghcr.io/karl-cardenas-coding/go-lambda-cleanup:nightly
```



## Usage

```shell
Expand Down
45 changes: 45 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package cmd

import (
"context"
"crypto/tls"
"fmt"
"net/http"
"os"
"testing"

Expand Down Expand Up @@ -371,3 +373,46 @@ func TestNoLambdas(t *testing.T) {

})
}

func TestCreateHTTPClient(t *testing.T) {
// Set an environment variable for the proxy
os.Setenv("HTTP_PROXY", "http://proxy.example.com")
defer os.Unsetenv("HTTP_PROXY")

client := createHTTPClient()

// Check if the client is not nil
if client == nil {
t.Fatalf("Expected non-nil HTTP client")
}

// Check if the transport is of type *http.Transport
transport, ok := client.Transport.(*http.Transport)
if !ok {
t.Fatalf("Expected transport to be of type *http.Transport, got %T", client.Transport)
}

if transport != nil {
t.Fatalf("Expected non-nil transport")
}

// Check if the minimum TLS version is set to TLS 1.2
if transport.TLSClientConfig.MinVersion != tls.VersionTLS12 {
t.Errorf("Expected MinVersion to be TLS 1.2, got %v", transport.TLSClientConfig.MinVersion)
}

// Check if ForceAttemptHTTP2 is set to true
if !transport.ForceAttemptHTTP2 {
t.Errorf("Expected ForceAttemptHTTP2 to be true, got %v", transport.ForceAttemptHTTP2)
}

// Check if Proxy is set correctly from the environment
req, _ := http.NewRequest("GET", "http://example.com", nil)
proxyURL, err := transport.Proxy(req)
if err != nil {
t.Fatalf("Expected no error from Proxy function, got %v", err)
}
if proxyURL.String() != "http://proxy.example.com" {
t.Errorf("Expected proxy URL to be http://proxy.example.com, got %v", proxyURL)
}
}

0 comments on commit 34d9ede

Please sign in to comment.