🚧 Stub for config package

This commit is contained in:
Dan Jones 2025-04-02 20:59:40 -05:00
commit 91bbd0f8e2
5 changed files with 471 additions and 1 deletions

24
config/config.go Normal file
View file

@ -0,0 +1,24 @@
package config
import (
"context"
"codeberg.org/danjones000/trakter/trakt"
)
//go:generate mockgen -source config.go -destination ../internal/mocks/config/config.go -package config -typed
type Config interface {
AppId(ctx context.Context) string
AppSecret(ctx context.Context) string
Device(ctx context.Context) trakt.OauthDevice
UserOauth(ctx context.Context) trakt.Oauth
AccessToken(ctx context.Context) string
RefreshToken(ctx context.Context) string
SetAppId(ctx context.Context, appID string) error
SetAppSecret(ctx context.Context, appSecret string) error
SetDevice(ctx context.Context, dev trakt.OauthDevice) error
SetUserOauth(ctx context.Context, user trakt.Oauth) error
}

5
go.mod
View file

@ -2,4 +2,7 @@ module codeberg.org/danjones000/trakter
go 1.23.6 go 1.23.6
require github.com/spf13/pflag v1.0.6 require (
github.com/spf13/pflag v1.0.6
go.uber.org/mock v0.5.0
)

2
go.sum
View file

@ -1,2 +1,4 @@
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=

View file

