1- import { getAvailablePort } from "https://deno.land/x/port/mod.ts"
1+ import { getAvailablePort } from "https://deno.land/x/port@1.0.0 /mod.ts"
22import * as fs from "https://deno.land/std@0.86.0/fs/mod.ts"
33import * as path from "https://deno.land/std@0.86.0/path/mod.ts"
44import * as yaml from "https://deno.land/std@0.86.0/encoding/yaml.ts"
@@ -17,9 +17,9 @@ function toText(bytes: Uint8Array): string {
1717 return new TextDecoder ( ) . decode ( bytes )
1818}
1919
20- async function runHelmDeno ( args : string [ ] ) {
20+ async function run ( args : string [ ] ) {
2121 const cmd = Deno . run ( {
22- cmd : [ helmDenoBin , ... args ] ,
22+ cmd : args ,
2323 env : {
2424 HELM_PLUGIN_DIR : helmPluginDir ,
2525 } ,
@@ -37,6 +37,14 @@ async function runHelmDeno(args: string[]) {
3737 return { status, stdout : toText ( output ) , stderr : toText ( error ) }
3838}
3939
40+ async function runHelm ( args : string [ ] ) {
41+ return await run ( [ Deno . env . get ( "HELM_BIN" ) as string , ...args ] )
42+ }
43+
44+ async function runHelmDeno ( args : string [ ] ) {
45+ return await run ( [ helmDenoBin , ...args ] )
46+ }
47+
4048Deno . test ( {
4149 name : "should successfuly run `helm deno template` with deno chart" ,
4250 async fn ( ) {
@@ -314,39 +322,26 @@ function sleep(ms: number): Promise<void> {
314322
315323async function startHelmRegistry ( ) {
316324 const port = await getAvailablePort ( )
317- const cmd = Deno . run ( {
318- cmd : [
319- "docker" ,
320- "run" ,
321- "--rm" ,
322- "--detach" ,
323- `--publish=${ port } :8080` ,
324- "--env=STORAGE=local" ,
325- "--env=STORAGE_LOCAL_ROOTDIR=/home/chartmuseum/charts" ,
326- "chartmuseum/chartmuseum:v0.12.0@sha256:38c5ec3b30046d7a02a55b4c8bd8a0cd279538c2e36090973798a858e900b18e" ,
327- ] ,
328- stdout : "piped" ,
329- stderr : "piped" ,
330- } )
331-
332- const [ status , stdout , stderr ] = await Promise . all ( [
333- cmd . status ( ) ,
334- cmd . output ( ) ,
335- cmd . stderrOutput ( ) ,
325+ const { status, stdout, stderr } = await run ( [
326+ "docker" ,
327+ "run" ,
328+ "--rm" ,
329+ "--detach" ,
330+ `--publish=${ port } :8080` ,
331+ "--env=STORAGE=local" ,
332+ "--env=STORAGE_LOCAL_ROOTDIR=/home/chartmuseum/charts" ,
333+ "chartmuseum/chartmuseum:v0.12.0@sha256:38c5ec3b30046d7a02a55b4c8bd8a0cd279538c2e36090973798a858e900b18e" ,
336334 ] )
337- cmd . close ( )
338335
339336 if ( ! status . success ) {
340- throw new Error (
341- `Could not start chartmuseum ${ new TextDecoder ( ) . decode ( stderr ) } `
342- )
337+ throw new Error ( `Could not start chartmuseum ${ stderr } ` )
343338 }
344- const containerID = new TextDecoder ( ) . decode ( stdout )
339+ const containerID = stdout
345340
346341 let errorsCount = 0
347342 // eslint-disable-next-line no-constant-condition
348343 while ( true ) {
349- if ( errorsCount > 100 ) {
344+ if ( errorsCount > 10 ) {
350345 throw new Error ( "To many errors" )
351346 }
352347 try {
@@ -367,21 +362,10 @@ async function startHelmRegistry() {
367362 // There is an error "response from daemon: 404 page not found"
368363 // with full ID not sure why
369364 const shortContainerID = containerID . slice ( 0 , 12 )
370- const cmd = Deno . run ( {
371- cmd : [ "docker" , "stop" , shortContainerID ] ,
372- stdout : "piped" ,
373- stderr : "piped" ,
374- } )
375-
376- const [ status , , stderr ] = await Promise . all ( [
377- cmd . status ( ) ,
378- cmd . output ( ) ,
379- cmd . stderrOutput ( ) ,
380- ] )
381- cmd . close ( )
365+ const { status, stderr } = await run ( [ "docker" , "stop" , shortContainerID ] )
382366
383367 if ( ! status . success ) {
384- const dockerStopError = new TextDecoder ( ) . decode ( stderr )
368+ const dockerStopError = stderr
385369 throw new Error (
386370 `Could not stop helm registry docker container ${ containerID } ${ dockerStopError } `
387371 )
@@ -663,3 +647,67 @@ Deno.test({
663647 assertEquals ( status . success , true )
664648 } ,
665649} )
650+
651+ Deno . test ( {
652+ name :
653+ "should successfuly run `helm deno template` with remote deno chart (with --repo option)" ,
654+ ignore : ! runAllTests ,
655+ async fn ( ) {
656+ const { status } = await runHelmDeno ( [
657+ "template" ,
658+ "ingress" ,
659+ "nginx-ingress" ,
660+ "--repo" ,
661+ "https://charts.helm.sh/stable" ,
662+ "--version" ,
663+ "1.41.3" ,
664+ ] )
665+
666+ assertEquals ( status . success , true )
667+ } ,
668+ } )
669+
670+ async function addStableRepo ( ) {
671+ const tmpRepoName = `tmp-repo-${ Math . random ( ) . toFixed ( 10 ) . slice ( 2 ) } `
672+ const repoAddCmd = await runHelm ( [
673+ "repo" ,
674+ "add" ,
675+ tmpRepoName ,
676+ "https://charts.helm.sh/stable" ,
677+ ] )
678+
679+ assertEquals ( repoAddCmd . status . success , true )
680+ return {
681+ name : tmpRepoName ,
682+ async cleanup ( ) {
683+ const repoAddCmd = await runHelm ( [ "repo" , "remove" , tmpRepoName ] )
684+
685+ if ( ! repoAddCmd . status . success ) {
686+ throw new Error ( `Could not remove repo ${ tmpRepoName } ` )
687+ }
688+ } ,
689+ }
690+ }
691+
692+ Deno . test ( {
693+ name :
694+ "should successfuly run `helm deno template` with remote chart (with helm repo add)" ,
695+ ignore : ! runAllTests ,
696+ async fn ( ) {
697+ const tmpRepo = await addStableRepo ( )
698+
699+ try {
700+ const templateCmd = await runHelmDeno ( [
701+ "template" ,
702+ "ingress" ,
703+ `${ tmpRepo . name } /nginx-ingress` ,
704+ "--version" ,
705+ "1.41.3" ,
706+ ] )
707+
708+ assertEquals ( templateCmd . status . success , true )
709+ } finally {
710+ await tmpRepo . cleanup ( )
711+ }
712+ } ,
713+ } )
0 commit comments