Skip to content

Commit

Permalink
misc: add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
voidint committed Jul 1, 2024
1 parent 8397c8a commit c6882f3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
7 changes: 7 additions & 0 deletions collector/autoindex/autoindex_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,10 @@ func TestNewCollector(t *testing.T) {
})
}
}

func TestCollector_Name(t *testing.T) {
t.Run("Collector name", func(t *testing.T) {
c := &Collector{}
assert.Equal(t, Name, c.Name())
})
}
26 changes: 17 additions & 9 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package collector

import (
"reflect"
"io"
"net/http"
"strings"
"testing"

"github.com/agiledragon/gomonkey/v2"
"github.com/stretchr/testify/assert"
"github.com/voidint/g/collector/autoindex"
"github.com/voidint/g/collector/fancyindex"
"github.com/voidint/g/collector/official"
"github.com/voidint/g/pkg/errs"
)

func TestNewCollector(t *testing.T) {
resp := &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader("hello world")),
}

patches := gomonkey.ApplyFuncReturn(http.Get, resp, nil)
defer patches.Reset()

type args struct {
urls []string
}
Expand Down Expand Up @@ -95,15 +107,11 @@ func TestNewCollector(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotC, err := NewCollector(tt.args.urls...)
if err != tt.wantErr {
t.Errorf("NewCollector() error = %v, wantErr %v", err, tt.wantErr)
return
}

if gotC != nil {
if !reflect.DeepEqual(gotC.Name(), tt.wantCollectorName) {
t.Errorf("NewCollector() = %v, want %v", gotC.Name(), tt.wantCollectorName)
}
assert.Equal(t, tt.wantErr, err)

if err == nil {
assert.Equal(t, tt.wantCollectorName, gotC.Name())
}
})
}
Expand Down
7 changes: 7 additions & 0 deletions collector/fancyindex/fancyindex_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,10 @@ func TestNewCollector(t *testing.T) {
})
}
}

func TestCollector_Name(t *testing.T) {
t.Run("Collector name", func(t *testing.T) {
c := &Collector{}
assert.Equal(t, Name, c.Name())
})
}
7 changes: 7 additions & 0 deletions collector/official/official_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,10 @@ func TestNewCollector(t *testing.T) {
})
}
}

func TestCollector_Name(t *testing.T) {
t.Run("Collector name", func(t *testing.T) {
c := &Collector{}
assert.Equal(t, Name, c.Name())
})
}

0 comments on commit c6882f3

Please sign in to comment.