added 'disable' filter
This commit is contained in:
parent
4ef6b14fe0
commit
cdf44e1560
6 changed files with 270 additions and 8 deletions
3
todo.md
3
todo.md
|
@ -1,2 +1 @@
|
||||||
# Todo
|
# Todo
|
||||||
- add 'disable schedules' filter, useful for child of 'expect' filter
|
|
|
@ -234,6 +234,10 @@ func getFilterResult(filters []Filter, filter *Filter, watch *Watch, web *Web, d
|
||||||
{
|
{
|
||||||
getFilterResultExpect(filter, web, debug)
|
getFilterResultExpect(filter, web, debug)
|
||||||
}
|
}
|
||||||
|
case filter.Type == "disable":
|
||||||
|
{
|
||||||
|
getFilterResultDisableSchedules(filter, web, debug)
|
||||||
|
}
|
||||||
case filter.Type == "notify":
|
case filter.Type == "notify":
|
||||||
{
|
{
|
||||||
notifyFilter(filters, filter, watch, web, debug)
|
notifyFilter(filters, filter, watch, web, debug)
|
||||||
|
@ -1291,6 +1295,32 @@ func getFilterResultExpect(filter *Filter, web *Web, debug bool) {
|
||||||
web.db.Create(&expectFail)
|
web.db.Create(&expectFail)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getFilterResultDisableSchedules disables all schedules of a watch if it gets any inputs
|
||||||
|
func getFilterResultDisableSchedules(filter *Filter, web *Web, debug bool) {
|
||||||
|
if len(filter.Parents) == 0 {
|
||||||
|
filter.Logs = append(filter.Logs, "Need Parents")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
anyParentWithResults := false
|
||||||
|
for i := range filter.Parents {
|
||||||
|
parent := filter.Parents[i]
|
||||||
|
if len(parent.Results) > 0 {
|
||||||
|
anyParentWithResults = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !anyParentWithResults {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
filter.Results = append(filter.Results, "Would have disabled Schedules")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
web.db.Model(&Filter{}).Where("watch_id = ?", filter.WatchID).Update("Var2", "no")
|
||||||
|
}
|
||||||
|
|
||||||
// getFilterResultEcho is a debug filter type, used to bootstrap some tests
|
// getFilterResultEcho is a debug filter type, used to bootstrap some tests
|
||||||
func getFilterResultEcho(filter *Filter) {
|
func getFilterResultEcho(filter *Filter) {
|
||||||
filter.Results = append(filter.Results, filter.Var1)
|
filter.Results = append(filter.Results, filter.Var1)
|
||||||
|
|
|
@ -2222,7 +2222,6 @@ func TestWatchWithExpect3TriggeringDB(t *testing.T) {
|
||||||
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
||||||
if len(expectFails) != 1 {
|
if len(expectFails) != 1 {
|
||||||
t.Errorf("Found %d ExpectFail values, expected 1!", len(expectFails))
|
t.Errorf("Found %d ExpectFail values, expected 1!", len(expectFails))
|
||||||
log.Println(expectFails)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
||||||
|
@ -2230,7 +2229,6 @@ func TestWatchWithExpect3TriggeringDB(t *testing.T) {
|
||||||
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
||||||
if len(expectFails) != 2 {
|
if len(expectFails) != 2 {
|
||||||
t.Errorf("Found %d ExpectFail values, expected 2!", len(expectFails))
|
t.Errorf("Found %d ExpectFail values, expected 2!", len(expectFails))
|
||||||
log.Println(expectFails)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
||||||
|
@ -2238,14 +2236,208 @@ func TestWatchWithExpect3TriggeringDB(t *testing.T) {
|
||||||
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
||||||
if len(expectFails) != 3 {
|
if len(expectFails) != 3 {
|
||||||
t.Errorf("Found %d ExpectFail values, expected 3! (1)", len(expectFails))
|
t.Errorf("Found %d ExpectFail values, expected 3! (1)", len(expectFails))
|
||||||
log.Println(expectFails)
|
|
||||||
}
|
}
|
||||||
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
||||||
|
|
||||||
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
||||||
if len(expectFails) != 3 {
|
if len(expectFails) != 3 {
|
||||||
t.Errorf("Found %d ExpectFail values, expected 3! (2)", len(expectFails))
|
t.Errorf("Found %d ExpectFail values, expected 3! (2)", len(expectFails))
|
||||||
log.Println(expectFails)
|
}
|
||||||
|
|
||||||
|
err := os.Remove("./test.db")
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Could not remove test db:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWatchWithExpectNotTriggeringWithDisableDB(t *testing.T) {
|
||||||
|
db := getTestDB()
|
||||||
|
watch := Watch{
|
||||||
|
Name: "Test",
|
||||||
|
}
|
||||||
|
db.Create(&watch)
|
||||||
|
filters := []Filter{
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
Name: "Schedule",
|
||||||
|
Type: "cron",
|
||||||
|
Var2: "yes",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
Name: "Echo",
|
||||||
|
Type: "echo",
|
||||||
|
Var1: HTML_STRING,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
Name: "XPath",
|
||||||
|
Type: "xpath",
|
||||||
|
Var1: "//td[@class='price']",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
Name: "Expect",
|
||||||
|
Type: "expect",
|
||||||
|
Var1: "1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
Name: "Disable",
|
||||||
|
Type: "disable",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
db.Create(&filters)
|
||||||
|
scheduleFilter := &filters[0]
|
||||||
|
echoFilter := &filters[1]
|
||||||
|
xpathFilter := &filters[2]
|
||||||
|
expectFilter := &filters[3]
|
||||||
|
disableFilter := &filters[4]
|
||||||
|
|
||||||
|
connections := []FilterConnection{
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
OutputID: scheduleFilter.ID,
|
||||||
|
InputID: echoFilter.ID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
OutputID: echoFilter.ID,
|
||||||
|
InputID: xpathFilter.ID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
OutputID: xpathFilter.ID,
|
||||||
|
InputID: expectFilter.ID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
OutputID: expectFilter.ID,
|
||||||
|
InputID: disableFilter.ID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
db.Create(&connections)
|
||||||
|
|
||||||
|
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
||||||
|
|
||||||
|
var expectFails []ExpectFail
|
||||||
|
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
||||||
|
if len(expectFails) > 0 {
|
||||||
|
t.Errorf("Found ExpectFail values expected none!")
|
||||||
|
}
|
||||||
|
|
||||||
|
var scheduleFilterFromDb Filter
|
||||||
|
db.Model(&Filter{}).First(&scheduleFilterFromDb, scheduleFilter.ID)
|
||||||
|
if scheduleFilterFromDb.Var2 != "yes" {
|
||||||
|
t.Errorf("Schedule filter is disabled!")
|
||||||
|
}
|
||||||
|
|
||||||
|
err := os.Remove("./test.db")
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Could not remove test db:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWatchWithExpect3TriggeringAndDisableDB(t *testing.T) {
|
||||||
|
db := getTestDB()
|
||||||
|
watch := Watch{
|
||||||
|
Name: "Test",
|
||||||
|
}
|
||||||
|
db.Create(&watch)
|
||||||
|
filters := []Filter{
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
Name: "Schedule",
|
||||||
|
Type: "cron",
|
||||||
|
Var2: "yes",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
Name: "Echo",
|
||||||
|
Type: "echo",
|
||||||
|
Var1: HTML_STRING,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
Name: "XPath",
|
||||||
|
Type: "xpath",
|
||||||
|
Var1: "//div[@class='price']",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
Name: "Expect",
|
||||||
|
Type: "expect",
|
||||||
|
Var1: "3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
Name: "Disable",
|
||||||
|
Type: "disable",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
db.Create(&filters)
|
||||||
|
scheduleFilter := &filters[0]
|
||||||
|
echoFilter := &filters[1]
|
||||||
|
xpathFilter := &filters[2]
|
||||||
|
expectFilter := &filters[3]
|
||||||
|
disableFilter := &filters[4]
|
||||||
|
|
||||||
|
connections := []FilterConnection{
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
OutputID: scheduleFilter.ID,
|
||||||
|
InputID: echoFilter.ID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
OutputID: echoFilter.ID,
|
||||||
|
InputID: xpathFilter.ID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
OutputID: xpathFilter.ID,
|
||||||
|
InputID: expectFilter.ID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
WatchID: watch.ID,
|
||||||
|
OutputID: expectFilter.ID,
|
||||||
|
InputID: disableFilter.ID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
db.Create(&connections)
|
||||||
|
|
||||||
|
var expectFails []ExpectFail
|
||||||
|
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
||||||
|
|
||||||
|
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
||||||
|
if len(expectFails) != 1 {
|
||||||
|
t.Errorf("Found %d ExpectFail values, expected 1!", len(expectFails))
|
||||||
|
}
|
||||||
|
|
||||||
|
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
||||||
|
|
||||||
|
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
||||||
|
if len(expectFails) != 2 {
|
||||||
|
t.Errorf("Found %d ExpectFail values, expected 2!", len(expectFails))
|
||||||
|
}
|
||||||
|
|
||||||
|
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
||||||
|
|
||||||
|
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
||||||
|
if len(expectFails) != 3 {
|
||||||
|
t.Errorf("Found %d ExpectFail values, expected 3! (1)", len(expectFails))
|
||||||
|
}
|
||||||
|
TriggerSchedule(watch.ID, &Web{db: db}, &scheduleFilter.ID)
|
||||||
|
|
||||||
|
db.Model(&ExpectFail{}).Find(&expectFails, "watch_id = ?", watch.ID)
|
||||||
|
if len(expectFails) != 3 {
|
||||||
|
t.Errorf("Found %d ExpectFail values, expected 3! (2)", len(expectFails))
|
||||||
|
}
|
||||||
|
|
||||||
|
var scheduleFilterFromDb Filter
|
||||||
|
db.Model(&Filter{}).First(&scheduleFilterFromDb, scheduleFilter.ID)
|
||||||
|
if scheduleFilterFromDb.Var2 != "no" {
|
||||||
|
t.Errorf("Schedule filter not disabled!")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := os.Remove("./test.db")
|
err := os.Remove("./test.db")
|
||||||
|
|
|
@ -351,6 +351,26 @@ function onTypeChange(node) {
|
||||||
var2Div.appendChild(var2Input);
|
var2Div.appendChild(var2Input);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "disable": {
|
||||||
|
var var1Input = document.createElement("input");
|
||||||
|
var1Input.name = "var1";
|
||||||
|
var1Input.id = "var1Input";
|
||||||
|
var1Input.value = var1Value;
|
||||||
|
var1Input.classList.add("form-control");
|
||||||
|
var1Input.disabled = true;
|
||||||
|
var1Label.innerHTML = "-";
|
||||||
|
var1Input.placeholder = "";
|
||||||
|
var1Div.appendChild(var1Input);
|
||||||
|
var var2Input = document.createElement("input");
|
||||||
|
var2Input.name = "var2";
|
||||||
|
var2Input.id = "var2Input";
|
||||||
|
var2Input.value = var2Value;
|
||||||
|
var2Input.classList.add("form-control");
|
||||||
|
var2Input.disabled = true;
|
||||||
|
var2Label.innerHTML = "-";
|
||||||
|
var2Div.appendChild(var2Input);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "unique": {
|
case "unique": {
|
||||||
var var1Input = document.createElement("input");
|
var var1Input = document.createElement("input");
|
||||||
var1Input.name = "var1";
|
var1Input.name = "var1";
|
||||||
|
|
|
@ -330,6 +330,27 @@ function onTypeChange(node: DiagramNode | null = null){
|
||||||
var2Div.appendChild(var2Input);
|
var2Div.appendChild(var2Input);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "disable": {
|
||||||
|
let var1Input = document.createElement("input");
|
||||||
|
var1Input.name = "var1";
|
||||||
|
var1Input.id = "var1Input";
|
||||||
|
var1Input.value = var1Value;
|
||||||
|
var1Input.classList.add("form-control")
|
||||||
|
var1Input.disabled = true;
|
||||||
|
var1Label.innerHTML = "-";
|
||||||
|
var1Input.placeholder = "";
|
||||||
|
var1Div.appendChild(var1Input);
|
||||||
|
|
||||||
|
let var2Input = document.createElement("input");
|
||||||
|
var2Input.name = "var2";
|
||||||
|
var2Input.id = "var2Input";
|
||||||
|
var2Input.value = var2Value;
|
||||||
|
var2Input.classList.add("form-control")
|
||||||
|
var2Input.disabled = true;
|
||||||
|
var2Label.innerHTML = "-";
|
||||||
|
var2Div.appendChild(var2Input);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "unique": {
|
case "unique": {
|
||||||
let var1Input = document.createElement("input");
|
let var1Input = document.createElement("input");
|
||||||
var1Input.name = "var1";
|
var1Input.name = "var1";
|
||||||
|
|
|
@ -89,6 +89,7 @@ GoWatch Edit {{ .Watch.Name }}
|
||||||
<option value="store">Store</option>
|
<option value="store">Store</option>
|
||||||
<option value="condition">Condition</option>
|
<option value="condition">Condition</option>
|
||||||
<option value="expect">Expect</option>
|
<option value="expect">Expect</option>
|
||||||
|
<option value="disable">Disable Schedules</option>
|
||||||
<option value="notify">Notify</option>
|
<option value="notify">Notify</option>
|
||||||
<option value="cron">Schedule</option>
|
<option value="cron">Schedule</option>
|
||||||
<option value="brow">Browserless</option>
|
<option value="brow">Browserless</option>
|
||||||
|
@ -104,8 +105,7 @@ GoWatch Edit {{ .Watch.Name }}
|
||||||
<div class="col-sm-10 p-2" id="var2Div">
|
<div class="col-sm-10 p-2" id="var2Div">
|
||||||
<input type="text" class="form-control" name="var2" id="var2Input" placeholder="" disabled>
|
<input type="text" class="form-control" name="var2" id="var2Input" placeholder="" disabled>
|
||||||
</div>
|
</div>
|
||||||
<label for="var3" id="var3Label" class="col-sm-2 col-form-label"></label>
|
<div id="var3Div">
|
||||||
<div class="col-sm-10 p-2" id="var3Div">
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue