Skip to content

Commit

Permalink
ci: fix classic confinement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VerteDinde committed Mar 31, 2022
1 parent 596cc18 commit 073aa83
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches:
branches:
- master
tags:
- v[0-9]+.[0-9]+.[0-9]+*
Expand Down
4 changes: 2 additions & 2 deletions resources/classic/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: |
App description
grade: devel
confinement: devmode
confinement: classic

apps:
electronApp:
Expand All @@ -24,7 +24,7 @@ apps:
TMPDIR: $XDG_RUNTIME_DIR

parts:
electron-deps:
electronApp:
source: .
plugin: nil
stage-packages:
Expand Down
12 changes: 7 additions & 5 deletions src/snapcraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ class Snapcraft {
const args = [command]
for (const flag in options) {
const value = options[flag]
if (value) {
args.push(`--${flag}=${value}`)
} else {
args.push(`--${flag}`)
if (flag !== 'target-arch') {
if (value) {
args.push(`--${flag}=${value}`)
} else {
args.push(`--${flag}`)
}
}
}
args.push('--destructive-mode')
/* istanbul ignore if */
if (debug.enabled) {
args.push('--destructive-mode')
args.push('--debug')
}

Expand Down
8 changes: 7 additions & 1 deletion test/snapcraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

const debug = require('debug')('electron-installer-snap:snapcraft')
const Snapcraft = require('../src/snapcraft')
const test = require('ava')

Expand All @@ -33,5 +34,10 @@ test('generateArgs flags and options', t => {
const snapcraft = new Snapcraft()
const args = snapcraft.generateArgs('nonexistent', { a: 1, b: null }, ['foo', 'bar'])

t.deepEqual(args, ['nonexistent', '--a=1', '--b', '--destructive-mode', 'foo', 'bar'], 'generated args')
// Note: --destructive-mode and --debug are enabled by default in CI
if (debug.enabled) {
t.deepEqual(args, ['nonexistent', '--a=1', '--b', '--destructive-mode', '--debug', 'foo', 'bar'], 'generated args')
} else {
t.deepEqual(args, ['nonexistent', '--a=1', '--b', 'foo', 'bar'], 'generated args')
}
})
35 changes: 35 additions & 0 deletions test/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,41 @@ test('custom app config', async t => {
t.true(apps.electronAppName.daemon, 'daemon is set in app')
})

test('strict confinement should apply by default', async t => {
const snapcraftYaml = await createYaml(t, { name: 'electronAppName' })
t.is(snapcraftYaml.confinement, 'strict')
})

test('custom confinement config (devmode should apply correctly)', async t => {
const snapcraftYaml = await createYaml(t, { name: 'electronAppName', confinement: 'devmode' })
t.is(snapcraftYaml.confinement, 'devmode')
})

test('custom confinement config (strict should apply correctly)', async t => {
const snapcraftYaml = await createYaml(t, { name: 'electronAppName', confinement: 'strict' })
t.is(snapcraftYaml.confinement, 'strict')
})

test('custom confinement config (classic should apply correctly)', async t => {
const snapcraftYaml = await createYaml(t, { name: 'electronAppName', confinement: 'classic' })
t.is(snapcraftYaml.confinement, 'classic')
})

test('use gnome extensions with strict confinement', async t => {
const { apps } = await createYaml(t, { name: 'electronAppName' })
t.deepEqual(apps.electronAppName.extensions, ['gnome-3-34'])
})

test('Electron < 2 classic confinement apps use desktop-gtk2', async t => {
const { parts } = await createYaml(t, { name: 'electronAppName', confinement: 'classic' }, '1.8.2')
t.deepEqual(parts.electronAppName.after, ['desktop-gtk2'])
})

test('Electron 2 classic confinement apps use desktop-gtk3', async t => {
const { parts } = await createYaml(t, { name: 'electronAppName', confinement: 'classic' }, '2.0.0-beta.1')
t.deepEqual(parts.electronAppName.after, ['desktop-gtk3'])
})

test('Electron < 4 apps require gconf', async t => {
const snapcraftYaml = await createYaml(t, { name: 'electronAppName' }, '1.8.2')
assertStagedPackage(t, snapcraftYaml, 'libgconf-2-4')
Expand Down

0 comments on commit 073aa83

Please sign in to comment.