@@ -79,98 +79,82 @@ func TestLocalActionsFindMetadata(t *testing.T) {
79
79
proj := & Project {testdir , nil }
80
80
c := NewLocalActionsCache (proj , nil )
81
81
82
- for _ , spec := range []string {"./action-yml" , "./action-yaml" } {
83
- want := testGetWantedActionMetadata ()
84
- t .Run (spec , func (t * testing.T ) {
82
+ want := testGetWantedActionMetadata ()
83
+
84
+ wantEmpty := testGetWantedActionMetadata ()
85
+ wantEmpty .Inputs = nil
86
+ wantEmpty .Outputs = nil
87
+
88
+ wantUpper := testGetWantedActionMetadata ()
89
+ for _ , i := range wantUpper .Inputs {
90
+ i .Name = strings .ToUpper (i .Name )
91
+ }
92
+ for _ , o := range wantUpper .Outputs {
93
+ o .Name = strings .ToUpper (o .Name )
94
+ }
95
+
96
+ tests := []struct {
97
+ spec string
98
+ want * ActionMetadata
99
+ cmp []cmp.Option
100
+ }{
101
+ {
102
+ spec : "./action-yml" ,
103
+ want : want ,
104
+ },
105
+ {
106
+ spec : "./action-yaml" ,
107
+ want : want ,
108
+ },
109
+ {
110
+ spec : "./empty" ,
111
+ want : wantEmpty ,
112
+ },
113
+ {
114
+ spec : "./uppercase" ,
115
+ want : wantUpper ,
116
+ },
117
+ {
118
+ spec : "./docker" ,
119
+ want : & ActionMetadata {
120
+ Name : "My action" ,
121
+ Runs : ActionMetadataRuns {
122
+ Using : "docker" ,
123
+ Image : "Dockerfile" ,
124
+ },
125
+ },
126
+ },
127
+ {
128
+ spec : "./composite" ,
129
+ want : & ActionMetadata {
130
+ Name : "My action" ,
131
+ Runs : ActionMetadataRuns {
132
+ Using : "composite" ,
133
+ },
134
+ },
135
+ cmp : []cmp.Option {
136
+ cmpopts .IgnoreFields (ActionMetadataRuns {}, "Steps" ),
137
+ },
138
+ },
139
+ }
140
+
141
+ for _ , tc := range tests {
142
+ t .Run (tc .spec , func (t * testing.T ) {
85
143
// read metadata repeatedly (should be cached)
86
144
for i := 0 ; i < 3 ; i ++ {
87
- have , cached , err := c .FindMetadata (spec )
145
+ have , cached , err := c .FindMetadata (tc . spec )
88
146
if err != nil {
89
147
t .Fatal (i , err )
90
148
}
91
149
if have == nil {
92
150
t .Fatal (i , "metadata is nil" )
93
151
}
94
152
testCheckCachedFlag (t , cached , i > 0 )
95
- testDiffActionMetadata (t , want , have )
96
- testCheckActionMetadataPath (t , spec , have )
153
+ testDiffActionMetadata (t , tc . want , have , tc . cmp ... )
154
+ testCheckActionMetadataPath (t , tc . spec , have )
97
155
}
98
156
})
99
157
}
100
-
101
- t .Run ("./empty" , func (t * testing.T ) {
102
- for i := 0 ; i < 3 ; i ++ {
103
- m , cached , err := c .FindMetadata ("./empty" )
104
- if err != nil {
105
- t .Fatal (i , err )
106
- }
107
- if m == nil {
108
- t .Fatal (i , "metadata is nil" )
109
- }
110
- if len (m .Inputs ) != 0 {
111
- t .Fatal ("inputs are not empty" , m .Inputs )
112
- }
113
- if len (m .Outputs ) != 0 {
114
- t .Fatal ("outputs are not empty" , m .Outputs )
115
- }
116
- testCheckCachedFlag (t , cached , i > 0 )
117
- testCheckActionMetadataPath (t , "empty" , m )
118
- }
119
- })
120
-
121
- t .Run ("./uppercase" , func (t * testing.T ) {
122
- want := testGetWantedActionMetadata ()
123
- for _ , i := range want .Inputs {
124
- i .Name = strings .ToUpper (i .Name )
125
- }
126
- for _ , o := range want .Outputs {
127
- o .Name = strings .ToUpper (o .Name )
128
- }
129
-
130
- have , cached , err := c .FindMetadata ("./uppercase" )
131
- if err != nil {
132
- t .Fatal (err )
133
- }
134
- testCheckCachedFlag (t , cached , false )
135
- testDiffActionMetadata (t , want , have )
136
- testCheckActionMetadataPath (t , "uppercase" , have )
137
- })
138
-
139
- t .Run ("./docker" , func (t * testing.T ) {
140
- want := & ActionMetadata {
141
- Name : "My action" ,
142
- Runs : ActionMetadataRuns {
143
- Using : "docker" ,
144
- Image : "Dockerfile" ,
145
- },
146
- }
147
- have , cached , err := c .FindMetadata ("./docker" )
148
- if err != nil {
149
- t .Fatal (err )
150
- }
151
- testCheckCachedFlag (t , cached , false )
152
- testDiffActionMetadata (t , want , have )
153
- testCheckActionMetadataPath (t , "docker" , have )
154
- })
155
-
156
- t .Run ("./composite" , func (t * testing.T ) {
157
- want := & ActionMetadata {
158
- Name : "My action" ,
159
- Runs : ActionMetadataRuns {
160
- Using : "composite" ,
161
- },
162
- }
163
- have , cached , err := c .FindMetadata ("./composite" )
164
- if err != nil {
165
- t .Fatal (err )
166
- }
167
- testCheckCachedFlag (t , cached , false )
168
- testDiffActionMetadata (t , want , have , cmpopts .IgnoreFields (ActionMetadataRuns {}, "Steps" ))
169
- if have .Runs .Steps == nil {
170
- t .Fatal (`"steps" was not decoded` , have .Runs )
171
- }
172
- testCheckActionMetadataPath (t , "composite" , have )
173
- })
174
158
}
175
159
176
160
func TestLocalActionsFindConcurrently (t * testing.T ) {
0 commit comments