Skip to content
This repository was archived by the owner on Feb 3, 2021. It is now read-only.

Commit 734247c

Browse files
author
flowerinthenight
committed
wip tags support
1 parent 22c7a55 commit 734247c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343

4444
files []string
4545
dir string
46+
tags []string
4647

4748
slack string
4849
verbose bool
@@ -344,6 +345,7 @@ func init() {
344345
rootcmd.PersistentFlags().StringVarP(&dir, "dir", "d", dir, "root directory for scenario file[s]")
345346
rootcmd.PersistentFlags().StringVar(&slack, "report-slack", slack, "slack url for notification")
346347
rootcmd.Flags().StringSliceVarP(&files, "scenarios", "s", files, "scenario file[s] to run, comma-separated, or multiple -s")
348+
rootcmd.Flags().StringSliceVarP(&tags, "tags", "t", tags, "key=value labels in scenario files that are allowed to run, empty means all")
347349
rootcmd.AddCommand(runCmd())
348350
}
349351

scenario.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Run struct {
4040

4141
// Scenario reprents a single scenario file to run.
4242
type Scenario struct {
43+
Tags map[string]string `yaml:"tags"`
4344
Env map[string]string `yaml:"env"`
4445
Prepare string `yaml:"prepare"`
4546
Run []Run `yaml:"run"`
@@ -150,6 +151,28 @@ type doScenarioInput struct {
150151
Verbose bool
151152
}
152153

154+
func isAllowed(s *Scenario) bool {
155+
if len(tags) == 0 {
156+
return true
157+
}
158+
159+
var matched int
160+
for _, t := range tags {
161+
tt := strings.Split(t, "=")
162+
if len(tt) != 2 {
163+
continue
164+
}
165+
166+
for k, v := range s.Tags {
167+
if k == tt[0] && v == tt[1] {
168+
matched++
169+
}
170+
}
171+
}
172+
173+
return matched == len(tags)
174+
}
175+
153176
func doScenario(in *doScenarioInput) error {
154177
for _, f := range in.ScenarioFiles {
155178
yml, err := ioutil.ReadFile(f)
@@ -163,6 +186,11 @@ func doScenario(in *doScenarioInput) error {
163186
continue
164187
}
165188

189+
if !isAllowed(&s) {
190+
log.Printf("%v is not allowed by tags", f)
191+
continue
192+
}
193+
166194
s.me = &s // self-reference for our LoggerReporter functions
167195
s.input = in // our copy
168196
log.Printf("scenario: %v", f)

0 commit comments

Comments
 (0)