import { join } from "path" ; import { ConfigGraph , GardenModule , ProjectConfig } from "@garden-io/sdk/types" ; import { expect } from "chai" ; import { makeTestGarden , TestGarden } from "@garden-io/sdk/testing" ; import { defaultApiVersion , defaultNamespace } from "@garden-io/sdk/constants" ; import { gardenPlugin } from ".." ; describe ( "jib-container" , ( ) => { const projectRoot = join ( __dirname , "test-project" ) ; const projectConfig = { apiVersion : defaultApiVersion , kind : "Project" , name : "test" , path : projectRoot , defaultEnvironment : "default" , dotIgnoreFiles : [ ] , environments : [ { name : "default" , defaultNamespace , variables : { } } ] , providers : [ { name : "jib" } ] , variables : { } , } ; let garden ; let graph ; let actions ; let module ; before ( async ( ) => { garden = await makeTestGarden ( projectRoot , { plugins : [ gardenPlugin ] , config : projectConfig , } ) ; graph = await garden . getConfigGraph ( { log : garden . log , emit : false } ) ; actions = await garden . getActionRouter ( ) ; } ) ; beforeEach ( async ( ) => { graph = await garden . getConfigGraph ( { log : garden . log , emit : false } ) ; module = graph . getModule ( "module" ) ; } ) ; describe ( "configure" , ( ) => { it ( "sets relevant parameters on the buildConfig and spec fields" , async ( ) => { expect ( module . buildConfig ?. projectType ) . to . equal ( "auto" ) ; expect ( module . buildConfig ?. jdkVersion ) . to . equal ( 11 ) ; expect ( module . buildConfig ?. dockerfile ) . to . equal ( "_jib" ) ; expect ( module . spec . dockerfile ) . to . equal ( "_jib" ) ; } ) ; } ) ; describe ( "getModuleOutputs" , ( ) => { it ( "correctly sets the module outputs" , async ( ) => { const image = "eu.gcr.io/garden-ci/jib-test-project" ; expect ( module . outputs ) . to . eql ( { "deployment-image-id" : image + ":" + module . version . versionString , "deployment-image-name" : image , "local-image-id" : image + ":" + module . version . versionString , "local-image-name" : image , } ) ; } ) ; } ) ; describe ( "build" , ( ) => { context ( "tarOnly=true" , ( ) => { it ( "builds a maven project" , async ( ) => { module . spec . build . projectType = "maven" ; module . spec . build . tarOnly = true ; const res = await actions . build ( { module , log : garden . log , graph , } ) ; const { tarPath } = res . details ; expect ( tarPath ) . to . equal ( join ( module . path , "target" , `jib-image-module-${ module . version . versionString }.tar` ) ) ; } ) ; it ( "builds a gradle project" , async ( ) => { module . spec . build . projectType = "gradle" ; module . spec . build . tarOnly = true ; const res = await actions . build ( { module , log : garden . log , graph , } ) ; const { tarPath } = res . details ; expect ( tarPath ) . to . equal ( join ( module . path , "build" , `jib-image-module-${ module . version . versionString }.tar` ) ) ; } ) ; } ) ; context ( "tarOnly=false" , ( ) => { it . skip ( "builds a maven project and pushed to a registry" , async ( ) => { module . spec . build . projectType = "maven" ; module . spec . build . tarOnly = false ; await actions . build ( { module , log : garden . log , graph , } ) ; } ) ; it . skip ( "builds a gradle project and pushes to a registry" , async ( ) => { module . spec . build . projectType = "gradle" ; module . spec . build . tarOnly = false ; await actions . build ( { module , log : garden . log , graph , } ) ; } ) ; } ) ; context ( "dockerBuild=true" , ( ) => { it ( "builds a maven project" , async ( ) => { module . spec . build . projectType = "maven" ; module . spec . build . tarOnly = false ; module . spec . build . dockerBuild = true ; await actions . build ( { module , log : garden . log , graph , } ) ; } ) ; it ( "builds a gradle project" , async ( ) => { module . spec . build . projectType = "gradle" ; module . spec . build . tarOnly = false ; module . spec . build . dockerBuild = true ; await actions . build ( { module , log : garden . log , graph , } ) ; } ) ; } ) ; } ) ; } ) ;