@ -0,0 +1,422 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: config.go
//
// Generated by this command:
//
// mockgen -source config.go -destination ../internal/mocks/config/config.go -package config -typed
//
// Package config is a generated GoMock package.
package config
import (
context "context"
reflect "reflect"
trakt "codeberg.org/danjones000/trakter/trakt"
gomock "go.uber.org/mock/gomock"
)
// MockConfig is a mock of Config interface.
type MockConfig struct {
ctrl *gomock.Controller
recorder *MockConfigMockRecorder
isgomock struct{}
}
// MockConfigMockRecorder is the mock recorder for MockConfig.
type MockConfigMockRecorder struct {
mock *MockConfig
}
// NewMockConfig creates a new mock instance.
func NewMockConfig(ctrl *gomock.Controller) *MockConfig {
mock := &MockConfig{ctrl: ctrl}
mock.recorder = &MockConfigMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockConfig) EXPECT() *MockConfigMockRecorder {
return m.recorder
}
// AccessToken mocks base method.
func (m *MockConfig) AccessToken(ctx context.Context) string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AccessToken", ctx)
ret0, _ := ret[0].(string)
return ret0
}
// AccessToken indicates an expected call of AccessToken.
func (mr *MockConfigMockRecorder) AccessToken(ctx any) *MockConfigAccessTokenCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AccessToken", reflect.TypeOf((*MockConfig)(nil).AccessToken), ctx)
return &MockConfigAccessTokenCall{Call: call}
}
// MockConfigAccessTokenCall wrap *gomock.Call
type MockConfigAccessTokenCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockConfigAccessTokenCall) Return(arg0 string) *MockConfigAccessTokenCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockConfigAccessTokenCall) Do(f func(context.Context) string) *MockConfigAccessTokenCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockConfigAccessTokenCall) DoAndReturn(f func(context.Context) string) *MockConfigAccessTokenCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// AppId mocks base method.
func (m *MockConfig) AppId(ctx context.Context) string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AppId", ctx)
ret0, _ := ret[0].(string)
return ret0
}
// AppId indicates an expected call of AppId.
func (mr *MockConfigMockRecorder) AppId(ctx any) *MockConfigAppIdCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppId", reflect.TypeOf((*MockConfig)(nil).AppId), ctx)
return &MockConfigAppIdCall{Call: call}
}
// MockConfigAppIdCall wrap *gomock.Call
type MockConfigAppIdCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockConfigAppIdCall) Return(arg0 string) *MockConfigAppIdCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockConfigAppIdCall) Do(f func(context.Context) string) *MockConfigAppIdCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockConfigAppIdCall) DoAndReturn(f func(context.Context) string) *MockConfigAppIdCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// AppSecret mocks base method.
func (m *MockConfig) AppSecret(ctx context.Context) string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AppSecret", ctx)
ret0, _ := ret[0].(string)
return ret0
}
// AppSecret indicates an expected call of AppSecret.
func (mr *MockConfigMockRecorder) AppSecret(ctx any) *MockConfigAppSecretCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AppSecret", reflect.TypeOf((*MockConfig)(nil).AppSecret), ctx)
return &MockConfigAppSecretCall{Call: call}
}
// MockConfigAppSecretCall wrap *gomock.Call
type MockConfigAppSecretCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockConfigAppSecretCall) Return(arg0 string) *MockConfigAppSecretCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockConfigAppSecretCall) Do(f func(context.Context) string) *MockConfigAppSecretCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockConfigAppSecretCall) DoAndReturn(f func(context.Context) string) *MockConfigAppSecretCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// Device mocks base method.
func (m *MockConfig) Device(ctx context.Context) trakt.OauthDevice {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Device", ctx)
ret0, _ := ret[0].(trakt.OauthDevice)
return ret0
}
// Device indicates an expected call of Device.
func (mr *MockConfigMockRecorder) Device(ctx any) *MockConfigDeviceCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Device", reflect.TypeOf((*MockConfig)(nil).Device), ctx)
return &MockConfigDeviceCall{Call: call}
}
// MockConfigDeviceCall wrap *gomock.Call
type MockConfigDeviceCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockConfigDeviceCall) Return(arg0 trakt.OauthDevice) *MockConfigDeviceCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockConfigDeviceCall) Do(f func(context.Context) trakt.OauthDevice) *MockConfigDeviceCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockConfigDeviceCall) DoAndReturn(f func(context.Context) trakt.OauthDevice) *MockConfigDeviceCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// RefreshToken mocks base method.
func (m *MockConfig) RefreshToken(ctx context.Context) string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "RefreshToken", ctx)
ret0, _ := ret[0].(string)
return ret0
}
// RefreshToken indicates an expected call of RefreshToken.
func (mr *MockConfigMockRecorder) RefreshToken(ctx any) *MockConfigRefreshTokenCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RefreshToken", reflect.TypeOf((*MockConfig)(nil).RefreshToken), ctx)
return &MockConfigRefreshTokenCall{Call: call}
}
// MockConfigRefreshTokenCall wrap *gomock.Call
type MockConfigRefreshTokenCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockConfigRefreshTokenCall) Return(arg0 string) *MockConfigRefreshTokenCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockConfigRefreshTokenCall) Do(f func(context.Context) string) *MockConfigRefreshTokenCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockConfigRefreshTokenCall) DoAndReturn(f func(context.Context) string) *MockConfigRefreshTokenCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// SetAppId mocks base method.
func (m *MockConfig) SetAppId(ctx context.Context, appID string) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetAppId", ctx, appID)
ret0, _ := ret[0].(error)
return ret0
}
// SetAppId indicates an expected call of SetAppId.
func (mr *MockConfigMockRecorder) SetAppId(ctx, appID any) *MockConfigSetAppIdCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAppId", reflect.TypeOf((*MockConfig)(nil).SetAppId), ctx, appID)
return &MockConfigSetAppIdCall{Call: call}
}
// MockConfigSetAppIdCall wrap *gomock.Call
type MockConfigSetAppIdCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockConfigSetAppIdCall) Return(arg0 error) *MockConfigSetAppIdCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockConfigSetAppIdCall) Do(f func(context.Context, string) error) *MockConfigSetAppIdCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockConfigSetAppIdCall) DoAndReturn(f func(context.Context, string) error) *MockConfigSetAppIdCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// SetAppSecret mocks base method.
func (m *MockConfig) SetAppSecret(ctx context.Context, appSecret string) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetAppSecret", ctx, appSecret)
ret0, _ := ret[0].(error)
return ret0
}
// SetAppSecret indicates an expected call of SetAppSecret.
func (mr *MockConfigMockRecorder) SetAppSecret(ctx, appSecret any) *MockConfigSetAppSecretCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAppSecret", reflect.TypeOf((*MockConfig)(nil).SetAppSecret), ctx, appSecret)
return &MockConfigSetAppSecretCall{Call: call}
}
// MockConfigSetAppSecretCall wrap *gomock.Call
type MockConfigSetAppSecretCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockConfigSetAppSecretCall) Return(arg0 error) *MockConfigSetAppSecretCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockConfigSetAppSecretCall) Do(f func(context.Context, string) error) *MockConfigSetAppSecretCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockConfigSetAppSecretCall) DoAndReturn(f func(context.Context, string) error) *MockConfigSetAppSecretCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// SetDevice mocks base method.
func (m *MockConfig) SetDevice(ctx context.Context, dev trakt.OauthDevice) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetDevice", ctx, dev)
ret0, _ := ret[0].(error)
return ret0
}
// SetDevice indicates an expected call of SetDevice.
func (mr *MockConfigMockRecorder) SetDevice(ctx, dev any) *MockConfigSetDeviceCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDevice", reflect.TypeOf((*MockConfig)(nil).SetDevice), ctx, dev)
return &MockConfigSetDeviceCall{Call: call}
}
// MockConfigSetDeviceCall wrap *gomock.Call
type MockConfigSetDeviceCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockConfigSetDeviceCall) Return(arg0 error) *MockConfigSetDeviceCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockConfigSetDeviceCall) Do(f func(context.Context, trakt.OauthDevice) error) *MockConfigSetDeviceCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockConfigSetDeviceCall) DoAndReturn(f func(context.Context, trakt.OauthDevice) error) *MockConfigSetDeviceCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// SetUserOauth mocks base method.
func (m *MockConfig) SetUserOauth(ctx context.Context, user trakt.Oauth) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetUserOauth", ctx, user)
ret0, _ := ret[0].(error)
return ret0
}
// SetUserOauth indicates an expected call of SetUserOauth.
func (mr *MockConfigMockRecorder) SetUserOauth(ctx, user any) *MockConfigSetUserOauthCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetUserOauth", reflect.TypeOf((*MockConfig)(nil).SetUserOauth), ctx, user)
return &MockConfigSetUserOauthCall{Call: call}
}
// MockConfigSetUserOauthCall wrap *gomock.Call
type MockConfigSetUserOauthCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockConfigSetUserOauthCall) Return(arg0 error) *MockConfigSetUserOauthCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockConfigSetUserOauthCall) Do(f func(context.Context, trakt.Oauth) error) *MockConfigSetUserOauthCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockConfigSetUserOauthCall) DoAndReturn(f func(context.Context, trakt.Oauth) error) *MockConfigSetUserOauthCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// UserOauth mocks base method.
func (m *MockConfig) UserOauth(ctx context.Context) trakt.Oauth {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UserOauth", ctx)
ret0, _ := ret[0].(trakt.Oauth)
return ret0
}
// UserOauth indicates an expected call of UserOauth.
func (mr *MockConfigMockRecorder) UserOauth(ctx any) *MockConfigUserOauthCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UserOauth", reflect.TypeOf((*MockConfig)(nil).UserOauth), ctx)
return &MockConfigUserOauthCall{Call: call}
}
// MockConfigUserOauthCall wrap *gomock.Call
type MockConfigUserOauthCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockConfigUserOauthCall) Return(arg0 trakt.Oauth) *MockConfigUserOauthCall {
c.Call = c.Call.Return(arg0)
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockConfigUserOauthCall) Do(f func(context.Context) trakt.Oauth) *MockConfigUserOauthCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockConfigUserOauthCall) DoAndReturn(f func(context.Context) trakt.Oauth) *MockConfigUserOauthCall {
c.Call = c.Call.DoAndReturn(f)
return c
}

19
trakt/oauth.go Normal file
View file

@ -0,0 +1,19 @@
package trakt
type OauthDevice struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationUrl string `json:"verification_url"`
ExpiresIn uint16 `json:"expires_in"`
CreatedAt uint64 `json:"created_at,omitempty"`
Interval uint8
}
type Oauth struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
ExpiresIn uint32 `json:"expires_in"`
CreatedAt uint64 `json:"created_at"`
Scope string
}