Skip to content
Draft
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
20 changes: 20 additions & 0 deletions jest/helmTool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,24 @@ describe('helmTool', () => {
})
expect(cmd).toEqual('helm repo add --force-update test https://example.com --username test --password test')
})

// test getIndexYaml
it('can get index.yaml', async () => {
const tool = new HelmTool(edition, store, tmpDir)
const repo = await helmRepoStore.create({
data: {
name: 'test-getindex-repo',
active: true,
url: 'https://charts.bitnami.com/bitnami',
},
})
const index = await tool.getIndexYaml(repo)
expect(index).toBeDefined()
}, 1200000)

// test updateDbHelmCharts
it('can run updateDbHelmCharts', async () => {
const tool = new HelmTool(edition, store, tmpDir)
await tool.updateDbHelmCharts()
}, 1200000)
})
73 changes: 71 additions & 2 deletions jest/store/helmchart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ describe('HelmChartStore', () => {
repository_id: repo.id,
icon: 'https://example.com/icon.png',
version: '1.0.0',
verified: false,
keywords: ['test', 'chart'],
urls: ['https://example.com/chart.tgz'],
},
})
expect(chart).toMatchObject({
Expand All @@ -60,7 +62,9 @@ describe('HelmChartStore', () => {
repository_id: repo.id,
icon: 'https://example.com/icon.png',
version: '1.0.0',
verified: false,
keywords: ['test', 'chart'],
urls: ['https://example.com/chart.tgz'],
},
})

Expand All @@ -82,7 +86,9 @@ describe('HelmChartStore', () => {
repository_id: repo.id,
icon: 'https://example.com/icon.png',
version: '1.0.0',
verified: false,
keywords: ['test', 'chart'],
urls: ['https://example.com/chart.tgz'],
},
})
const getChart = await store.get({ id: chart.id })
Expand All @@ -91,6 +97,67 @@ describe('HelmChartStore', () => {
})
})

it('should get an exact helm chart', async () => {
const chart = await store.create({
data: {
active: true,
name: 'test-chart-getexact',
app_version: '1.0.0',
description: 'test chart description',
digest: 'test-digest',
repository_id: repo.id,
icon: 'https://example.com/icon.png',
version: '1.0.0',
verified: false,
keywords: ['test', 'chart'],
urls: ['https://example.com/chart.tgz'],
},
})
const getChart = await store.getExact({
name: chart.name,
version: chart.version,
repository_id: chart.repository_id,
})
expect(getChart).toMatchObject({
...chart,
})
})

it('should get matching helm charts', async () => {
const chartOne = await store.create({
data: {
active: true,
name: 'test-chart-getmatching',
app_version: '1.0.0',
description: 'test chart description one',
digest: 'test-digest',
repository_id: repo.id,
icon: 'https://example.com/icon.png',
version: '1.0.0',
verified: false,
keywords: ['test', 'chart'],
urls: ['https://example.com/chart-100.tgz'],
},
})
const chartTwo = await store.create({
data: {
active: true,
name: 'test-chart-getmatching',
app_version: '2.0.0',
description: 'test chart description',
digest: 'test-digest',
repository_id: repo.id,
icon: 'https://example.com/icon.png',
version: '2.0.0',
verified: false,
keywords: ['test', 'chart'],
urls: ['https://example.com/chart-200.tgz'],
},
})
const matchingCharts = await store.getMatching({ name: chartOne.name })
expect(matchingCharts.length).toBe(2)
})

it('should list all helm charts', async () => {
const chart = await store.create({
data: {
Expand All @@ -102,11 +169,11 @@ describe('HelmChartStore', () => {
repository_id: repo.id,
icon: 'https://example.com/icon.png',
version: '1.0.0',
verified: false,
keywords: ['test', 'chart'],
urls: ['https://example.com/chart.tgz'],
},
})
await store.delete({ id: chart.id })

const charts = await store.list()
expect(charts.length).toBeGreaterThan(0)
})
Expand All @@ -122,7 +189,9 @@ describe('HelmChartStore', () => {
repository_id: repo.id,
icon: 'https://example.com/icon.png',
version: '1.0.0',
verified: false,
keywords: ['test', 'chart'],
urls: ['https://example.com/chart.tgz'],
},
})
const updatedChart = await store.update({
Expand Down
13 changes: 13 additions & 0 deletions jest/store/helmrepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,17 @@ describe('HelmRepositoryStore', () => {
active: 'false',
})
})
it('should get a helm chart by url', async () => {
const repo = await helmRepoStore.create({
data: {
name: 'test-repo-getbyurl',
active: true,
url: 'https://charts.example.com/url',
},
})
const getRepo = await helmRepoStore.getByUrl({ url: repo.url })
expect(getRepo).toMatchObject({
...repo,
})
})
})
8 changes: 5 additions & 3 deletions migrations/202303091537_helmchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ const up = (knex) => {
table.boolean('active').defaultTo('true').notNullable()
table.string('app_version').notNullable()
table.specificType('created_at', 'timestamp default now()')
table.string('description').notNullable()
table.text('description').notNullable()
table.string('digest').notNullable()
table.string('icon')
table.text('icon')
table.specificType('id', 'serial primary key not null')
table.string('keywords')
table.string('kube_version')
table.string('name').unique().notNullable()
table.string('name').notNullable()
table.specificType('refreshed_at', 'timestamp')
table.specificType('repository_id', 'integer references helmrepository(id)')
table.specificType('updated_at', 'timestamp default now()')
table.string('urls').notNullable()
table.boolean('verified').defaultTo(false).notNullable()
table.string('version').notNullable()
table.unique(['name', 'version', 'repository_id'])
}),
])
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"download-helm-charts": "if [ -r dist/src/download-helm-charts.js ]; then node dist/src/download-helm-charts.js; else node src/download-helm-charts.js; fi",
"copy-helm-fixtures": "tar -xf ./test/fixtures/helmCharts.tar.gz -C .",
"remove-helm-fixtures": "rm -rf ./helmCharts/*",
"preserve": "npm run download-helm-charts && npm run migrate",
"preserve": " npm run migrate && npm run download-helm-charts",
"serve": "if [ -r dist/src/index.js ]; then node dist/src/index.js ; else node src/index.js; fi",
"generate-swagger": "node src/generateSwagger.js",
"pretest": "npm run copy-helm-fixtures",
Expand Down
Loading