1+ /*
2+ * Copyright 2023-2025, Seqera Labs
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ *
16+ */
17+
18+ package io.seqera.wave.cli
19+
20+ import java.nio.file.Files
21+
22+ import io.seqera.wave.api.PackagesSpec
23+ import io.seqera.wave.config.PixiOpts
24+ import picocli.CommandLine
25+ import spock.lang.Specification
26+ /**
27+ * Test App Pixi prefixed options
28+ *
29+ * @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
30+ */
31+ class AppPixiOptsTest extends Specification {
32+
33+ def ' should include pixi opts with conda package' () {
34+ given :
35+ def app = new App ()
36+ String [] args = [" --conda-package" , " foo" ]
37+
38+ when :
39+ new CommandLine (app). parseArgs(args)
40+ and :
41+ def req = app. createRequest()
42+ then :
43+ req. packages. type == PackagesSpec.Type . CONDA
44+ req. packages. entries == [' foo' ]
45+ and :
46+ req. packages. pixiOpts == new PixiOpts (
47+ pixiImage : PixiOpts . DEFAULT_PIXI_IMAGE ,
48+ baseImage : PixiOpts . DEFAULT_BASE_IMAGE ,
49+ basePackages : PixiOpts . DEFAULT_PACKAGES
50+ )
51+ }
52+
53+ def ' should include pixi opts with conda file' () {
54+ given :
55+ def CONDA_RECIPE = '''
56+ name: my-recipe
57+ dependencies:
58+ - one=1.0
59+ - two:2.0
60+ ''' . stripIndent(true )
61+ and :
62+ def folder = Files . createTempDirectory(' test' )
63+ def condaFile = folder. resolve(' conda.yml' );
64+ condaFile. text = CONDA_RECIPE
65+ and :
66+ def app = new App ()
67+ String [] args = [" --conda-file" , condaFile. toString()]
68+
69+ when :
70+ new CommandLine (app). parseArgs(args)
71+ and :
72+ def req = app. createRequest()
73+ then :
74+ req. packages. type == PackagesSpec.Type . CONDA
75+ and :
76+ req. packages. pixiOpts == new PixiOpts (
77+ pixiImage : PixiOpts . DEFAULT_PIXI_IMAGE ,
78+ baseImage : PixiOpts . DEFAULT_BASE_IMAGE ,
79+ basePackages : PixiOpts . DEFAULT_PACKAGES
80+ )
81+
82+ cleanup :
83+ folder?. deleteDir()
84+ }
85+
86+ def ' should include custom pixi build image with conda package' () {
87+ given :
88+ def app = new App ()
89+ String [] args = [
90+ " --conda-package" , " foo" ,
91+ " --pixi-build-image" , " my/pixi:latest"
92+ ]
93+
94+ when :
95+ new CommandLine (app). parseArgs(args)
96+ and :
97+ def req = app. createRequest()
98+ then :
99+ req. packages. type == PackagesSpec.Type . CONDA
100+ req. packages. entries == [' foo' ]
101+ and :
102+ req. packages. pixiOpts == new PixiOpts (
103+ pixiImage : ' my/pixi:latest' ,
104+ baseImage : PixiOpts . DEFAULT_BASE_IMAGE ,
105+ basePackages : PixiOpts . DEFAULT_PACKAGES
106+ )
107+ }
108+
109+ def ' should include custom pixi base image with conda package' () {
110+ given :
111+ def app = new App ()
112+ String [] args = [
113+ " --conda-package" , " foo" ,
114+ " --pixi-base-image" , " ubuntu:22.04"
115+ ]
116+
117+ when :
118+ new CommandLine (app). parseArgs(args)
119+ and :
120+ def req = app. createRequest()
121+ then :
122+ req. packages. type == PackagesSpec.Type . CONDA
123+ req. packages. entries == [' foo' ]
124+ and :
125+ req. packages. pixiOpts == new PixiOpts (
126+ pixiImage : PixiOpts . DEFAULT_PIXI_IMAGE ,
127+ baseImage : ' ubuntu:22.04' ,
128+ basePackages : PixiOpts . DEFAULT_PACKAGES
129+ )
130+ }
131+
132+ def ' should include custom pixi base packages with conda package' () {
133+ given :
134+ def app = new App ()
135+ String [] args = [
136+ " --conda-package" , " foo" ,
137+ " --pixi-base-packages" , " conda-forge::curl"
138+ ]
139+
140+ when :
141+ new CommandLine (app). parseArgs(args)
142+ and :
143+ def req = app. createRequest()
144+ then :
145+ req. packages. type == PackagesSpec.Type . CONDA
146+ req. packages. entries == [' foo' ]
147+ and :
148+ req. packages. pixiOpts == new PixiOpts (
149+ pixiImage : PixiOpts . DEFAULT_PIXI_IMAGE ,
150+ baseImage : PixiOpts . DEFAULT_BASE_IMAGE ,
151+ basePackages : ' conda-forge::curl'
152+ )
153+ }
154+
155+ def ' should include pixi run commands with conda package' () {
156+ given :
157+ def app = new App ()
158+ String [] args = [
159+ " --conda-package" , " foo" ,
160+ " --pixi-run-command" , " RUN apt-get update" ,
161+ " --pixi-run-command" , " RUN apt-get install -y curl"
162+ ]
163+
164+ when :
165+ new CommandLine (app). parseArgs(args)
166+ and :
167+ def req = app. createRequest()
168+ then :
169+ req. packages. type == PackagesSpec.Type . CONDA
170+ req. packages. entries == [' foo' ]
171+ and :
172+ req. packages. pixiOpts == new PixiOpts (
173+ pixiImage : PixiOpts . DEFAULT_PIXI_IMAGE ,
174+ baseImage : PixiOpts . DEFAULT_BASE_IMAGE ,
175+ basePackages : PixiOpts . DEFAULT_PACKAGES ,
176+ commands : [' RUN apt-get update' , ' RUN apt-get install -y curl' ]
177+ )
178+ }
179+
180+ def ' should include all pixi options' () {
181+ given :
182+ def app = new App ()
183+ String [] args = [
184+ " --conda-package" , " foo" ,
185+ " --conda-package" , " bar" ,
186+ " --pixi-build-image" , " custom/pixi:v1" ,
187+ " --pixi-base-image" , " debian:12" ,
188+ " --pixi-base-packages" , " conda-forge::wget" ,
189+ " --pixi-run-command" , " RUN one" ,
190+ " --pixi-run-command" , " RUN two"
191+ ]
192+
193+ when :
194+ new CommandLine (app). parseArgs(args)
195+ and :
196+ def req = app. createRequest()
197+ then :
198+ req. packages. type == PackagesSpec.Type . CONDA
199+ req. packages. entries == [' foo' , ' bar' ]
200+ and :
201+ req. packages. pixiOpts == new PixiOpts (
202+ pixiImage : ' custom/pixi:v1' ,
203+ baseImage : ' debian:12' ,
204+ basePackages : ' conda-forge::wget' ,
205+ commands : [' RUN one' , ' RUN two' ]
206+ )
207+ }
208+ }
0 commit comments