@@ -1061,14 +1061,64 @@ describe('Config', () => {
10611061 } )
10621062
10631063 context ( 'sci embedding' , ( ) => {
1064+ const DUMMY_COMMIT_SHA = 'b7b5dfa992008c77ab3f8a10eb8711e0092445b0'
1065+ const DUMMY_REPOSITORY_URL = '[email protected] :DataDog/dd-trace-js.git' 1066+ let ddTags
1067+ beforeEach ( ( ) => {
1068+ ddTags = process . env . DD_TAGS
1069+ } )
10641070 afterEach ( ( ) => {
10651071 delete process . env . DD_GIT_PROPERTIES_FILE
1072+ delete process . env . DD_GIT_COMMIT_SHA
1073+ delete process . env . DD_GIT_REPOSITORY_URL
1074+ process . env . DD_TAGS = ddTags
10661075 } )
1067- it ( 'reads git.properties' , ( ) => {
1076+ it ( 'reads DD_GIT_* env vars' , ( ) => {
1077+ process . env . DD_GIT_COMMIT_SHA = DUMMY_COMMIT_SHA
1078+ process . env . DD_GIT_REPOSITORY_URL = DUMMY_REPOSITORY_URL
1079+ const config = new Config ( { } )
1080+ expect ( config ) . to . have . property ( 'commitSHA' , DUMMY_COMMIT_SHA )
1081+ expect ( config ) . to . have . property ( 'repositoryUrl' , DUMMY_REPOSITORY_URL )
1082+ } )
1083+ it ( 'reads DD_TAGS env var' , ( ) => {
1084+ process . env . DD_TAGS = `git.commit.sha:${ DUMMY_COMMIT_SHA } ,git.repository_url:${ DUMMY_REPOSITORY_URL } `
1085+ process . env . DD_GIT_REPOSITORY_URL = DUMMY_REPOSITORY_URL
1086+ const config = new Config ( { } )
1087+ expect ( config ) . to . have . property ( 'commitSHA' , DUMMY_COMMIT_SHA )
1088+ expect ( config ) . to . have . property ( 'repositoryUrl' , DUMMY_REPOSITORY_URL )
1089+ } )
1090+ it ( 'reads git.properties if it is available' , ( ) => {
10681091 process . env . DD_GIT_PROPERTIES_FILE = DD_GIT_PROPERTIES_FILE
10691092 const config = new Config ( { } )
10701093 expect ( config ) . to . have . property ( 'commitSHA' , '4e7da8069bcf5ffc8023603b95653e2dc99d1c7d' )
1071- expect ( config ) . to . have . property ( 'repositoryUrl' , '[email protected] :DataDog/dd-trace-js.git' ) 1094+ expect ( config ) . to . have . property ( 'repositoryUrl' , DUMMY_REPOSITORY_URL )
1095+ } )
1096+ it ( 'does not crash if git.properties is not available' , ( ) => {
1097+ process . env . DD_GIT_PROPERTIES_FILE = '/does/not/exist'
1098+ const config = new Config ( { } )
1099+ expect ( config ) . to . have . property ( 'commitSHA' , undefined )
1100+ expect ( config ) . to . have . property ( 'repositoryUrl' , undefined )
1101+ } )
1102+ it ( 'does not read git.properties if env vars are passed' , ( ) => {
1103+ process . env . DD_GIT_PROPERTIES_FILE = DD_GIT_PROPERTIES_FILE
1104+ process . env . DD_GIT_COMMIT_SHA = DUMMY_COMMIT_SHA
1105+ process . env . DD_GIT_REPOSITORY_URL = 'https://github.com:env-var/dd-trace-js.git'
1106+ const config = new Config ( { } )
1107+ expect ( config ) . to . have . property ( 'commitSHA' , DUMMY_COMMIT_SHA )
1108+ expect ( config ) . to . have . property ( 'repositoryUrl' , 'https://github.com:env-var/dd-trace-js.git' )
1109+ } )
1110+ it ( 'still reads git.properties if one of the env vars is missing' , ( ) => {
1111+ process . env . DD_GIT_PROPERTIES_FILE = DD_GIT_PROPERTIES_FILE
1112+ process . env . DD_GIT_COMMIT_SHA = DUMMY_COMMIT_SHA
1113+ const config = new Config ( { } )
1114+ expect ( config ) . to . have . property ( 'commitSHA' , DUMMY_COMMIT_SHA )
1115+ expect ( config ) . to . have . property ( 'repositoryUrl' , DUMMY_REPOSITORY_URL )
1116+ } )
1117+ it ( 'reads git.properties and filters out credentials' , ( ) => {
1118+ process . env . DD_GIT_PROPERTIES_FILE = require . resolve ( './fixtures/config/git.properties.credentials' )
1119+ const config = new Config ( { } )
1120+ expect ( config ) . to . have . property ( 'commitSHA' , '4e7da8069bcf5ffc8023603b95653e2dc99d1c7d' )
1121+ expect ( config ) . to . have . property ( 'repositoryUrl' , 'https://github.com/datadog/dd-trace-js' )
10721122 } )
10731123 } )
10741124} )
0 commit comments