From 29b4ec51663e925a3d94dc0b797f0ff519860cf0 Mon Sep 17 00:00:00 2001 From: Pablo Ovelleiro Corral Date: Sat, 20 Apr 2019 00:00:09 +0200 Subject: [PATCH] removed unused methods --- giteabot.go | 34 +---------- giteadb_test.go | 148 +++++++++++++++++++++++++++++++++++++++++++++++ listener_test.go | 58 ------------------- 3 files changed, 150 insertions(+), 90 deletions(-) create mode 100644 giteadb_test.go delete mode 100644 listener_test.go diff --git a/giteabot.go b/giteabot.go index 87883a2..b033ef7 100644 --- a/giteabot.go +++ b/giteabot.go @@ -16,14 +16,6 @@ type GiteaBot struct { 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 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("set", 0, "Set an existing token for the room", gbot.handleCommandSet) bot.RegisterCommand("reset", 0, "Delete the room's token", gbot.handleCommandReset) 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 ") -// } 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) { + //TODO make the room a parameter (dont use the current room as room) + //Check if room already has a token if gb.Tokens[room] != "" { gb.SendToRoom(room, "This room already has a token. Your secert token is:") diff --git a/giteadb_test.go b/giteadb_test.go new file mode 100644 index 0000000..8891564 --- /dev/null +++ b/giteadb_test.go @@ -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) + }) + } +} diff --git a/listener_test.go b/listener_test.go deleted file mode 100644 index 828dad5..0000000 --- a/listener_test.go +++ /dev/null @@ -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) - } - }) - } -}