| garciadeblas | 83775ba | 2025-07-23 18:35:24 +0200 | [diff] [blame] | 1 | ####################################################################################### |
| 2 | # Copyright ETSI Contributors and Others. |
| 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 |
| 13 | # implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | ####################################################################################### |
| 17 | |
| 18 | # Module with custom functions to manage KSUs and their renderization of the corresponding ResourceList into a given target folder. |
| 19 | |
| 20 | |
| 21 | # Imports |
| 22 | use std assert |
| 23 | use ../location.nu * |
| 24 | |
| 25 | |
| 26 | ### to path components tests ### |
| 27 | |
| 28 | export def "test location to path components repo-path with base-path" [] { |
| 29 | let input: record = { |
| 30 | "repo-path": ["/custom/repo"], |
| 31 | "base-path": ["base/dir"], # Now unused in base construction |
| 32 | "relative-path": ["file.txt"] |
| 33 | } |
| 34 | let actual: list<string> = ($input | to path components) |
| 35 | let expected: list<string> = [ "/custom/repo" "base/dir" "file.txt" ] |
| 36 | assert equal $actual $expected |
| 37 | } |
| 38 | |
| 39 | |
| 40 | export def "test location to path components repo-path with base-path with strings" [] { |
| 41 | let input: record = { |
| 42 | "repo-path": "/custom/repo", |
| 43 | "base-path": "base/dir", # Now unused in base construction |
| 44 | "relative-path": "file.txt" |
| 45 | } |
| 46 | let actual: list<string> = ($input | to path components) |
| 47 | let expected: list<string> = [ "/custom/repo" "base/dir" "file.txt" ] |
| 48 | assert equal $actual $expected |
| 49 | } |
| 50 | |
| 51 | |
| 52 | export def "test location to path components explicit base-path usage" [] { |
| 53 | let input: record = { |
| 54 | "repo-name": "my_repo", |
| 55 | "base-path": "explicit/base", |
| 56 | "relative-path": "data.csv" |
| 57 | } |
| 58 | let actual: list<string> = ($input | to path components) |
| 59 | let expected: list<string> = [ "/repos/my_repo" "explicit/base" "data.csv" ] |
| 60 | assert equal $actual $expected |
| 61 | } |
| 62 | |
| 63 | |
| 64 | export def "test location to path components empty repo-name errors" [] { |
| 65 | let input: record = { |
| 66 | "repo-name": "", |
| 67 | "relative-path": "file.txt" |
| 68 | } |
| 69 | assert error { $input | to path components } |
| 70 | } |
| 71 | |
| 72 | |
| 73 | export def "test location to path components partial profile spec errors" [] { |
| 74 | let input: record = { |
| 75 | "repo-path": "/valid/repo", |
| 76 | "profile-type": "dev", |
| 77 | "relative-path": "file.txt" |
| 78 | } |
| 79 | assert error { $input | to path components } |
| 80 | } |
| 81 | |
| 82 | |
| 83 | export def "test location to path components mixed spec priorities" [] { |
| 84 | let input: record = { |
| 85 | "repo-path": "/primary/repo", |
| 86 | "repo-name": "secondary", |
| 87 | "base-path": "explicit_base", |
| 88 | "oka-type": "models", |
| 89 | "oka-name": "ai", |
| 90 | "relative-path": "config.yaml" |
| 91 | } |
| 92 | let actual: list<string> = ($input | to path components) |
| 93 | let expected: list<string> = [ "/primary/repo" "explicit_base" "config.yaml" ] |
| 94 | assert equal $actual $expected |
| 95 | } |
| 96 | |
| 97 | |
| 98 | # Updated existing tests with clearer names |
| 99 | export def "test location to path components profile-based with normalization" [] { |
| 100 | let input: record = { |
| 101 | "repo-name": "profile_repo", |
| 102 | "profile-type": "PROD", |
| 103 | "profile-name": "EU_Cluster", |
| 104 | "relative-path": "secrets.env" |
| 105 | } |
| 106 | let actual: list<string> = ($input | to path components) |
| 107 | let expected: list<string> = [ "/repos/profile_repo" "osm_admin/PROD/EU_Cluster" "secrets.env" ] |
| 108 | assert equal $actual $expected |
| 109 | } |
| 110 | |
| 111 | |
| 112 | export def "test location to path components oka-based with normalization" [] { |
| 113 | let input: record = { |
| 114 | "repo-path": "/repos/oka_repo", |
| 115 | "oka-type": "DATA", |
| 116 | "oka-name": "Census2025", |
| 117 | "relative-path": "demographics.csv" |
| 118 | } |
| 119 | let actual: list<string> = ($input | to path components) |
| 120 | let expected: list<string> = [ "/repos/oka_repo" "DATA/Census2025" "demographics.csv" ] |
| 121 | assert equal $actual $expected |
| 122 | } |
| 123 | |
| 124 | |
| 125 | # TODO: |
| 126 | |
| 127 | ### to absolute path tests ### |
| 128 | |
| 129 | export def "test location to absolute path basic repo-path" [] { |
| 130 | let input: record = { |
| 131 | "repo-path": ["/main/repo", "sw-catalogs"], |
| 132 | "base-path": ["apps", "example1"], |
| 133 | "relative-path": ["manifests", "main-pattern", "main-brick-manifests"] |
| 134 | } |
| 135 | let actual: string = ($input | to absolute path) |
| 136 | let expected: string = "/main/repo/sw-catalogs/apps/example1/manifests/main-pattern/main-brick-manifests" |
| 137 | assert equal $actual $expected |
| 138 | } |
| 139 | |
| 140 | |
| 141 | export def "test location to absolute path profile-based with defaults" [] { |
| 142 | let input: record = { |
| 143 | "repo-name": "fleet", |
| 144 | "profile-type": "dev", |
| 145 | "profile-name": "TestEnv", |
| 146 | "relative-path": ["app_instance01", "main"] |
| 147 | } |
| 148 | let actual = ($input | to absolute path) |
| 149 | let expected = "/repos/fleet/osm_admin/dev/TestEnv/app_instance01/main" |
| 150 | assert equal $actual $expected |
| 151 | } |
| 152 | |
| 153 | |
| 154 | export def "test location to absolute path oka-based with custom defaults" [] { |
| 155 | let input: record = { |
| 156 | "repo-name": "data_repo", |
| 157 | "oka-type": "app", # It should be converted to "apps" |
| 158 | "oka-name": "upf", |
| 159 | "relative-path": ["2024", "main"] |
| 160 | } |
| 161 | let actual: string = ($input | to absolute path "geo" "/data") |
| 162 | let expected: string = "/data/data_repo/apps/upf/2024/main" |
| 163 | assert equal $actual $expected |
| 164 | } |
| 165 | |
| 166 | |
| 167 | export def "test location to absolute path mixed specifications priority" [] { |
| 168 | let input: record = { |
| 169 | "repo-name": "fleet", |
| 170 | "base-path": ["my_oka"], |
| 171 | "relative-path": ["manifests"] |
| 172 | } |
| 173 | let actual: string = ($input | to absolute path) |
| 174 | let expected: string = "/repos/fleet/my_oka/manifests" |
| 175 | assert equal $actual $expected |
| 176 | } |
| 177 | |
| 178 | |
| 179 | export def "test location to absolute path special characters handling" [] { |
| 180 | let input: record = { |
| 181 | "repo-name": "fleet", |
| 182 | "profile-type": "apps", # Should become "app-profiles" |
| 183 | "profile-name": "mycluster01", |
| 184 | "relative-path": ["configs/prod"] |
| 185 | } |
| 186 | let actual: string = ($input | to absolute path) |
| 187 | let expected: string = "/repos/fleet/osm_admin/app-profiles/mycluster01/configs/prod" |
| 188 | assert equal $actual $expected |
| 189 | } |
| 190 | |
| 191 | |
| 192 | export def "test location to absolute path error missing relative-path" [] { |
| 193 | let input: record = { |
| 194 | "repo-path": ["/valid/repo"], |
| 195 | "base-path": ["valid/base"] |
| 196 | } |
| 197 | assert error { $input | to absolute path } |
| 198 | } |
| 199 | |
| 200 | |
| 201 | export def "test location to absolute path nested relative path" [] { |
| 202 | let input: record = { |
| 203 | "repo-path": ["/repos/core"], |
| 204 | "oka-type": "infra-controllers", |
| 205 | "oka-name": "predictive", |
| 206 | "relative-path": ["mobile", "serverless-web"] |
| 207 | } |
| 208 | let actual: string = ($input | to absolute path) |
| 209 | let expected: string = "/repos/core/infra-controllers/predictive/mobile/serverless-web" |
| 210 | assert equal $actual $expected |
| 211 | } |
| 212 | |
| 213 | |
| 214 | export def "test location to absolute path empty repo-name error" [] { |
| 215 | let input: record = { |
| 216 | "repo-name": "", |
| 217 | "relative-path": ["file.txt"] |
| 218 | } |
| 219 | assert error { $input | to absolute path } |
| 220 | } |
| 221 | |
| 222 | |
| 223 | export def "test location to absolute path minimal valid input" [] { |
| 224 | let input: record = { |
| 225 | "repo-name": "fleet", |
| 226 | "base-path": ["apps"], |
| 227 | "relative-path": ["test-app"] |
| 228 | } |
| 229 | let actual: string = ($input | to absolute path) |
| 230 | let expected: string = "/repos/fleet/apps/test-app" |
| 231 | assert equal $actual $expected |
| 232 | } |