Browse Source

Fix test, format code

pull/19/head
Jan-Lukas Else 1 year ago
parent
commit
d1b3dd4814
3 changed files with 45 additions and 54 deletions
  1. +34
    -44
      database_test.go
  2. +7
    -7
      main.go
  3. +4
    -3
      stats.go

+ 34
- 44
database_test.go View File

@ -12,9 +12,8 @@ func TestViewsRequest_buildDateTimeFilter(t *testing.T) {
to: "",
}
namedArgs := &[]sql.NamedArg{}
if gotDateTimeFilter := request.buildDateTimeFilter(namedArgs);
gotDateTimeFilter != "" ||
len(*namedArgs) != 0 {
if gotDateTimeFilter := request.buildDateTimeFilter(namedArgs); gotDateTimeFilter != "" ||
len(*namedArgs) != 0 {
t.Errorf("ViewsRequest.buildDateTimeFilter(): Wrong return string or length of namedArgs, should be empty")
}
})
@ -24,11 +23,10 @@ func TestViewsRequest_buildDateTimeFilter(t *testing.T) {
to: "",
}
namedArgs := &[]sql.NamedArg{}
if gotDateTimeFilter := request.buildDateTimeFilter(namedArgs);
gotDateTimeFilter != "datetime(time, 'localtime') >= :from" ||
len(*namedArgs) != 1 ||
(*namedArgs)[0].Name != "from" ||
(*namedArgs)[0].Value != "2019-01-01" {
if gotDateTimeFilter := request.buildDateTimeFilter(namedArgs); gotDateTimeFilter != "datetime(time, 'localtime') >= :from" ||
len(*namedArgs) != 1 ||
(*namedArgs)[0].Name != "from" ||
(*namedArgs)[0].Value != "2019-01-01" {
t.Errorf("ViewsRequest.buildDateTimeFilter(): Wrong return string or namedArgs")
}
})
@ -38,11 +36,10 @@ func TestViewsRequest_buildDateTimeFilter(t *testing.T) {
to: "2019-01-01",
}
namedArgs := &[]sql.NamedArg{}
if gotDateTimeFilter := request.buildDateTimeFilter(namedArgs);
gotDateTimeFilter != "datetime(time, 'localtime') <= :to" ||
len(*namedArgs) != 1 ||
(*namedArgs)[0].Name != "to" ||
(*namedArgs)[0].Value != "2019-01-01" {
if gotDateTimeFilter := request.buildDateTimeFilter(namedArgs); gotDateTimeFilter != "datetime(time, 'localtime') <= :to" ||
len(*namedArgs) != 1 ||
(*namedArgs)[0].Name != "to" ||
(*namedArgs)[0].Value != "2019-01-01" {
t.Errorf("ViewsRequest.buildDateTimeFilter(): Wrong return string or namedArgs")
}
})
@ -52,13 +49,12 @@ func TestViewsRequest_buildDateTimeFilter(t *testing.T) {
to: "2019-01-01",
}
namedArgs := &[]sql.NamedArg{}
if gotDateTimeFilter := request.buildDateTimeFilter(namedArgs);
gotDateTimeFilter != "datetime(time, 'localtime') between :from and :to" ||
len(*namedArgs) != 2 ||
(*namedArgs)[0].Name != "from" ||
(*namedArgs)[0].Value != "2018-01-01" ||
(*namedArgs)[1].Name != "to" ||
(*namedArgs)[1].Value != "2019-01-01" {
if gotDateTimeFilter := request.buildDateTimeFilter(namedArgs); gotDateTimeFilter != "datetime(time, 'localtime') between :from and :to" ||
len(*namedArgs) != 2 ||
(*namedArgs)[0].Name != "from" ||
(*namedArgs)[0].Value != "2018-01-01" ||
(*namedArgs)[1].Name != "to" ||
(*namedArgs)[1].Value != "2019-01-01" {
t.Errorf("ViewsRequest.buildDateTimeFilter(): Wrong return string or namedArgs")
}
})
@ -70,9 +66,8 @@ func TestViewsRequest_buildUrlFilter(t *testing.T) {
url: "",
}
namedArgs := &[]sql.NamedArg{}
if gotUrlFilter := request.buildUrlFilter(namedArgs);
gotUrlFilter != "" ||
len(*namedArgs) != 0 {
if gotUrlFilter := request.buildUrlFilter(namedArgs); gotUrlFilter != "" ||
len(*namedArgs) != 0 {
t.Errorf("ViewsRequest.buildUrlFilter(): Wrong return string or length of namedArgs, should be empty")
}
})
@ -81,11 +76,10 @@ func TestViewsRequest_buildUrlFilter(t *testing.T) {
url: "google",
}
namedArgs := &[]sql.NamedArg{}
if gotUrlFilter := request.buildUrlFilter(namedArgs);
gotUrlFilter != "url like :url" ||
len(*namedArgs) != 1 ||
(*namedArgs)[0].Name != "url" ||
(*namedArgs)[0].Value != "%google%" {
if gotUrlFilter := request.buildUrlFilter(namedArgs); gotUrlFilter != "url like :url" ||
len(*namedArgs) != 1 ||
(*namedArgs)[0].Name != "url" ||
(*namedArgs)[0].Value != "%google%" {
t.Errorf("ViewsRequest.buildUrlFilter(): Wrong return string or namedArgs")
}
})
@ -97,9 +91,8 @@ func TestViewsRequest_buildRefFilter(t *testing.T) {
ref: "",
}
namedArgs := &[]sql.NamedArg{}
if gotRefFilter := request.buildRefFilter(namedArgs);
gotRefFilter != "" ||
len(*namedArgs) != 0 {
if gotRefFilter := request.buildRefFilter(namedArgs); gotRefFilter != "" ||
len(*namedArgs) != 0 {
t.Errorf("ViewsRequest.buildRefFilter(): Wrong return string or length of namedArgs, should be empty")
}
})
@ -108,11 +101,10 @@ func TestViewsRequest_buildRefFilter(t *testing.T) {
ref: "google",
}
namedArgs := &[]sql.NamedArg{}
if gotRefFilter := request.buildRefFilter(namedArgs);
gotRefFilter != "ref like :ref" ||
len(*namedArgs) != 1 ||
(*namedArgs)[0].Name != "ref" ||
(*namedArgs)[0].Value != "%google%" {
if gotRefFilter := request.buildRefFilter(namedArgs); gotRefFilter != "ref like :ref" ||
len(*namedArgs) != 1 ||
(*namedArgs)[0].Name != "ref" ||
(*namedArgs)[0].Value != "%google%" {
t.Errorf("ViewsRequest.buildRefFilter(): Wrong return string or namedArgs")
}
})
@ -124,9 +116,8 @@ func TestViewsRequest_buildUseragentFilter(t *testing.T) {
ua: "",
}
namedArgs := &[]sql.NamedArg{}
if gotUseragentFilter := request.buildUseragentFilter(namedArgs);
gotUseragentFilter != "" ||
len(*namedArgs) != 0 {
if gotUseragentFilter := request.buildUseragentFilter(namedArgs); gotUseragentFilter != "" ||
len(*namedArgs) != 0 {
t.Errorf("ViewsRequest.buildUseragentFilter(): Wrong return string or length of namedArgs, should be empty")
}
})
@ -135,11 +126,10 @@ func TestViewsRequest_buildUseragentFilter(t *testing.T) {
ua: "Firefox",
}
namedArgs := &[]sql.NamedArg{}
if gotUseragentFilter := request.buildUseragentFilter(namedArgs);
gotUseragentFilter != "useragent like :ua" ||
len(*namedArgs) != 1 ||
(*namedArgs)[0].Name != "ua" ||
(*namedArgs)[0].Value != "%Firefox%" {
if gotUseragentFilter := request.buildUseragentFilter(namedArgs); gotUseragentFilter != "useragent like :ua" ||
len(*namedArgs) != 1 ||
(*namedArgs)[0].Name != "ua" ||
(*namedArgs)[0].Value != "%Firefox%" {
t.Errorf("ViewsRequest.buildUseragentFilter(): Wrong return string or namedArgs")
}
})


+ 7
- 7
main.go View File

@ -2,14 +2,15 @@ package main
import (
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/gobuffalo/packr/v2"
"github.com/gorilla/mux"
"log"
"net/http"
"os"
"os/signal"
"syscall"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/gobuffalo/packr/v2"
"github.com/gorilla/mux"
)
type kis3 struct {
@ -24,7 +25,8 @@ var (
}
)
func init() {
func main() {
// Init
initConfig()
e := initDatabase()
if e != nil {
@ -32,9 +34,7 @@ func init() {
}
initRouter()
initTelegramBot()
}
func main() {
// Start
go startListeningToWeb()
go startReports()
go startStatsTelegram()


+ 4
- 3
stats.go View File

@ -3,14 +3,15 @@ package main
import (
"encoding/json"
"fmt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/kis3/kis3/helpers"
"github.com/whiteshtef/clockwork"
"html/template"
"net/http"
"net/url"
"strconv"
"strings"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/kis3/kis3/helpers"
"github.com/whiteshtef/clockwork"
)
func initStatsRouter() {


Loading…
Cancel
Save