|
| 1 | +package integrations |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func TestGetCurrentRef(t *testing.T) { |
| 11 | + // Github action specific environment variable |
| 12 | + os.Setenv("GITHUB_REF", "github-develop") |
| 13 | + |
| 14 | + actionCompareBranch := GetCurrentRef() |
| 15 | + |
| 16 | + assert.Equal(t, "github-develop", actionCompareBranch) |
| 17 | + |
| 18 | + os.Setenv("GITHUB_REF", "") |
| 19 | + |
| 20 | + // Gitlab specific environment variable |
| 21 | + os.Setenv("CI_COMMIT_REF_NAME", "gitlab-develop") |
| 22 | + |
| 23 | + gitlabCompareBranch := GetCurrentRef() |
| 24 | + |
| 25 | + assert.Equal(t, "gitlab-develop", gitlabCompareBranch) |
| 26 | + |
| 27 | + os.Setenv("CI_COMMIT_REF_NAME", "") |
| 28 | + |
| 29 | + // Drone specific environment variable |
| 30 | + os.Setenv("DRONE_COMMIT_REF", "drone-develop") |
| 31 | + |
| 32 | + droneCompareBranch := GetCurrentRef() |
| 33 | + |
| 34 | + assert.Equal(t, "drone-develop", droneCompareBranch) |
| 35 | + |
| 36 | + os.Setenv("DRONE_COMMIT_REF", "") |
| 37 | + |
| 38 | + // Should default to empty if no conditions are satisfied |
| 39 | + defaultMaster := GetCurrentRef() |
| 40 | + |
| 41 | + assert.Equal(t, "", defaultMaster) |
| 42 | +} |
0 commit comments