| 7 | ) |
| 8 | |
| 9 | func TestIsCI(t *testing.T) { |
| 10 | tests := []struct { |
| 11 | name string |
| 12 | env map[string]string |
| 13 | want bool |
| 14 | }{ |
| 15 | {name: "no CI env vars", env: map[string]string{}, want: false}, |
| 16 | {name: "CI set", env: map[string]string{"CI": "true"}, want: true}, |
| 17 | {name: "BUILD_NUMBER set", env: map[string]string{"BUILD_NUMBER": "42"}, want: true}, |
| 18 | {name: "RUN_ID set", env: map[string]string{"RUN_ID": "abc"}, want: true}, |
| 19 | {name: "CI empty string", env: map[string]string{"CI": ""}, want: false}, |
| 20 | } |
| 21 | for _, tt := range tests { |
| 22 | t.Run(tt.name, func(t *testing.T) { |
| 23 | t.Setenv("CI", "") |
| 24 | t.Setenv("BUILD_NUMBER", "") |
| 25 | t.Setenv("RUN_ID", "") |
| 26 | for k, v := range tt.env { |
| 27 | t.Setenv(k, v) |
| 28 | } |
| 29 | assert.Equal(t, tt.want, IsCI()) |
| 30 | }) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestIsGitHubActions(t *testing.T) { |
| 35 | tests := []struct { |