1+ import path from "path" ;
12import { create as createBedrockYaml } from "../../lib/bedrockYaml" ;
23import { disableVerboseLogging , enableVerboseLogging } from "../../logger" ;
3-
4+ import { IBedrockFile , IBedrockServiceConfig } from "../../types" ;
45import {
56 addChartToRing ,
67 checkForFabrikate ,
@@ -21,8 +22,6 @@ import {
2122} from "./reconcile" ;
2223import * as reconcile from "./reconcile" ;
2324
24- import { IBedrockFile , IBedrockServiceConfig } from "../../types" ;
25-
2625beforeAll ( ( ) => {
2726 enableVerboseLogging ( ) ;
2827} ) ;
@@ -270,21 +269,22 @@ describe("addChartToRing", () => {
270269
271270 const branch = "v1" ;
272271 const git = "github.com/company/service" ;
273- const path = "/charts/service" ;
272+ const chartPath = "/charts/service" ;
274273
275274 const serviceConfig : IBedrockServiceConfig = {
276275 helm : {
277276 chart : {
278277 branch,
279278 git,
280- path
279+ path : chartPath
281280 }
282281 } ,
283282 k8sBackendPort : 1337
284283 } ;
285284
286285 /* tslint:disable-next-line: no-string-literal */
287- const addHelmChartCommand = `fab add chart --source ${ git } --path ${ path } --branch ${ branch } --type helm` ;
286+ const addHelmChartCommand = `fab add chart --source ${ git } --path ${ chartPath } --branch ${ branch } --type helm` ;
287+
288288 const expectedInvocation = `cd ${ ringPath } && ${ addHelmChartCommand } ` ;
289289
290290 await addChartToRing ( exec , ringPath , serviceConfig ) ;
@@ -298,21 +298,22 @@ describe("addChartToRing", () => {
298298
299299 const sha = "f8a33e1d" ;
300300 const git = "github.com/company/service" ;
301- const path = "/charts/service" ;
301+ const chartPath = "/charts/service" ;
302302
303303 const serviceConfig : IBedrockServiceConfig = {
304304 helm : {
305305 chart : {
306306 git,
307- path,
307+ path : chartPath ,
308308 sha
309309 }
310310 } ,
311311 k8sBackendPort : 1337
312312 } ;
313313
314314 /* tslint:disable-next-line: no-string-literal */
315- const addHelmChartCommand = `fab add chart --source ${ git } --path ${ path } --version ${ sha } --type helm` ;
315+ const addHelmChartCommand = `fab add chart --source ${ git } --path ${ chartPath } --version ${ sha } --type helm` ;
316+
316317 const expectedInvocation = `cd ${ ringPath } && ${ addHelmChartCommand } ` ;
317318
318319 await addChartToRing ( exec , ringPath , serviceConfig ) ;
@@ -425,8 +426,8 @@ describe("reconcile tests", () => {
425426 let bedrockYaml : IBedrockFile ;
426427 const sha = "f8a33e1d" ;
427428 const git = "github.com/company/service" ;
428- const path = "/charts/service" ;
429-
429+ const pathToChart = "/charts/service" ;
430+ const accessTokenVariable = "SECRET_TOKEN" ;
430431 beforeEach ( ( ) => {
431432 dependencies = {
432433 addChartToRing : jest . fn ( ) . mockReturnValue ( Promise . resolve ( { } ) ) ,
@@ -452,12 +453,13 @@ describe("reconcile tests", () => {
452453 prod : { }
453454 } ,
454455 services : {
455- "./path/to/svc/" : {
456+ "./path/to/a/ svc/" : {
456457 disableRouteScaffold : false ,
457458 helm : {
458459 chart : {
460+ accessTokenVariable,
459461 git,
460- path,
462+ path : pathToChart ,
461463 sha
462464 }
463465 } ,
@@ -486,6 +488,12 @@ describe("reconcile tests", () => {
486488 expect ( dependencies . createStaticComponent ) . toHaveBeenCalledTimes ( 2 ) ;
487489 expect ( dependencies . createMiddlewareForRing ) . toHaveBeenCalledTimes ( 2 ) ;
488490 expect ( dependencies . createIngressRouteForRing ) . toHaveBeenCalledTimes ( 2 ) ;
491+ expect ( dependencies . generateAccessYaml ) . toHaveBeenCalledTimes ( 1 ) ;
492+ expect ( dependencies . generateAccessYaml ) . toBeCalledWith (
493+ "path/to/hld/service" ,
494+ git ,
495+ accessTokenVariable
496+ ) ;
489497 } ) ;
490498
491499 it ( "should be able to create a HLD without rings, when no rings are provided" , async ( ) => {
@@ -519,7 +527,7 @@ describe("reconcile tests", () => {
519527 helm : {
520528 chart : {
521529 git,
522- path,
530+ path : pathToChart ,
523531 sha
524532 }
525533 } ,
@@ -597,7 +605,7 @@ describe("reconcile tests", () => {
597605 helm : {
598606 chart : {
599607 git,
600- path,
608+ path : pathToChart ,
601609 sha
602610 }
603611 } ,
@@ -626,7 +634,7 @@ describe("reconcile tests", () => {
626634 helm : {
627635 chart : {
628636 git,
629- path,
637+ path : pathToChart ,
630638 sha
631639 }
632640 } ,
@@ -659,7 +667,7 @@ describe("reconcile tests", () => {
659667 helm : {
660668 chart : {
661669 git,
662- path,
670+ path : pathToChart ,
663671 sha
664672 }
665673 } ,
@@ -681,6 +689,43 @@ describe("reconcile tests", () => {
681689 ( dependencies . createServiceComponent as jest . Mock ) . mock . calls [ 0 ] [ 2 ]
682690 ) . toBe ( displayName ) ;
683691 } ) ;
692+
693+ it ( "properly updates access.yaml" , async ( ) => {
694+ const anotherGit = "github.com/foobar/baz" ;
695+ const anotherToken = "MY_FANCY_ENV_VAR" ;
696+ bedrockYaml . services [ "another/service" ] = {
697+ disableRouteScaffold : false ,
698+ helm : {
699+ chart : {
700+ accessTokenVariable : anotherToken ,
701+ git : anotherGit ,
702+ path : "path/to/chart" ,
703+ sha : "12345"
704+ }
705+ } ,
706+ k8sBackendPort : 8888
707+ } ;
708+ const pathToHLD = "./the/path/to/hld" ;
709+ const service = "service" ;
710+ await reconcileHld (
711+ dependencies ,
712+ bedrockYaml ,
713+ service ,
714+ pathToHLD ,
715+ "./path/to/app"
716+ ) ;
717+ expect ( dependencies . generateAccessYaml ) . toHaveBeenCalledTimes ( 2 ) ;
718+ expect ( dependencies . generateAccessYaml ) . toHaveBeenCalledWith (
719+ path . join ( pathToHLD , service ) ,
720+ git ,
721+ accessTokenVariable
722+ ) ;
723+ expect ( dependencies . generateAccessYaml ) . toHaveBeenCalledWith (
724+ path . join ( pathToHLD , service ) ,
725+ anotherGit ,
726+ anotherToken
727+ ) ;
728+ } ) ;
684729} ) ;
685730
686731describe ( "normalizedName" , ( ) => {
0 commit comments