mirror of
https://github.com/desktop/desktop
synced 2024-10-31 11:07:25 +00:00
Created an in memory store for use in tests.
This commit is contained in:
parent
fa0fa3cb81
commit
f81a44623d
1 changed files with 29 additions and 0 deletions
29
test/in-memory-store.ts
Normal file
29
test/in-memory-store.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
export default class InMemoryStore {
|
||||
private store: {[key: string]: string}
|
||||
private secureStore: {[key: string]: string}
|
||||
|
||||
public constructor() {
|
||||
this.store = {}
|
||||
this.secureStore = {}
|
||||
}
|
||||
|
||||
private secureKey(key: string, login: string): string {
|
||||
return `__key/${key}/${login}`
|
||||
}
|
||||
|
||||
public setItem(key: string, loginOrValue: string, secureValue?: string) {
|
||||
if (secureValue) {
|
||||
this.secureStore[this.secureKey(key, loginOrValue)] = secureValue
|
||||
} else {
|
||||
this.store[key] = loginOrValue
|
||||
}
|
||||
}
|
||||
|
||||
public getItem(key: string, login?: string): string {
|
||||
if (login) {
|
||||
return this.secureStore[this.secureKey(key, login)]
|
||||
} else {
|
||||
return this.store[key]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue