Skip to content

Commit

Permalink
fix auth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Feb 7, 2024
1 parent 7629eac commit 460f5af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 5 additions & 3 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"reflect"
"strings"
"testing"

"github.com/rusq/slackdump/v3/internal/fixtures"
)

func TestLoad(t *testing.T) {
Expand Down Expand Up @@ -82,14 +84,14 @@ func TestSave(t *testing.T) {
},
{
"cookies missing on client token",
args{ValueAuth{simpleProvider{Token: "xoxc-blah", Cookie: []*http.Cookie{}}}},
args{ValueAuth{simpleProvider{Token: fixtures.TestClientToken, Cookie: []*http.Cookie{}}}},
"",
true,
},
{
"cookies missing on non-client token",
args{ValueAuth{simpleProvider{Token: "xoxp-blah", Cookie: []*http.Cookie{}}}},
`{"Token":"xoxp-blah","Cookie":[]}
args{ValueAuth{simpleProvider{Token: fixtures.TestPersonalToken, Cookie: []*http.Cookie{}}}},
`{"Token":"` + fixtures.TestPersonalToken + `","Cookie":[]}
`,
false,
},
Expand Down
17 changes: 9 additions & 8 deletions internal/cache/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.uber.org/mock/gomock"

"github.com/rusq/slackdump/v3/auth"
"github.com/rusq/slackdump/v3/internal/fixtures"
"github.com/rusq/slackdump/v3/internal/mocks/mock_appauth"
"github.com/rusq/slackdump/v3/internal/mocks/mock_io"
)
Expand Down Expand Up @@ -43,7 +44,7 @@ func Test_isExistingFile(t *testing.T) {
}
}

func TestSlackCreds_Type(t *testing.T) {
func TestAuthData_Type(t *testing.T) {
dir := t.TempDir()
testFile := filepath.Join(dir, "fake_cookie")
if err := os.WriteFile(testFile, []byte("unittest"), 0644); err != nil {
Expand Down Expand Up @@ -81,17 +82,17 @@ func TestSlackCreds_Type(t *testing.T) {
}
got, err := c.Type(tt.args.ctx)
if (err != nil) != tt.wantErr {
t.Errorf("SlackCreds.Type() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("AuthData.Type() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("SlackCreds.Type() = %v, want %v", got, tt.want)
t.Errorf("AuthData.Type() = %v, want %v", got, tt.want)
}
})
}
}

func TestSlackCreds_IsEmpty(t *testing.T) {
func TestAuthData_IsEmpty(t *testing.T) {
type fields struct {
Token string
Cookie string
Expand All @@ -103,9 +104,9 @@ func TestSlackCreds_IsEmpty(t *testing.T) {
}{
{"empty", fields{Token: "", Cookie: ""}, true},
{"no token", fields{Token: "", Cookie: "x"}, true},
{"xoxc: token and cookie present", fields{Token: "xoxc-", Cookie: "x"}, false},
{"xoxc: no cookie is not ok", fields{Token: "xoxc-", Cookie: ""}, true},
{"other: no cookie is ok", fields{Token: "xoxp-", Cookie: ""}, false},
{"xoxc: token and cookie present", fields{Token: fixtures.TestClientToken, Cookie: "x"}, false},
{"xoxc: no cookie is not ok", fields{Token: fixtures.TestClientToken, Cookie: ""}, true},
{"personal token: no cookie is ok", fields{Token: fixtures.TestPersonalToken, Cookie: ""}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -114,7 +115,7 @@ func TestSlackCreds_IsEmpty(t *testing.T) {
Cookie: tt.fields.Cookie,
}
if got := c.IsEmpty(); got != tt.want {
t.Errorf("SlackCreds.IsEmpty() = %v, want %v", got, tt.want)
t.Errorf("AuthData.IsEmpty() = %v, want %v", got, tt.want)
}
})
}
Expand Down
5 changes: 5 additions & 0 deletions internal/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/slack-go/slack"
)

const (
TestClientToken = "xoxc-888888888888-888888888888-8888888888888-fffffffffffffffa915fe069d70a8ad81743b0ec4ee9c81540af43f5e143264b"
TestPersonalToken = "xoxp-777777777777-888888888888-8888888888888-fffffffffffffffa915fe069d70a8ad81743b0ec4ee9c81540af43f5e143264b"
)

// Load loads a json data into T, or panics.
func Load[T any](js string) T {
var ret T
Expand Down

0 comments on commit 460f5af

Please sign in to comment.