From 241828e917d241e12d6e2cd239bb1fd1a73beec5 Mon Sep 17 00:00:00 2001 From: Carlos Treminio Date: Sun, 9 Oct 2022 10:41:41 -0600 Subject: [PATCH] :white_check_mark: Added more test cases un the authentication_impl_test.go --- .../internal/authentication_impl_test.go | 333 ++++++++++++++++++ .../internal/authentication_impl_test.go | 122 +++++++ jira/internal/authentication_impl_test.go | 122 +++++++ jira/sm/internal/authentication_impl_test.go | 122 +++++++ 4 files changed, 699 insertions(+) create mode 100644 confluence/internal/authentication_impl_test.go diff --git a/confluence/internal/authentication_impl_test.go b/confluence/internal/authentication_impl_test.go new file mode 100644 index 00000000..ac34e654 --- /dev/null +++ b/confluence/internal/authentication_impl_test.go @@ -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: "example@example.com", + 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) + } + }) + } +} diff --git a/jira/agile/internal/authentication_impl_test.go b/jira/agile/internal/authentication_impl_test.go index 78e074f9..ac34e654 100644 --- a/jira/agile/internal/authentication_impl_test.go +++ b/jira/agile/internal/authentication_impl_test.go @@ -209,3 +209,125 @@ func TestNewAuthenticationService(t *testing.T) { }) } } + +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: "example@example.com", + 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) + } + }) + } +} diff --git a/jira/internal/authentication_impl_test.go b/jira/internal/authentication_impl_test.go index 78e074f9..ac34e654 100644 --- a/jira/internal/authentication_impl_test.go +++ b/jira/internal/authentication_impl_test.go @@ -209,3 +209,125 @@ func TestNewAuthenticationService(t *testing.T) { }) } } + +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: "example@example.com", + 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) + } + }) + } +} diff --git a/jira/sm/internal/authentication_impl_test.go b/jira/sm/internal/authentication_impl_test.go index 78e074f9..ac34e654 100644 --- a/jira/sm/internal/authentication_impl_test.go +++ b/jira/sm/internal/authentication_impl_test.go @@ -209,3 +209,125 @@ func TestNewAuthenticationService(t *testing.T) { }) } } + +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: "example@example.com", + 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) + } + }) + } +}