Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deployed_version): support for post requests #398

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/help_test.go
Original file line number Diff line number Diff line change
@@ -163,8 +163,9 @@ func testServiceURL(id string) *service.Service {
&latestver.LookupDefaults{}, &latestver.LookupDefaults{}),
DeployedVersionLookup: deployedver.New(
test.BoolPtr(false),
nil, nil,
nil, nil, nil,
"version",
"GET",
nil, "", nil, nil,
"https://valid.release-argus.io/json",
&deployedver.LookupDefaults{}, &deployedver.LookupDefaults{}),
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
"standard-version": "^9.5.0"
},
"dependencies": {
"@commitlint/cli": "^19.2.2",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2"
}
}
11 changes: 11 additions & 0 deletions service/deployed_version/gets.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,9 @@
package deployedver

import (
"io"
"strings"

"github.com/release-argus/Argus/util"
)

@@ -30,3 +33,11 @@ func (l *Lookup) GetAllowInvalidCerts() bool {
func (l *Lookup) GetURL() string {
return util.EvalEnvVars(l.URL)
}

// GetBody will return the Body of the Lookup.
func (l *Lookup) GetBody() io.Reader {
if l.Body == nil {
return nil
}
return strings.NewReader(*l.Body)
}
38 changes: 38 additions & 0 deletions service/deployed_version/gets_test.go
Original file line number Diff line number Diff line change
@@ -17,7 +17,10 @@
package deployedver

import (
"io"
"os"
"reflect"
"strings"
"testing"

"github.com/release-argus/Argus/test"
@@ -112,3 +115,38 @@ func TestLookup_GetURL(t *testing.T) {
})
}
}

func TestLookup_GetBody(t *testing.T) {
// GIVEN a Lookup
tests := map[string]struct {
body *string
want io.Reader
}{
"nil body": {
body: nil,
want: nil,
},
"non-nil body": {
body: test.StringPtr("test body"),
want: strings.NewReader("test body"),
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()

lookup := testLookup()
lookup.Body = tc.body

// WHEN GetBody is called
got := lookup.GetBody()

// THEN the function returns the correct result
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("want: %v\ngot: %v",
tc.want, got)
}
})
}
}
2 changes: 2 additions & 0 deletions service/deployed_version/help_test.go
Original file line number Diff line number Diff line change
@@ -43,7 +43,9 @@ func testLookup() (lookup *Lookup) {
test.BoolPtr(true),
nil,
nil,
nil,
"version",
"GET",
opt.New(
nil, "", test.BoolPtr(true),
&opt.OptionsDefaults{},
6 changes: 3 additions & 3 deletions service/deployed_version/query.go
Original file line number Diff line number Diff line change
@@ -189,23 +189,23 @@ func (l *Lookup) httpRequest(logFrom *util.LogFrom) (rawBody []byte, err error)
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}

req, err := http.NewRequest(http.MethodGet, l.GetURL(), nil)
// Create the request.
req, err := http.NewRequest(l.Method, l.GetURL(), l.GetBody())
if err != nil {
jLog.Error(err, logFrom, true)
return
}

// Set headers
req.Header.Set("Connection", "close")
for _, header := range l.Headers {
req.Header.Set(util.EvalEnvVars(header.Key), util.EvalEnvVars(header.Value))
}

// Basic auth
if l.BasicAuth != nil {
req.SetBasicAuth(util.EvalEnvVars(l.BasicAuth.Username), util.EvalEnvVars(l.BasicAuth.Password))
}

// Send the request.
client := &http.Client{Transport: customTransport}
resp, err := client.Do(req)
if err != nil {
Loading