Skip to content

Commit 5ac4935

Browse files
committed
Fixed snap
1 parent 5f90f6e commit 5ac4935

2 files changed

Lines changed: 12 additions & 45 deletions

File tree

src/resources/snap/snap.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CreatePlan, Resource, ResourceSettings, SpawnStatus, getPty } from 'codify-plugin-lib';
1+
import { CreatePlan, Resource, ResourceSettings, SpawnStatus, getPty, Utils } from 'codify-plugin-lib';
22
import { OS, ResourceConfig } from 'codify-schemas';
33

44
import { SnapInstallParameter, SnapPackage } from './install-parameter.js';
@@ -14,6 +14,7 @@ export class SnapResource extends Resource<SnapConfig> {
1414
return {
1515
id: 'snap',
1616
operatingSystems: [OS.Linux],
17+
removeStatefulParametersBeforeDestroy: true,
1718
schema,
1819
parameterSettings: {
1920
install: { type: 'stateful', definition: new SnapInstallParameter() }
@@ -33,14 +34,11 @@ export class SnapResource extends Resource<SnapConfig> {
3334
}
3435

3536
override async create(_plan: CreatePlan<SnapConfig>): Promise<void> {
36-
const $ = getPty();
37-
await $.spawn('apt update', { requiresRoot: true })
38-
await $.spawn('apt install -y snapd', { requiresRoot: true })
37+
await Utils.installViaPkgMgr('snapd');
3938
}
4039

4140
override async destroy(): Promise<void> {
4241
// snap is a core system component and should not be removed
43-
const $ = getPty();
44-
await $.spawn('apt uninstall snapd', { requiresRoot: true })
42+
await Utils.uninstallViaPkgMgr('snapd');
4543
}
4644
}

test/snap/snap.test.ts

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@ import { describe, expect, it } from 'vitest'
22
import { PluginTester, testSpawn } from 'codify-plugin-test';
33
import * as path from 'node:path';
44
import { TestUtils } from '../test-utils.js';
5-
import { SpawnStatus } from 'codify-plugin-lib';
5+
import { SpawnStatus, Utils } from 'codify-plugin-lib';
66

77
// Currently need to figure out a way to test snap. It requires system ctl
8-
describe('Snap resource integration tests', { skip: true }, () => {
8+
describe('Snap resource integration tests', { skip: !Utils.isLinux() }, () => {
99
const pluginPath = path.resolve('./src/index.ts');
1010

1111
it('Can install and uninstall snap packages', { timeout: 300000 }, async () => {
12-
if (!TestUtils.isLinux()) {
13-
console.log('Skipping snap test - not running on Linux');
14-
return;
15-
}
16-
17-
// Check if snap is available
18-
if ((await testSpawn('which snap')).status !== SpawnStatus.SUCCESS) {
19-
console.log('Skipping snap test - snap not available on this system');
20-
return;
21-
}
2212

2313
// Plans correctly and detects that snap is available
2414
await PluginTester.fullTest(pluginPath, [{
@@ -47,8 +37,6 @@ describe('Snap resource integration tests', { skip: true }, () => {
4737
const snapList = (await testSpawn('snap list')).data;
4838
expect(snapList).toContain('hello-world');
4939
expect(snapList).toContain('jq');
50-
// curl should be removed
51-
expect(snapList).not.toContain('curl');
5240
}
5341
},
5442
validateDestroy: async () => {
@@ -59,17 +47,6 @@ describe('Snap resource integration tests', { skip: true }, () => {
5947
});
6048

6149
it('Can install packages with specific channels', { timeout: 300000 }, async () => {
62-
if (!TestUtils.isLinux()) {
63-
console.log('Skipping snap test - not running on Linux');
64-
return;
65-
}
66-
67-
// Check if snap is available
68-
// if ((await testSpawn('which snap')).status !== SpawnStatus.SUCCESS) {
69-
// console.log('Skipping snap test - snap not available on this system');
70-
// return;
71-
// }
72-
7350
await PluginTester.fullTest(pluginPath, [{
7451
type: 'snap',
7552
install: [
@@ -85,28 +62,20 @@ describe('Snap resource integration tests', { skip: true }, () => {
8562
});
8663

8764
it('Can install classic snaps', { timeout: 300000 }, async () => {
88-
if (!TestUtils.isLinux()) {
89-
console.log('Skipping snap test - not running on Linux');
90-
return;
91-
}
92-
93-
// Check if snap is available
94-
// if ((await testSpawn('which snap')).status !== SpawnStatus.SUCCESS) {
95-
// console.log('Skipping snap test - snap not available on this system');
96-
// return;
97-
// }
98-
9965
await PluginTester.fullTest(pluginPath, [{
10066
type: 'snap',
10167
install: [
102-
{ name: 'code', classic: true }
68+
{ name: 'vault', classic: true }
10369
]
10470
}], {
105-
skipUninstall: true,
10671
validateApply: async () => {
10772
const snapList = (await testSpawn('snap list')).data;
108-
expect(snapList).toContain('code');
73+
expect(snapList).toContain('vault');
10974
},
11075
});
76+
77+
await PluginTester.install(pluginPath, [{
78+
type: 'snap',
79+
}])
11180
});
11281
});

0 commit comments

Comments
 (0)