Skip to content

Commit 9db92a8

Browse files
committed
Use env to load keys
1 parent 62b3704 commit 9db92a8

File tree

4 files changed

+94
-7
lines changed

4 files changed

+94
-7
lines changed

captchatools-go/anticaptcha_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package captchatoolsgo
22

33
import (
4+
"os"
45
"testing"
5-
)
66

7-
const antiCapKey = "9f47074b59d3d4cf5c07961f90deb7d8"
7+
"github.com/joho/godotenv"
8+
)
89

910
// TestGetAnticapID tests that it can successfully get a ID from anticaptcha
1011
// to run this specific test:
1112
// go test -v -run ^TestGetAnticapID$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
1213
func TestGetAnticapID(t *testing.T) {
14+
// Load Env
15+
if err := godotenv.Load("../.env"); err != nil {
16+
t.Fatalf("Failed to load .env file: %v", err)
17+
}
18+
antiCapKey := os.Getenv("ANTICAPTCHA_KEY")
19+
1320
var tests = []testConfigs{
1421
{
1522
SolvingSite: AnticaptchaSite,
@@ -58,6 +65,11 @@ func TestGetAnticapID(t *testing.T) {
5865
// to run this specific test:
5966
// go test -v -run ^TestGetAnticapBalance$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
6067
func TestGetAnticapBalance(t *testing.T) {
68+
// Load Env
69+
if err := godotenv.Load("../.env"); err != nil {
70+
t.Fatalf("Failed to load .env file: %v", err)
71+
}
72+
antiCapKey := os.Getenv("ANTICAPTCHA_KEY")
6173
var tests = []testConfigs{
6274
{
6375
SolvingSite: AnticaptchaSite,
@@ -94,6 +106,11 @@ func TestGetAnticapBalance(t *testing.T) {
94106
// to run this specific test:
95107
// go test -v -run ^TestGetAnticapV2$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
96108
func TestGetAnticapV2(t *testing.T) {
109+
// Load Env
110+
if err := godotenv.Load("../.env"); err != nil {
111+
t.Fatalf("Failed to load .env file: %v", err)
112+
}
113+
antiCapKey := os.Getenv("ANTICAPTCHA_KEY")
97114
configs := []testConfigs{
98115
{
99116
SolvingSite: AnticaptchaSite,
@@ -133,6 +150,11 @@ func TestGetAnticapV2(t *testing.T) {
133150
// to run this specific test:
134151
// go test -v -run ^TestAnticaptchaGetV2Additional$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
135152
func TestAnticaptchaGetV2Additional(t *testing.T) {
153+
// Load Env
154+
if err := godotenv.Load("../.env"); err != nil {
155+
t.Fatalf("Failed to load .env file: %v", err)
156+
}
157+
antiCapKey := os.Getenv("ANTICAPTCHA_KEY")
136158
configs := []testConfigs{
137159
{
138160
SolvingSite: AnticaptchaSite,
@@ -189,6 +211,11 @@ func TestAnticaptchaGetV2Additional(t *testing.T) {
189211
// to run this specific test:
190212
// go test -v -run ^TestGetAnticapV3$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
191213
func TestGetAnticapV3(t *testing.T) {
214+
// Load Env
215+
if err := godotenv.Load("../.env"); err != nil {
216+
t.Fatalf("Failed to load .env file: %v", err)
217+
}
218+
antiCapKey := os.Getenv("ANTICAPTCHA_KEY")
192219
configs := []testConfigs{
193220
{
194221
SolvingSite: AnticaptchaSite,
@@ -213,6 +240,11 @@ func TestGetAnticapV3(t *testing.T) {
213240
// to run this specific test:
214241
// go test -v -run ^Test2AntiCaptchaGetImage$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
215242
func Test2AntiCaptchaGetImage(t *testing.T) {
243+
// Load Env
244+
if err := godotenv.Load("../.env"); err != nil {
245+
t.Fatalf("Failed to load .env file: %v", err)
246+
}
247+
antiCapKey := os.Getenv("ANTICAPTCHA_KEY")
216248
configs := []testConfigs{
217249
{
218250
SolvingSite: AnticaptchaSite,

captchatools-go/capmonster_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package captchatoolsgo
22

33
import (
4+
"os"
45
"testing"
5-
)
66

7-
const capmonsterKey = "2cffb45a7f3b15b7f7bfd5c53c08d0cd"
7+
"github.com/joho/godotenv"
8+
)
89

910
// TestCapmonsterGetID tests that it can successfully get a ID from Capmonster
1011
// to run this specific test:
1112
// go test -v -run ^TestCapmonsterGetID$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
1213
func TestCapmonsterGetID(t *testing.T) {
14+
// Load Env
15+
if err := godotenv.Load("../.env"); err != nil {
16+
t.Fatalf("Failed to load .env file: %v", err)
17+
}
18+
capmonsterKey := os.Getenv("CAPMONSTER_KEY")
1319
var tests = []testConfigs{
1420
{
1521
SolvingSite: CapmonsterSite,
@@ -58,6 +64,10 @@ func TestCapmonsterGetID(t *testing.T) {
5864
// to run this specific test:
5965
// go test -v -run ^TestCapmonsterGetBalance$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
6066
func TestCapmonsterGetBalance(t *testing.T) {
67+
if err := godotenv.Load("../.env"); err != nil {
68+
t.Fatalf("Failed to load .env file: %v", err)
69+
}
70+
capmonsterKey := os.Getenv("CAPMONSTER_KEY")
6171
var tests = []testConfigs{
6272
{
6373
SolvingSite: CapmonsterSite,
@@ -94,6 +104,10 @@ func TestCapmonsterGetBalance(t *testing.T) {
94104
// to run this specific test:
95105
// go test -v -run ^TestCapmonsterGetV2$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
96106
func TestCapmonsterGetV2(t *testing.T) {
107+
if err := godotenv.Load("../.env"); err != nil {
108+
t.Fatalf("Failed to load .env file: %v", err)
109+
}
110+
capmonsterKey := os.Getenv("CAPMONSTER_KEY")
97111
configs := []testConfigs{
98112
{
99113
SolvingSite: CapmonsterSite,
@@ -131,6 +145,10 @@ func TestCapmonsterGetV2(t *testing.T) {
131145
// to run this specific test:
132146
// go test -v -run ^TestCapmonsterGetV2Additional$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
133147
func TestCapmonsterGetV2Additional(t *testing.T) {
148+
if err := godotenv.Load("../.env"); err != nil {
149+
t.Fatalf("Failed to load .env file: %v", err)
150+
}
151+
capmonsterKey := os.Getenv("CAPMONSTER_KEY")
134152
configs := []testConfigs{
135153
{
136154
SolvingSite: CapmonsterSite,
@@ -187,6 +205,10 @@ func TestCapmonsterGetV2Additional(t *testing.T) {
187205
// to run this specific test:
188206
// go test -v -run ^TestCapmonsterGetV3$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
189207
func TestCapmonsterGetV3(t *testing.T) {
208+
if err := godotenv.Load("../.env"); err != nil {
209+
t.Fatalf("Failed to load .env file: %v", err)
210+
}
211+
capmonsterKey := os.Getenv("CAPMONSTER_KEY")
190212
configs := []testConfigs{
191213
{
192214
SolvingSite: CapmonsterSite,
@@ -211,6 +233,10 @@ func TestCapmonsterGetV3(t *testing.T) {
211233
// to run this specific test:
212234
// go test -v -run ^Test2CapmonsterGetImage$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
213235
func Test2CapmonsterGetImage(t *testing.T) {
236+
if err := godotenv.Load("../.env"); err != nil {
237+
t.Fatalf("Failed to load .env file: %v", err)
238+
}
239+
capmonsterKey := os.Getenv("CAPMONSTER_KEY")
214240
configs := []testConfigs{
215241
{
216242
SolvingSite: CapmonsterSite,

captchatools-go/harvester_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ var configs = []testConfigs{
5959
}
6060

6161
func TestHarvester(t *testing.T) {
62+
if err := godotenv.Load("../.env"); err != nil {
63+
t.Fatalf("Failed to load .env file: %v", err)
64+
}
65+
capmonsterKey := os.Getenv("CAPMONSTER_KEY")
6266
solver, err := NewHarvester(CapmonsterSite, &Config{
63-
Api_key: "2cffb45a7f3b15b7f7bfd5c53c08d0cd",
67+
Api_key: capmonsterKey,
6468
Sitekey: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
6569
CaptchaURL: "https://www.google.com/recaptcha/api2/demo",
6670
CaptchaType: "V2",

captchatools-go/twocaptcha_test.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ package captchatoolsgo
22

33
import (
44
"fmt"
5+
"os"
56
"testing"
6-
)
77

8-
const twocapKey = "c9a8a86ed4e59e331e2ca6a304155d6b"
8+
"github.com/joho/godotenv"
9+
)
910

1011
// Test2CaptchaGetID tests that it can successfully get a ID from 2Captcha
1112
// to run this specific test:
1213
// go test -v -run ^Test2CaptchaGetID$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
1314
func Test2CaptchaGetID(t *testing.T) {
15+
if err := godotenv.Load("../.env"); err != nil {
16+
t.Fatalf("Failed to load .env file: %v", err)
17+
}
18+
twocapKey := os.Getenv("2CAPTCHA_KEY")
1419
var tests = []testConfigs{
1520
{
1621
SolvingSite: TwoCaptchaSite,
@@ -59,6 +64,10 @@ func Test2CaptchaGetID(t *testing.T) {
5964
// to run this specific test:
6065
// go test -v -run ^Test2CaptchaGetBalance$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
6166
func Test2CaptchaGetBalance(t *testing.T) {
67+
if err := godotenv.Load("../.env"); err != nil {
68+
t.Fatalf("Failed to load .env file: %v", err)
69+
}
70+
twocapKey := os.Getenv("2CAPTCHA_KEY")
6271
var tests = []testConfigs{
6372
{
6473
SolvingSite: TwoCaptchaSite,
@@ -95,6 +104,10 @@ func Test2CaptchaGetBalance(t *testing.T) {
95104
// to run this specific test:
96105
// go test -v -run ^Test2CaptchaGetV2$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
97106
func Test2CaptchaGetV2(t *testing.T) {
107+
if err := godotenv.Load("../.env"); err != nil {
108+
t.Fatalf("Failed to load .env file: %v", err)
109+
}
110+
twocapKey := os.Getenv("2CAPTCHA_KEY")
98111
configs := []testConfigs{
99112
{
100113
SolvingSite: TwoCaptchaSite,
@@ -132,6 +145,10 @@ func Test2CaptchaGetV2(t *testing.T) {
132145
// to run this specific test:
133146
// go test -v -run ^Test2CaptchaGetV2Additional$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
134147
func Test2CaptchaGetV2Additional(t *testing.T) {
148+
if err := godotenv.Load("../.env"); err != nil {
149+
t.Fatalf("Failed to load .env file: %v", err)
150+
}
151+
twocapKey := os.Getenv("2CAPTCHA_KEY")
135152
configs := []testConfigs{
136153
{
137154
SolvingSite: TwoCaptchaSite,
@@ -182,6 +199,10 @@ func Test2CaptchaGetV2Additional(t *testing.T) {
182199
// to run this specific test:
183200
// go test -v -run ^Test2CaptchaGetV3$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
184201
func Test2CaptchaGetV3(t *testing.T) {
202+
if err := godotenv.Load("../.env"); err != nil {
203+
t.Fatalf("Failed to load .env file: %v", err)
204+
}
205+
twocapKey := os.Getenv("2CAPTCHA_KEY")
185206
configs := []testConfigs{
186207
{
187208
SolvingSite: TwoCaptchaSite,
@@ -206,6 +227,10 @@ func Test2CaptchaGetV3(t *testing.T) {
206227
// to run this specific test:
207228
// go test -v -run ^Test2CaptchaGetImage$ github.com/Matthew17-21/Captcha-Tools/captchatools-go
208229
func Test2CaptchaGetImage(t *testing.T) {
230+
if err := godotenv.Load("../.env"); err != nil {
231+
t.Fatalf("Failed to load .env file: %v", err)
232+
}
233+
twocapKey := os.Getenv("2CAPTCHA_KEY")
209234
configs := []testConfigs{
210235
{
211236
SolvingSite: TwoCaptchaSite,

0 commit comments

Comments
 (0)