-
Notifications
You must be signed in to change notification settings - Fork 784
Expand file tree
/
Copy pathSeqeraExecutorTest.groovy
More file actions
159 lines (136 loc) · 5.28 KB
/
SeqeraExecutorTest.groovy
File metadata and controls
159 lines (136 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright 2013-2026, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seqera.executor
import io.seqera.config.SeqeraConfig
import io.seqera.sched.client.SchedClientConfig
import nextflow.Session
import nextflow.SysEnv
import nextflow.platform.PlatformHelper
import spock.lang.Specification
/**
* Tests for SeqeraExecutor client configuration
*
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
*/
class SeqeraExecutorTest extends Specification {
def cleanup() {
SysEnv.pop()
}
def 'should create client config with config settings'() {
given:
SysEnv.push([:])
when:
def config = buildClientConfig(
[endpoint: 'https://sched.example.com', region: 'us-west-2'],
[endpoint: 'https://api.platform.example.com', accessToken: 'config-access-token', refreshToken: 'config-refresh-token']
)
then:
config.endpoint == 'https://sched.example.com'
config.platformUrl == 'https://api.platform.example.com'
config.accessToken == 'config-access-token'
config.refreshToken == 'config-refresh-token'
}
def 'should create client config with env variable settings'() {
given:
SysEnv.push([
TOWER_API_ENDPOINT: 'https://api.env.example.com',
TOWER_ACCESS_TOKEN: 'env-access-token',
TOWER_REFRESH_TOKEN: 'env-refresh-token'
])
when:
def config = buildClientConfig(
[endpoint: 'https://sched.example.com', region: 'us-west-2'],
[:]
)
then:
config.endpoint == 'https://sched.example.com'
config.platformUrl == 'https://api.env.example.com'
config.accessToken == 'env-access-token'
config.refreshToken == 'env-refresh-token'
}
def 'should use default platform url when not configured'() {
given:
SysEnv.push([:])
when:
def config = buildClientConfig(
[endpoint: 'https://sched.example.com', region: 'us-west-2'],
[accessToken: 'my-token']
)
then:
config.endpoint == 'https://sched.example.com'
config.platformUrl == 'https://api.cloud.seqera.io'
config.accessToken == 'my-token'
config.refreshToken == null
}
def 'should prefer config over env variables'() {
given:
SysEnv.push([
TOWER_API_ENDPOINT: 'https://api.env.example.com',
TOWER_ACCESS_TOKEN: 'env-access-token',
TOWER_REFRESH_TOKEN: 'env-refresh-token'
])
when:
def config = buildClientConfig(
[endpoint: 'https://sched.example.com', region: 'us-west-2'],
[endpoint: 'https://api.config.example.com', accessToken: 'config-access-token', refreshToken: 'config-refresh-token']
)
then:
config.endpoint == 'https://sched.example.com'
config.platformUrl == 'https://api.config.example.com'
config.accessToken == 'config-access-token'
config.refreshToken == 'config-refresh-token'
}
def 'should set fusion default version when not configured' () {
given:
SysEnv.push([:])
def fusionConfig = [enabled: true]
def config = [fusion: fusionConfig]
def session = Mock(Session) { getConfig() >> config }
def executor = new SeqeraExecutor(session: session)
when:
executor.applyFusionDefaults()
then:
fusionConfig.targetVersion == '2.6'
}
def 'should not override fusion version when containerConfigUrl is set' () {
given:
SysEnv.push([:])
def fusionConfig = [enabled: true, containerConfigUrl: 'https://custom.url/v3.0-amd64.json']
def config = [fusion: fusionConfig]
def session = Mock(Session) { getConfig() >> config }
def executor = new SeqeraExecutor(session: session)
when:
executor.applyFusionDefaults()
then:
fusionConfig.targetVersion == null
}
/**
* Builds a SchedClientConfig using the same logic as {@link SeqeraExecutor#createClient()}
*/
private SchedClientConfig buildClientConfig(Map executorOpts, Map towerConfig) {
def seqeraConfig = new SeqeraConfig([executor: executorOpts]).executor
def accessToken = PlatformHelper.getAccessToken(towerConfig, SysEnv.get())
def refreshToken = PlatformHelper.getRefreshToken(towerConfig, SysEnv.get())
def platformUrl = PlatformHelper.getEndpoint(towerConfig, SysEnv.get())
return SchedClientConfig.builder()
.endpoint(seqeraConfig.endpoint)
.platformUrl(platformUrl)
.accessToken(accessToken)
.refreshToken(refreshToken)
.retryConfig(seqeraConfig.retryOpts())
.build()
}
}