<commit_before>package oauth2

import (
  "sync"
)

type MockStorage struct {
  store  map[string]interface{}
  locker *sync.RWMutex
}

func NewMockStorage() *MockStorage {
  return &MockStorage{make(map[string]interface{}), new(sync.RWMutex)}
}

func (m *MockStorage) Insert(id string, data interface{}) {
  m.locker.Lock()
  defer m.locker.Unlock()
  m.store[id] = data
}

func (m *MockStorage) Remove(id string) {
  m.locker.Lock()
  defer m.locker.Unlock()
  delete(m.store, id)
}

func (m *MockStorage) Read(id string) interface{} {
  m.locker.RLock()
  defer m.locker.RUnlock()
  data, ok := m.store[id]
  if !ok {
    return nil
  }
  return data
}

type MockClientStore struct {
  store *MockStorage
}

func NewMockClientStore() *MockClientStore {
  return &MockClientStore{NewMockStorage()}
}

func (m *MockClientStore) Insert(c *Client) (string, error) {
  m.store.Insert(c.Id, c)
  return c.Id, nil
}

func (m *MockClientStore) Remove(id string) error {
  m.store.Remove(id)
  return nil
}

func (m *MockClientStore) Read(id string) (*Client, error) {
  c, _ := m.store.Read(id).(*Client)
  return c, nil
}<commit_msg>Add mock store for token<commit_after>package oauth2

import (
  "sync"
  "time"
)

type MockStorage struct {
  store  map[string]interface{}
  locker *sync.RWMutex
}

func NewMockStorage() *MockStorage {
  return &MockStorage{make(map[string]interface{}), new(sync.RWMutex)}
}

func (m *MockStorage) Insert(id string, data interface{}) {
  m.locker.Lock()
  defer m.locker.Unlock()
  m.store[id] = data
}

func (m *MockStorage) Remove(id string) {
  m.locker.Lock()
  defer m.locker.Unlock()
  delete(m.store, id)
}

func (m *MockStorage) Read(id string) interface{} {
  m.locker.RLock()
  defer m.locker.RUnlock()
  data, ok := m.store[id]
  if !ok {
    return nil
  }
  return data
}

type MockClientStore struct {
  store *MockStorage
}

func NewMockClientStore() *MockClientStore {
  return &MockClientStore{NewMockStorage()}
}

func (m *MockClientStore) Insert(c *Client) (string, error) {
  m.store.Insert(c.Id, c)
  return c.Id, nil
}

func (m *MockClientStore) Remove(id string) error {
  m.store.Remove(id)
  return nil
}

func (m *MockClientStore) Read(id string) (*Client, error) {
  c, _ := m.store.Read(id).(*Client)
  return c, nil
}

type MockTokenStore struct {
  store *MockStorage
}

func NewMockTokenStore() *MockTokenStore {
  return &MockTokenStore{NewMockStorage()}
}

func (m *MockTokenStore) Insert(t *Token) (string, error) {
  m.store.Insert(t.Value, t)
  return t.Value, nil
}

func (m *MockTokenStore) Remove(id string) error {
  m.store.Remove(id)
  return nil
}

func (m *MockTokenStore) Read(id string) (*Token, error) {
  t, ok := m.store.Read(id).(*Token)
  if !ok {
    return nil, nil
  }
  if t.CreatedAt+t.Life < time.Now().Unix() {
    return nil, nil
  }
  return t, nil
}
{'fraction_non_alphanumeric': 0.14672765657987333, 'fraction_numerical': 0.0007037297677691766, 'mean_word_length': 4.049733570159858, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6384908', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1069, 'n_words': 260}