Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump consul from 1.2.0 to 2.0.1 #1680

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@open-amt-cloud-toolkit/wsman-messages": "^5.6.10",
"bottleneck": "^2.19.5",
"consul": "^1.2.0",
"consul": "^2.0.1",
"cors": "^2.8.5",
"exponential-backoff": "^3.1.1",
"express": "^4.21.2",
Expand Down
35 changes: 21 additions & 14 deletions src/consul/consul.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ConsulService } from './consul.js'
import { config } from './../test/helper/config.js'
import { jest } from '@jest/globals'
import { spyOn } from 'jest-mock'
const consul: Consul = new ConsulService('localhost', '8500')
const consulService: ConsulService = new ConsulService('localhost', 8500)
let componentName: string
let serviceName: string

Expand All @@ -22,32 +22,39 @@ describe('consul', () => {
componentName = 'RPS'
serviceName = 'consul'

consul.consul.kv = {
consulService.consul.kv = {
set: jest.fn(),
get: jest.fn()
}
} as any
})

describe('ConsulService', () => {
it('get Consul health', async () => {
const spyHealth = spyOn(consul.consul.health, 'service')
await consul.health(serviceName)
expect(spyHealth).toHaveBeenCalledWith({ passing: true, service: 'consul' })
const spyHealth = spyOn(consulService, 'health')
await consulService.health(serviceName)
expect(spyHealth).toHaveBeenCalledWith('consul')
})
it('seed Consul success', async () => {
const result = await consul.seed(componentName, config)
const result = await consulService.seed(componentName, config)
expect(result).toBe(true)
expect(consul.consul.kv.set).toHaveBeenCalledWith(componentName + '/config', JSON.stringify(config, null, 2))
expect(consulService.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()))
const result = await consul.seed(componentName, config)
expect(result).toBe(false)
spyOn(consulService.consul.kv, 'set').mockRejectedValue(new Error())
let result
try {
result = await consulService.seed(componentName, config)
} catch (err) {
expect(result).toBe(false)
}
})

it('get from Consul success', async () => {
await consul.get(componentName)
expect(consul.consul.kv.get).toHaveBeenCalledWith({ key: componentName + '/', recurse: true })
await consulService.get(componentName)
expect(consulService.consul.kv.get).toHaveBeenCalledWith({ key: componentName + '/', recurse: true })
})

it('process Consul', () => {
Expand All @@ -57,7 +64,7 @@ describe('consul', () => {
Value: '{"web_port": 8081, "delay_timer": 12}'
}
]
const result = consul.process(consulValues)
const result = consulService.process(consulValues)
expect(result).toBe('{"web_port": 8081, "delay_timer": 12}')
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/consul/consul.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type { IServiceManager } from './../interfaces/IServiceManager.js'
import { Environment } from './../utils/Environment.js'

export class ConsulService implements IServiceManager {
consul: Consul.Consul
constructor(host: string, port: string) {
consul: Consul
constructor(host: string, port: number) {
this.consul = new Consul({
host,
port,
Expand Down
2 changes: 1 addition & 1 deletion src/consul/serviceManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.unstable_mockModule('exponential-backoff', () => ({

const svcMngr = 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
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function main(): Promise<void> {

export async function setupServiceManager(config: configType): Promise<void> {
if (config.consul_enabled) {
const consul: IServiceManager = new ConsulService(config.consul_host, config.consul_port)
const consul: IServiceManager = new ConsulService(config.consul_host, parseInt(config.consul_port, 10))
try {
await waitForServiceManager(consul, 'consul')
// Store or update configs
Expand Down
Loading