forked from
tangled.org/core
fork
Configure Feed
Select the types of activity you want to include in your feed.
Monorepo for Tangled
fork
Configure Feed
Select the types of activity you want to include in your feed.
1package workflow
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7)
8
9func TestUnmarshalWorkflow(t *testing.T) {
10 yamlData := `
11when:
12 - event: ["push", "pull_request"]
13 branch: ["main", "develop"]
14
15dependencies:
16 nixpkgs:
17 - go
18 - git
19 - curl
20
21steps:
22 - name: "Test"
23 command: |
24 go test ./...`
25
26 wf, err := FromFile("test.yml", []byte(yamlData))
27 assert.NoError(t, err, "YAML should unmarshal without error")
28
29 assert.Len(t, wf.When, 1, "Should have one constraint")
30 assert.ElementsMatch(t, []string{"main", "develop"}, wf.When[0].Branch)
31 assert.ElementsMatch(t, []string{"push", "pull_request"}, wf.When[0].Event)
32
33 assert.Len(t, wf.Steps, 1)
34 assert.Equal(t, "Test", wf.Steps[0].Name)
35 assert.Equal(t, "go test ./...", wf.Steps[0].Command)
36
37 pkgs, ok := wf.Dependencies["nixpkgs"]
38 assert.True(t, ok, "`nixpkgs` should be present in dependencies")
39 assert.ElementsMatch(t, []string{"go", "git", "curl"}, pkgs)
40
41 assert.False(t, wf.CloneOpts.Skip, "Skip should default to false")
42}
43
44func TestUnmarshalCustomRegistry(t *testing.T) {
45 yamlData := `
46when:
47 - event: push
48 branch: main
49
50dependencies:
51 git+https://tangled.sh/@oppi.li/tbsp:
52 - tbsp
53 git+https://git.peppe.rs/languages/statix:
54 - statix
55
56steps:
57 - name: "Check"
58 command: |
59 statix check`
60
61 wf, err := FromFile("test.yml", []byte(yamlData))
62 assert.NoError(t, err, "YAML should unmarshal without error")
63
64 assert.ElementsMatch(t, []string{"push"}, wf.When[0].Event)
65 assert.ElementsMatch(t, []string{"main"}, wf.When[0].Branch)
66
67 assert.ElementsMatch(t, []string{"tbsp"}, wf.Dependencies["git+https://tangled.sh/@oppi.li/tbsp"])
68 assert.ElementsMatch(t, []string{"statix"}, wf.Dependencies["git+https://git.peppe.rs/languages/statix"])
69}
70
71func TestUnmarshalCloneFalse(t *testing.T) {
72 yamlData := `
73when:
74 - event: pull_request_close
75
76clone:
77 skip: true
78
79dependencies:
80 nixpkgs:
81 - python3
82
83steps:
84 - name: Notify
85 command: |
86 python3 ./notify.py
87`
88
89 wf, err := FromFile("test.yml", []byte(yamlData))
90 assert.NoError(t, err)
91
92 assert.ElementsMatch(t, []string{"pull_request_close"}, wf.When[0].Event)
93
94 assert.True(t, wf.CloneOpts.Skip, "Skip should be false")
95}
96
97func TestUnmarshalEnv(t *testing.T) {
98 yamlData := `
99when:
100 - event: ["pull_request_close"]
101
102clone:
103 skip: false
104
105environment:
106 HOME: /home/foo bar/baz
107 CGO_ENABLED: 1
108
109steps:
110 - name: Something
111 command: echo "hello"
112 environment:
113 FOO: bar
114 BAZ: qux
115`
116
117 wf, err := FromFile("test.yml", []byte(yamlData))
118 assert.NoError(t, err)
119
120 assert.Len(t, wf.Environment, 2)
121 assert.Equal(t, "/home/foo bar/baz", wf.Environment["HOME"])
122 assert.Equal(t, "1", wf.Environment["CGO_ENABLED"])
123 assert.Equal(t, "bar", wf.Steps[0].Environment["FOO"])
124 assert.Equal(t, "qux", wf.Steps[0].Environment["BAZ"])
125}