1
0
mirror of https://github.com/pinpox/gitea-matrix-bot synced 2024-11-22 19:31:58 +01:00

removed unused methods

This commit is contained in:
Pablo Ovelleiro Corral 2019-04-20 00:00:09 +02:00
parent 362d9d0296
commit 29b4ec5166
No known key found for this signature in database
GPG Key ID: F7C1D57C8464E825
3 changed files with 150 additions and 90 deletions

@ -16,14 +16,6 @@ type GiteaBot struct {
db *GiteaDB db *GiteaDB
} }
func (gb *GiteaBot) Send(token, message string) {
for k, v := range gb.Tokens {
if v == token {
gb.SendToRoom(k, message)
}
}
}
//NewGiteaBot creates a new bot form user credentials //NewGiteaBot creates a new bot form user credentials
func NewGiteaBot(user, pass string, DBPath string) *GiteaBot { func NewGiteaBot(user, pass string, DBPath string) *GiteaBot {
@ -41,7 +33,6 @@ func NewGiteaBot(user, pass string, DBPath string) *GiteaBot {
} }
bot.RegisterCommand("secret", 0, "Request token for a webhook", gbot.handleCommandSecret) bot.RegisterCommand("secret", 0, "Request token for a webhook", gbot.handleCommandSecret)
// bot.RegisterCommand("set", 0, "Set an existing token for the room", gbot.handleCommandSet)
bot.RegisterCommand("reset", 0, "Delete the room's token", gbot.handleCommandReset) bot.RegisterCommand("reset", 0, "Delete the room's token", gbot.handleCommandReset)
return gbot return gbot
@ -68,31 +59,10 @@ func (gb *GiteaBot) handleCommandReset(message, room, sender string) {
} }
} }
// func (gb *GiteaBot) handleCommandSet(message, room, sender string) {
// // Get the parameter(s) given to the command
// args := strings.Split(message, " ")
// // Display help/error if more than one argument is given
// if len(args) != 3 {
// gb.SendToRoom(room, "set expects exactly one argument")
// gb.SendToRoom(room, "!gitea set <token>")
// } else {
// // Display help/error if the token has the wrong length
// if len(args[2]) != 20 {
// gb.SendToRoom(room, "Tokens have a length of 20 characters")
// } else {
// // If the token seems ok, set it for the room
// gb.SendToRoom(room, "Setting token for this room to:")
// gb.SendToRoom(room, args[2])
// gb.Tokens[room] = args[2]
// gb.db.Update(gb.Tokens)
// }
// }
// }
func (gb *GiteaBot) handleCommandSecret(message, room, sender string) { func (gb *GiteaBot) handleCommandSecret(message, room, sender string) {
//TODO make the room a parameter (dont use the current room as room)
//Check if room already has a token //Check if room already has a token
if gb.Tokens[room] != "" { if gb.Tokens[room] != "" {
gb.SendToRoom(room, "This room already has a token. Your secert token is:") gb.SendToRoom(room, "This room already has a token. Your secert token is:")

148
giteadb_test.go Normal file

@ -0,0 +1,148 @@
package main
import (
"reflect"
"testing"
_ "github.com/mattn/go-sqlite3"
)
func TestNewGiteaDB(t *testing.T) {
type args struct {
path string
}
tests := []struct {
name string
args args
want *GiteaDB
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewGiteaDB(tt.args.path); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewGiteaDB() = %v, want %v", got, tt.want)
}
})
}
}
func TestGiteaDB_Init(t *testing.T) {
type fields struct {
path string
}
tests := []struct {
name string
fields fields
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dbg := &GiteaDB{
path: tt.fields.path,
}
dbg.Init()
})
}
}
func TestGiteaDB_GetToken(t *testing.T) {
type fields struct {
path string
}
type args struct {
room string
}
tests := []struct {
name string
fields fields
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dbg := &GiteaDB{
path: tt.fields.path,
}
if got := dbg.GetToken(tt.args.room); got != tt.want {
t.Errorf("GiteaDB.GetToken() = %v, want %v", got, tt.want)
}
})
}
}
func TestGiteaDB_GetAll(t *testing.T) {
type fields struct {
path string
}
tests := []struct {
name string
fields fields
want map[string]string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dbg := &GiteaDB{
path: tt.fields.path,
}
if got := dbg.GetAll(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GiteaDB.GetAll() = %v, want %v", got, tt.want)
}
})
}
}
func TestGiteaDB_Unset(t *testing.T) {
type fields struct {
path string
}
type args struct {
room string
token string
}
tests := []struct {
name string
fields fields
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dbg := &GiteaDB{
path: tt.fields.path,
}
dbg.Unset(tt.args.room, tt.args.token)
})
}
}
func TestGiteaDB_Set(t *testing.T) {
type fields struct {
path string
}
type args struct {
room string
token string
}
tests := []struct {
name string
fields fields
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dbg := &GiteaDB{
path: tt.fields.path,
}
dbg.Set(tt.args.room, tt.args.token)
})
}
}

@ -1,58 +0,0 @@
package main
import (
"net/http"
"testing"
)
// func Test_setupListener(t *testing.T) {
// tests := []struct {
// name string
// }{
// // TODO: Add test cases.
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// setupListener()
// })
// }
// }
// func TestPostHandler(t *testing.T) {
// type args struct {
// w http.ResponseWriter
// r *http.Request
// }
// tests := []struct {
// name string
// args args
// }{
// // TODO: Add test cases.
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// PostHandler(tt.args.w, tt.args.r)
// })
// }
// }
func Test_generateMessage(t *testing.T) {
type args struct {
data GiteaPostData
eventHeader string
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := generateMessage(tt.args.data, tt.args.eventHeader); got != tt.want {
t.Errorf("generateMessage() = %v, want %v", got, tt.want)
}
})
}
}