go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/cli/execruntime/env_github_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 TestGithubRuntimeEnv(t *testing.T) { 13 // set mock provider 14 environmentProvider = newMockEnvProvider() 15 environmentProvider.Setenv("CI", "1") 16 environmentProvider.Setenv("GITHUB_ACTION", "action") 17 environmentProvider.Setenv("GITHUB_SHA", "1234") 18 environmentProvider.Setenv("GITHUB_REF", "example-project") 19 environmentProvider.Setenv("GITHUB_ACTOR", "johndoe") 20 environmentProvider.Setenv("GITHUB_RUN_NUMBER", "23") 21 22 env := Detect() 23 assert.True(t, env.IsAutomatedEnv()) 24 assert.Equal(t, GITHUB, env.Id) 25 assert.Equal(t, "GitHub Actions", env.Name) 26 27 annotations := env.Labels() 28 assert.Equal(t, 6, len(annotations)) 29 assert.Equal(t, "actions.github.com", annotations["mondoo.com/exec-environment"]) 30 assert.Equal(t, "action", annotations["actions.github.com/action"]) 31 assert.Equal(t, "1234", annotations["actions.github.com/sha"]) 32 assert.Equal(t, "example-project", annotations["actions.github.com/ref"]) 33 assert.Equal(t, "johndoe", annotations["actions.github.com/actor"]) 34 assert.Equal(t, "23", annotations["actions.github.com/run-number"]) 35 }