-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Added more test cases un the authentication_impl_test.go
- Loading branch information
1 parent
c5bc607
commit 241828e
Showing
4 changed files
with
699 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,333 @@ | ||
package internal | ||
|
||
import ( | ||
"github.com/ctreminiom/go-atlassian/service" | ||
"github.com/ctreminiom/go-atlassian/service/common" | ||
"github.com/ctreminiom/go-atlassian/service/mocks" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestAuthenticationService_GetBasicAuth(t *testing.T) { | ||
|
||
type fields struct { | ||
c service.Client | ||
basicAuthProvided bool | ||
mail string | ||
token string | ||
userAgentProvided bool | ||
agent string | ||
} | ||
testCases := []struct { | ||
name string | ||
fields fields | ||
want string | ||
want1 string | ||
}{ | ||
{ | ||
name: "when the basic auth is already set", | ||
fields: fields{ | ||
c: mocks.NewClient(t), | ||
mail: "mail", | ||
token: "token", | ||
}, | ||
want: "mail", | ||
want1: "token", | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
|
||
a := &AuthenticationService{ | ||
c: testCase.fields.c, | ||
basicAuthProvided: testCase.fields.basicAuthProvided, | ||
mail: testCase.fields.mail, | ||
token: testCase.fields.token, | ||
userAgentProvided: testCase.fields.userAgentProvided, | ||
agent: testCase.fields.agent, | ||
} | ||
|
||
got, got1 := a.GetBasicAuth() | ||
if got != testCase.want { | ||
t.Errorf("GetBasicAuth() got = %v, want %v", got, testCase.want) | ||
} | ||
|
||
if got1 != testCase.want1 { | ||
t.Errorf("GetBasicAuth() got1 = %v, want %v", got1, testCase.want1) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAuthenticationService_GetUserAgent(t *testing.T) { | ||
type fields struct { | ||
c service.Client | ||
basicAuthProvided bool | ||
mail string | ||
token string | ||
userAgentProvided bool | ||
agent string | ||
} | ||
testCases := []struct { | ||
name string | ||
fields fields | ||
want string | ||
}{ | ||
{ | ||
name: "when the user agent is already set", | ||
fields: fields{ | ||
c: mocks.NewClient(t), | ||
agent: "firefox-09", | ||
}, | ||
want: "firefox-09", | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
a := &AuthenticationService{ | ||
c: testCase.fields.c, | ||
basicAuthProvided: testCase.fields.basicAuthProvided, | ||
mail: testCase.fields.mail, | ||
token: testCase.fields.token, | ||
userAgentProvided: testCase.fields.userAgentProvided, | ||
agent: testCase.fields.agent, | ||
} | ||
if got := a.GetUserAgent(); got != testCase.want { | ||
t.Errorf("GetUserAgent() = %v, want %v", got, testCase.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAuthenticationService_HasBasicAuth(t *testing.T) { | ||
type fields struct { | ||
c service.Client | ||
basicAuthProvided bool | ||
mail string | ||
token string | ||
userAgentProvided bool | ||
agent string | ||
} | ||
testCases := []struct { | ||
name string | ||
fields fields | ||
want bool | ||
}{ | ||
{ | ||
name: "when the params are correct", | ||
fields: fields{ | ||
c: mocks.NewClient(t), | ||
basicAuthProvided: true, | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
|
||
t.Run(testCase.name, func(t *testing.T) { | ||
a := &AuthenticationService{ | ||
c: testCase.fields.c, | ||
basicAuthProvided: testCase.fields.basicAuthProvided, | ||
mail: testCase.fields.mail, | ||
token: testCase.fields.token, | ||
userAgentProvided: testCase.fields.userAgentProvided, | ||
agent: testCase.fields.agent, | ||
} | ||
if got := a.HasBasicAuth(); got != testCase.want { | ||
t.Errorf("HasBasicAuth() = %v, want %v", got, testCase.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAuthenticationService_HasUserAgent(t *testing.T) { | ||
type fields struct { | ||
c service.Client | ||
basicAuthProvided bool | ||
mail string | ||
token string | ||
userAgentProvided bool | ||
agent string | ||
} | ||
testCases := []struct { | ||
name string | ||
fields fields | ||
want bool | ||
}{ | ||
{ | ||
name: "when the parameters are correct", | ||
fields: fields{ | ||
userAgentProvided: true, | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
|
||
t.Run(testCase.name, func(t *testing.T) { | ||
a := &AuthenticationService{ | ||
c: testCase.fields.c, | ||
basicAuthProvided: testCase.fields.basicAuthProvided, | ||
mail: testCase.fields.mail, | ||
token: testCase.fields.token, | ||
userAgentProvided: testCase.fields.userAgentProvided, | ||
agent: testCase.fields.agent, | ||
} | ||
|
||
if got := a.HasUserAgent(); got != testCase.want { | ||
t.Errorf("HasUserAgent() = %v, want %v", got, testCase.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestNewAuthenticationService(t *testing.T) { | ||
|
||
clientMocked := mocks.NewClient(t) | ||
|
||
type args struct { | ||
client service.Client | ||
} | ||
testCases := []struct { | ||
name string | ||
args args | ||
want common.Authentication | ||
}{ | ||
{ | ||
name: "when the parameters are correct", | ||
args: args{ | ||
client: clientMocked, | ||
}, | ||
want: NewAuthenticationService(clientMocked), | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
if got := NewAuthenticationService(testCase.args.client); !reflect.DeepEqual(got, testCase.want) { | ||
t.Errorf("NewAuthenticationService() = %v, want %v", got, testCase.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAuthenticationService_SetUserAgent(t *testing.T) { | ||
|
||
type fields struct { | ||
c service.Client | ||
basicAuthProvided bool | ||
mail string | ||
token string | ||
userAgentProvided bool | ||
agent string | ||
} | ||
type args struct { | ||
agent string | ||
} | ||
testCases := []struct { | ||
name string | ||
fields fields | ||
args args | ||
}{ | ||
{ | ||
name: "when the parameters are correct", | ||
args: args{agent: "mozilla-9"}, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
|
||
a := &AuthenticationService{ | ||
c: testCase.fields.c, | ||
basicAuthProvided: testCase.fields.basicAuthProvided, | ||
mail: testCase.fields.mail, | ||
token: testCase.fields.token, | ||
userAgentProvided: testCase.fields.userAgentProvided, | ||
agent: testCase.fields.agent, | ||
} | ||
|
||
a.SetUserAgent(testCase.args.agent) | ||
}) | ||
} | ||
} | ||
|
||
func TestAuthenticationService_SetBasicAuth(t *testing.T) { | ||
|
||
type fields struct { | ||
c service.Client | ||
basicAuthProvided bool | ||
mail string | ||
token string | ||
userAgentProvided bool | ||
agent string | ||
} | ||
type args struct { | ||
mail string | ||
token string | ||
} | ||
testCases := []struct { | ||
name string | ||
fields fields | ||
args args | ||
}{ | ||
{ | ||
name: "when the parameters are correct", | ||
args: args{ | ||
mail: "[email protected]", | ||
token: "token-sample", | ||
}, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
a := &AuthenticationService{ | ||
c: testCase.fields.c, | ||
basicAuthProvided: testCase.fields.basicAuthProvided, | ||
mail: testCase.fields.mail, | ||
token: testCase.fields.token, | ||
userAgentProvided: testCase.fields.userAgentProvided, | ||
agent: testCase.fields.agent, | ||
} | ||
|
||
a.SetBasicAuth(testCase.args.mail, testCase.args.token) | ||
}) | ||
} | ||
} | ||
|
||
func TestAuthenticationService_HasSetExperimentalFlag(t *testing.T) { | ||
|
||
type fields struct { | ||
c service.Client | ||
basicAuthProvided bool | ||
mail string | ||
token string | ||
userAgentProvided bool | ||
agent string | ||
} | ||
testCases := []struct { | ||
name string | ||
fields fields | ||
want bool | ||
}{ | ||
|
||
{ | ||
name: "when the parameters are correct", | ||
fields: fields{}, | ||
want: false, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
a := &AuthenticationService{ | ||
c: testCase.fields.c, | ||
basicAuthProvided: testCase.fields.basicAuthProvided, | ||
mail: testCase.fields.mail, | ||
token: testCase.fields.token, | ||
userAgentProvided: testCase.fields.userAgentProvided, | ||
agent: testCase.fields.agent, | ||
} | ||
if got := a.HasSetExperimentalFlag(); got != testCase.want { | ||
t.Errorf("HasSetExperimentalFlag() = %v, want %v", got, testCase.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.