summaryrefslogtreecommitdiffstats
path: root/pkg/jobparser/jobparser_test.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-20 23:07:42 +0200
committerDaniel Baumann <daniel@debian.org>2024-11-09 15:38:42 +0100
commit714c83b2736d7e308bc33c49057952490eb98be2 (patch)
tree1d9ba7035798368569cd49056f4d596efc908cd8 /pkg/jobparser/jobparser_test.go
parentInitial commit. (diff)
downloadforgejo-act-714c83b2736d7e308bc33c49057952490eb98be2.tar.xz
forgejo-act-714c83b2736d7e308bc33c49057952490eb98be2.zip
Adding upstream version 1.21.4.HEADupstream/1.21.4upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'pkg/jobparser/jobparser_test.go')
-rw-r--r--pkg/jobparser/jobparser_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/pkg/jobparser/jobparser_test.go b/pkg/jobparser/jobparser_test.go
new file mode 100644
index 0000000..06ed825
--- /dev/null
+++ b/pkg/jobparser/jobparser_test.go
@@ -0,0 +1,81 @@
+package jobparser
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+
+ "github.com/stretchr/testify/require"
+
+ "gopkg.in/yaml.v3"
+)
+
+func TestParse(t *testing.T) {
+ tests := []struct {
+ name string
+ options []ParseOption
+ wantErr bool
+ }{
+ {
+ name: "multiple_named_matrix",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "multiple_jobs",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "multiple_matrix",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "has_needs",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "has_with",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "has_secrets",
+ options: nil,
+ wantErr: false,
+ },
+ {
+ name: "empty_step",
+ options: nil,
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ content := ReadTestdata(t, tt.name+".in.yaml")
+ want := ReadTestdata(t, tt.name+".out.yaml")
+ got, err := Parse(content, tt.options...)
+ if tt.wantErr {
+ require.Error(t, err)
+ }
+ require.NoError(t, err)
+
+ builder := &strings.Builder{}
+ for _, v := range got {
+ if builder.Len() > 0 {
+ builder.WriteString("---\n")
+ }
+ encoder := yaml.NewEncoder(builder)
+ encoder.SetIndent(2)
+ require.NoError(t, encoder.Encode(v))
+ id, job := v.Job()
+ assert.NotEmpty(t, id)
+ assert.NotNil(t, job)
+ }
+ assert.Equal(t, string(want), builder.String())
+ })
+ }
+}