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 . trim ( )
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 {
@@ -364,24 +359,10 @@ async function startHelmRegistry() {
364359 return {
365360 url : `http://localhost:${ port } ` ,
366361 async stop ( ) {
367- // There is an error "response from daemon: 404 page not found"
368- // with full ID not sure why
369- 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 ( )
362+ const { status, stderr } = await run ( [ "docker" , "stop" , containerID ] )
382363
383364 if ( ! status . success ) {
384- const dockerStopError = new TextDecoder ( ) . decode ( stderr )
365+ const dockerStopError = stderr
385366 throw new Error (
386367 `Could not stop helm registry docker container ${ containerID } ${ dockerStopError } `
387368 )
@@ -663,3 +644,67 @@ Deno.test({
663644 assertEquals ( status . success , true )
664645 } ,
665646} )
647+
648+ Deno . test ( {
649+ name :
650+ "should successfuly run `helm deno template` with remote deno chart (with --repo option)" ,
651+ ignore : ! runAllTests ,
652+ async fn ( ) {
653+ const { status } = await runHelmDeno ( [
654+ "template" ,
655+ "ingress" ,
656+ "nginx-ingress" ,
657+ "--repo" ,
658+ "https://charts.helm.sh/stable" ,
659+ "--version" ,
660+ "1.41.3" ,
661+ ] )
662+
663+ assertEquals ( status . success , true )
664+ } ,
665+ } )
666+
667+ async function addStableRepo ( ) {
668+ const tmpRepoName = `tmp-repo-${ Math . random ( ) . toFixed ( 10 ) . slice ( 2 ) } `
669+ const repoAddCmd = await runHelm ( [
670+ "repo" ,
671+ "add" ,
672+ tmpRepoName ,
673+ "https://charts.helm.sh/stable" ,
674+ ] )
675+
676+ assertEquals ( repoAddCmd . status . success , true )
677+ return {
678+ name : tmpRepoName ,
679+ async cleanup ( ) {
680+ const repoAddCmd = await runHelm ( [ "repo" , "remove" , tmpRepoName ] )
681+
682+ if ( ! repoAddCmd . status . success ) {
683+ throw new Error ( `Could not remove repo ${ tmpRepoName } ` )
684+ }
685+ } ,
686+ }
687+ }
688+
689+ Deno . test ( {
690+ name :
691+ "should successfuly run `helm deno template` with remote chart (with helm repo add)" ,
692+ ignore : ! runAllTests ,
693+ async fn ( ) {
694+ const tmpRepo = await addStableRepo ( )
695+
696+ try {
697+ const templateCmd = await runHelmDeno ( [
698+ "template" ,
699+ "ingress" ,
700+ `${ tmpRepo . name } /nginx-ingress` ,
701+ "--version" ,
702+ "1.41.3" ,
703+ ] )
704+
705+ assertEquals ( templateCmd . status . success , true )
706+ } finally {
707+ await tmpRepo . cleanup ( )
708+ }
709+ } ,
710+ } )
0 commit comments