forked from codeboten/github-action-to-otlp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
45 lines (32 loc) · 1.04 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestParseConfig(t *testing.T) {
_, err := parseConfig()
require.Error(t, err)
require.Contains(t, err.Error(), "invalid endpoint")
os.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "endpoint:443")
_, err = parseConfig()
require.Error(t, err)
require.Contains(t, err.Error(), "missing variable: GITHUB_REPOSITORY")
os.Setenv("GITHUB_REPOSITORY", "garbage")
_, err = parseConfig()
require.Error(t, err)
require.Contains(t, err.Error(), "missing variable: GITHUB_RUN_ID")
os.Setenv("GITHUB_RUN_ID", "123")
_, err = parseConfig()
require.Error(t, err)
require.Contains(t, err.Error(), "missing variable: GITHUB_WORKFLOW")
os.Setenv("GITHUB_WORKFLOW", "test name")
_, err = parseConfig()
require.Error(t, err)
require.Contains(t, err.Error(), "invalid variable GITHUB_REPOSITORY: garbage")
os.Setenv("GITHUB_REPOSITORY", "test/code")
conf, err := parseConfig()
require.NoError(t, err)
require.Equal(t, "test", conf.owner)
require.Equal(t, "code", conf.repo)
}