-
Notifications
You must be signed in to change notification settings - Fork 52
/
module_test.go
58 lines (46 loc) · 1.4 KB
/
module_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
46
47
48
49
50
51
52
53
54
55
56
57
58
package module_test
import (
"errors"
"testing"
"github.com/commitdev/zero/internal/config/moduleconfig"
"github.com/stretchr/testify/assert"
"github.com/commitdev/zero/internal/module"
)
func TestGetSourceDir(t *testing.T) {
source := "tests/test_data/modules"
relativeSource := source
dir := module.GetSourceDir(source)
t.Log("dir", dir)
if dir != relativeSource {
t.Errorf("Error, local sources should not be changed: %s", source)
}
source = "github.com/commitdev/my-repo"
dir = module.GetSourceDir(source)
if dir == relativeSource {
t.Errorf("Error, remote sources should be converted to a local dir: %s", source)
}
}
func TestNewTemplateModule(t *testing.T) {
testModuleSource := "../../tests/test_data/modules/ci"
var mod moduleconfig.ModuleConfig
t.Run("Loading module from source", func(t *testing.T) {
mod, _ = module.ParseModuleConfig(testModuleSource)
assert.Equal(t, "CI templates", mod.Name)
})
t.Run("Parameters are loaded", func(t *testing.T) {
param, err := findParameter(mod.Parameters, "platform")
if err != nil {
panic(err)
}
assert.Equal(t, "platform", param.Field)
assert.Equal(t, "CI Platform", param.Label)
})
}
func findParameter(params []moduleconfig.Parameter, field string) (moduleconfig.Parameter, error) {
for _, v := range params {
if v.Field == field {
return v, nil
}
}
return moduleconfig.Parameter{}, errors.New("parameter not found")
}