go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/cli/execruntime/env_azure_test.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package execruntime
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestAzureRuntimeEnv(t *testing.T) {
    13  	// set mock provider
    14  	environmentProvider = newMockEnvProvider()
    15  	environmentProvider.Setenv("CI", "1")
    16  	environmentProvider.Setenv("TF_BUILD", "1")
    17  	environmentProvider.Setenv("BUILD_REPOSITORY_NAME", "example-project")
    18  	environmentProvider.Setenv("BUILD_BUILDID", "1")
    19  	environmentProvider.Setenv("BUILD_SOURCEVERSION", "897248974893749873894789374")
    20  	environmentProvider.Setenv("BUILD_SOURCEVERSIONAUTHOR", "vj")
    21  
    22  	env := Detect()
    23  	assert.True(t, env.IsAutomatedEnv())
    24  	assert.Equal(t, AZUREPIPELINE, env.Id)
    25  	assert.Equal(t, "Azure Pipelines", env.Name)
    26  
    27  	annotations := env.Labels()
    28  	assert.Equal(t, 5, len(annotations))
    29  	assert.Equal(t, "devops.azure.com", annotations["mondoo.com/exec-environment"])
    30  	assert.Equal(t, "example-project", annotations["devops.azure.com/repository-name"])
    31  	assert.Equal(t, "1", annotations["devops.azure.com/buildid"])
    32  	assert.Equal(t, "vj", annotations["devops.azure.com/sourceversionauthor"])
    33  }