diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ba1003 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +key.test \ No newline at end of file diff --git a/sms.go b/sms.go index c47ce06..3597192 100644 --- a/sms.go +++ b/sms.go @@ -8,6 +8,7 @@ type RequestSMS struct { ApiKey string `json:"apikey"` Phone string `json:"phones"` Message string `json:"mes"` + Sender string `json:"sender,omitempty"` } type ResponseSMS struct { diff --git a/sms_test.go b/sms_test.go index 60d495b..3b95d0a 100644 --- a/sms_test.go +++ b/sms_test.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "math/rand" + "os" + "path/filepath" "testing" ) @@ -11,12 +13,33 @@ func generateCode() string { return fmt.Sprintf("%04d", rand.Intn(10000)) } +func loadAPIKey(t *testing.T) string { + dirPath, err := os.Getwd() + if err != nil { + t.Fatalf("Не удалось получить текущий каталог: %v", err) + } + data, err := os.ReadFile(filepath.Join(dirPath, "key.test")) + if err != nil { + t.Fatalf("Не удалось прочитать файл key.test: %v", err) + } + return string(data) +} + +func TestLoadAPIKey(t *testing.T) { + key := loadAPIKey(t) + t.Log(key) +} + func TestSendSMS(t *testing.T) { + // Загружаем API-ключ из файла + apiKey := loadAPIKey(t) + // Создаем тестовый запрос req := RequestSMS{ - ApiKey: "80g8w5-t4D5n2X5v2!8s1S3p5E2n2X68e", // Замените на реальный API-ключ для теста - Phone: "79397804368", // Замените на реальный номер телефона + ApiKey: apiKey, + Phone: "79857770038", // Замените на реальный номер телефона Message: "Код подтверждения: " + generateCode(), + Sender: "Noglik-Market", } // Вызываем тестируемую функцию