Skip to content

Commit

Permalink
Merge pull request #71 from anuraaga/reformat-code
Browse files Browse the repository at this point in the history
  • Loading branch information
fzipi authored Sep 8, 2022
2 parents 23cca65 + 2f34af4 commit fe1d01d
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 115 deletions.
6 changes: 3 additions & 3 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"os"

"github.com/fzipi/go-ftw/test"
"github.com/rs/zerolog/log"

"github.com/kyokomi/emoji"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

"github.com/fzipi/go-ftw/test"
)

// checkCmd represents the check command
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"log"
"os"

"github.com/fzipi/go-ftw/config"

"github.com/rs/zerolog"
"github.com/spf13/cobra"

"github.com/fzipi/go-ftw/config"
)

var (
Expand Down
200 changes: 100 additions & 100 deletions ftwhttp/client_test.go
Original file line number Diff line number Diff line change
@@ -1,152 +1,152 @@
package ftwhttp

import (
"testing"
"testing"
)

func TestNewClient(t *testing.T) {
c := NewClient(NewClientConfig())
c := NewClient(NewClientConfig())

if c.Jar == nil {
t.Logf("Error creating Client")
}
if c.Jar == nil {
t.Logf("Error creating Client")
}
}

func TestConnectDestinationHTTPS(t *testing.T) {
d := &Destination{
DestAddr: "example.com",
Port: 443,
Protocol: "https",
}

c := NewClient(NewClientConfig())

err := c.NewConnection(*d)
if err != nil {
t.Logf("This should not error")
}

if c.Transport.protocol != "https" {
t.Logf("Error connecting to example.com using https")
}
d := &Destination{
DestAddr: "example.com",
Port: 443,
Protocol: "https",
}

c := NewClient(NewClientConfig())

err := c.NewConnection(*d)
if err != nil {
t.Logf("This should not error")
}

if c.Transport.protocol != "https" {
t.Logf("Error connecting to example.com using https")
}
}

func TestDoRequest(t *testing.T) {
d := &Destination{
DestAddr: "httpbin.org",
Port: 443,
Protocol: "https",
}
d := &Destination{
DestAddr: "httpbin.org",
Port: 443,
Protocol: "https",
}

c := NewClient(NewClientConfig())
c := NewClient(NewClientConfig())

req := generateBaseRequestForTesting()
req := generateBaseRequestForTesting()

err := c.NewConnection(*d)
if err != nil {
t.Logf("This should not error")
}
err := c.NewConnection(*d)
if err != nil {
t.Logf("This should not error")
}

_, err = c.Do(*req)
_, err = c.Do(*req)

if err == nil {
t.Logf("This should return error")
}
if err == nil {
t.Logf("This should return error")
}
}

func TestGetTrackedTime(t *testing.T) {
d := &Destination{
DestAddr: "httpbin.org",
Port: 443,
Protocol: "https",
}
d := &Destination{
DestAddr: "httpbin.org",
Port: 443,
Protocol: "https",
}

c := NewClient(NewClientConfig())
c := NewClient(NewClientConfig())

rl := &RequestLine{
Method: "POST",
URI: "/post",
Version: "HTTP/1.1",
}
rl := &RequestLine{
Method: "POST",
URI: "/post",
Version: "HTTP/1.1",
}

h := Header{"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost"}
h := Header{"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost"}

data := []byte(`test=me&one=two&one=twice`)
req := NewRequest(rl, h, data, true)
data := []byte(`test=me&one=two&one=twice`)
req := NewRequest(rl, h, data, true)

err := c.NewConnection(*d)
if err != nil {
t.Logf("This should not error")
}
err := c.NewConnection(*d)
if err != nil {
t.Logf("This should not error")
}

c.StartTrackingTime()
c.StartTrackingTime()

resp, err := c.Do(*req)
resp, err := c.Do(*req)

c.StopTrackingTime()
c.StopTrackingTime()

if err != nil {
t.Logf("This should not error")
}
if err != nil {
t.Logf("This should not error")
}

if resp.Parsed.StatusCode != 200 {
t.Logf("Error in calling website")
}
if resp.Parsed.StatusCode != 200 {
t.Logf("Error in calling website")
}

rtt := c.GetRoundTripTime()
rtt := c.GetRoundTripTime()

if rtt.RoundTripDuration() < 0 {
t.Logf("Error getting RTT")
}
if rtt.RoundTripDuration() < 0 {
t.Logf("Error getting RTT")
}
}

func TestClientMultipartFormDataRequest(t *testing.T) {
d := &Destination{
DestAddr: "httpbin.org",
Port: 443,
Protocol: "https",
}

c := NewClient(NewClientConfig())

rl := &RequestLine{
Method: "POST",
URI: "/post",
Version: "HTTP/1.1",
}

h := Header{
"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost",
"Content-Type": "multipart/form-data; boundary=--------397236876",
}

data := []byte(`----------397236876
d := &Destination{
DestAddr: "httpbin.org",
Port: 443,
Protocol: "https",
}

c := NewClient(NewClientConfig())

rl := &RequestLine{
Method: "POST",
URI: "/post",
Version: "HTTP/1.1",
}

h := Header{
"Accept": "*/*", "User-Agent": "go-ftw test agent", "Host": "localhost",
"Content-Type": "multipart/form-data; boundary=--------397236876",
}

data := []byte(`----------397236876
Content-Disposition: form-data; name="fileRap"; filename="test.txt"
Content-Type: text/plain
Some-file-test-here
----------397236876--`)

req := NewRequest(rl, h, data, true)
req := NewRequest(rl, h, data, true)

err := c.NewConnection(*d)
err := c.NewConnection(*d)

if err != nil {
t.Logf("This should not error")
}
if err != nil {
t.Logf("This should not error")
}

c.StartTrackingTime()
c.StartTrackingTime()

resp, err := c.Do(*req)
resp, err := c.Do(*req)

c.StopTrackingTime()
c.StopTrackingTime()

if err != nil {
t.Logf("This should not error")
}
if err != nil {
t.Logf("This should not error")
}

if resp.Parsed.StatusCode != 200 {
t.Logf("Error in calling website")
if resp.Parsed.StatusCode != 200 {
t.Logf("Error in calling website")
}

}
4 changes: 2 additions & 2 deletions ftwhttp/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"net/url"
"strings"

"github.com/fzipi/go-ftw/utils"

"github.com/rs/zerolog/log"

"github.com/fzipi/go-ftw/utils"
)

// ToString converts the request line to string for sending it in the wire
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"time"
_ "time/tzdata"

"github.com/fzipi/go-ftw/cmd"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/fzipi/go-ftw/cmd"
)

// nolint: gochecknoglobals
Expand Down
8 changes: 4 additions & 4 deletions runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"regexp"
"time"

"github.com/google/uuid"
"github.com/kyokomi/emoji"
"github.com/rs/zerolog/log"

"github.com/fzipi/go-ftw/check"
"github.com/fzipi/go-ftw/config"
"github.com/fzipi/go-ftw/ftwhttp"
"github.com/fzipi/go-ftw/test"
"github.com/fzipi/go-ftw/utils"
"github.com/fzipi/go-ftw/waflog"
"github.com/google/uuid"

"github.com/kyokomi/emoji"
"github.com/rs/zerolog/log"
)

// Run runs your tests with the specified Config. Returns error if some test failed
Expand Down
1 change: 0 additions & 1 deletion test/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package test

import (
"bytes"

"text/template"

"github.com/Masterminds/sprig"
Expand Down
3 changes: 2 additions & 1 deletion waflog/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"os"
"regexp"

"github.com/fzipi/go-ftw/config"
"github.com/icza/backscanner"
"github.com/rs/zerolog/log"

"github.com/fzipi/go-ftw/config"
)

// Contains looks in logfile for regex
Expand Down
3 changes: 2 additions & 1 deletion waflog/waflog.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package waflog
import (
"os"

"github.com/fzipi/go-ftw/config"
"github.com/rs/zerolog/log"

"github.com/fzipi/go-ftw/config"
)

// NewFTWLogLines is the base struct for reading the log file
Expand Down

0 comments on commit fe1d01d

Please sign in to comment.