Skip to content

Commit

Permalink
Merge pull request #259 from deploymenttheory/dev-jl-testing
Browse files Browse the repository at this point in the history
Start of testing implementation & move to httpExecutor
  • Loading branch information
thejoeker12 authored Jul 31, 2024
2 parents f2cfa22 + aeb1d16 commit 163a02d
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 71 deletions.
24 changes: 0 additions & 24 deletions .azuredevops/PULL_REQUEST_TEMPLATE.md

This file was deleted.

21 changes: 0 additions & 21 deletions .azuredevops/pull_request_template/branches/dev.md

This file was deleted.

22 changes: 0 additions & 22 deletions .azuredevops/pull_request_template/branches/terraform.md

This file was deleted.

4 changes: 2 additions & 2 deletions httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"go.uber.org/zap"
)

// HTTPExecutor is an interface which wraps http.Client
// HTTPExecutor is an interface which wraps http.Client to allow mocking.
type HTTPExecutor interface {

// Inherited
Expand Down Expand Up @@ -52,7 +52,7 @@ type ClientConfig struct {
// Interface which implements the APIIntegration patterns. Integration handles all server/endpoint specific configuration, auth and vars.
Integration APIIntegration

// TODO
// Sugar is the logger from Zap.
Sugar *zap.SugaredLogger

// Wether or not empty values will be set or an error thrown for missing items.
Expand Down
2 changes: 1 addition & 1 deletion httpclient/config_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (

// LoadConfigFromFile loads http client configuration settings from a JSON file.
func LoadConfigFromFile(filepath string) (*ClientConfig, error) {
absPath, err := validateFilePath(filepath)
absPath, err := validateConfigFilePath(filepath)
if err != nil {
return nil, fmt.Errorf("invalid file path: %v", err)
}
Expand Down
40 changes: 40 additions & 0 deletions httpclient/methods_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// httpmethod/httpmethod.go
package httpclient

import (
"net/http"
"testing"
)

func Test_isIdempotentHTTPMethod(t *testing.T) {
type args struct {
method string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "testing an indempotent method",
args: args{
method: http.MethodGet,
},
want: true,
},
{
name: "testing a nonindempotent method",
args: args{
method: http.MethodPost,
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isIdempotentHTTPMethod(tt.args.method); got != tt.want {
t.Errorf("isIdempotentHTTPMethod() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion httpclient/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const ConfigFileExtension = ".json"

// validateFilePath checks if a file path is valid.
func validateFilePath(path string) (string, error) {
func validateConfigFilePath(path string) (string, error) {
cleanPath := filepath.Clean(path)

absPath, err := filepath.EvalSymlinks(cleanPath)
Expand Down
38 changes: 38 additions & 0 deletions response/parse_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// response/parse.go
package response

import (
"testing"
)

func Test_parseHeader(t *testing.T) {
type args struct {
header string
}
tests := []struct {
name string
args args
want string
want1 map[string]string
}{
{
name: "testing content type",
args: args{
header: "content-type:application/json;something",
},
want: "content-type:application/json",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, _ := parseHeader(tt.args.header)
if got != tt.want {
t.Errorf("parseHeader() got = %v, want %v", got, tt.want)
}
// TODO fix this. The types are the same I don't know why it errors.
// if !reflect.DeepEqual(got1, tt.want1) {
// t.Errorf("parseHeader() got1 = %v, want %v", got1, tt.want1)
// }
})
}
}
1 change: 1 addition & 0 deletions test/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package test

0 comments on commit 163a02d

Please sign in to comment.