Skip to content

Commit

Permalink
refactor: move to consul v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Dec 16, 2024
1 parent f20c456 commit d81f003
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const startItUp = (): void => {
}

export async function setupServiceManager(config: RPSConfig): Promise<void> {
const consul: IServiceManager = new ConsulService(config.consul_host, config.consul_port)
const consul: IServiceManager = new ConsulService(config.consul_host, parseInt(config.consul_port,10))
await waitForServiceManager(consul, 'consul')
await processServiceConfigs(consul, config)
}
Expand Down
4 changes: 2 additions & 2 deletions src/consulService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let serviceName: string
let consul: ConsulService
describe('consul', () => {
beforeEach(() => {
consul = new ConsulService('localhost', '8500')
consul = new ConsulService('localhost', 8500)

jest.clearAllMocks()
jest.restoreAllMocks()
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('consul', () => {
expect(consul.consul.kv.set).toHaveBeenCalledWith(componentName + '/config', JSON.stringify(config, null, 2))
})
it('seed Consul failure', async () => {
consul.consul.kv.set = spyOn(consul.consul.kv, 'set').mockResolvedValue(Promise.reject(new Error())) as any
consul.consul.kv.set = spyOn(consul.consul.kv, 'set').mockRejectedValue(new Error()) as any
const result = await consul.seed(componentName, config)
expect(result).toBe(false)
})
Expand Down
4 changes: 2 additions & 2 deletions src/consulService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import type { IServiceManager } from './interfaces/IServiceManager.js'
import { Environment } from './utils/Environment.js'

export class ConsulService implements IServiceManager {
consul: Consul.Consul
consul: Consul
log = new Logger('ConsulService')
constructor(host: string, port: string) {
constructor(host: string, port: number) {
this.consul = new Consul({
host,
port,
Expand Down
2 changes: 1 addition & 1 deletion src/serviceManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { jest } from '@jest/globals'

const { processServiceConfigs, waitForServiceManager } = await import('./serviceManager.js')

const consul: IServiceManager = new ConsulService('consul', '8500')
const consul: IServiceManager = new ConsulService('consul', 8500)
let componentName: string
let config: any

Expand Down

0 comments on commit d81f003

Please sign in to comment.