Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions db/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ type WorkoutDto struct {
Year int `json:"year"`
}

func TestGetCats(t *testing.T) {
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI("mongodb://172.17.0.2:27017/cats"))
if err != nil {
log.Printf("Error connecting to MongoDB: %v", err)
}

defer func() {
if err := client.Disconnect(context.TODO()); err != nil {
panic(err)
}
}()

coll := client.Database("cats").Collection("cats")

var result bson.M

coll.FindOne(context.TODO(), bson.D{{"age", 2}}).Decode(&result)

println(result)
}

func TestGetWorkouts(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions fss/git_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fss

import (
"encoding/json"
"io/ioutil"
"os"
"time"
)

Expand Down Expand Up @@ -116,7 +116,7 @@ type Repo struct {
func ReadJsonGT() []Repo {
var repos []Repo
pth := "/home/malandr/Documents/repos.json"
file, err := ioutil.ReadFile(pth)
file, err := os.ReadFile(pth)
if err != nil {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions fss/read_lorem.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"time"
)

const DIR_NAME = "/home/malandr/Documents/"
const DirName = "/home/andrii/Documents/"

func TestReadDocs(t *testing.T) {
docsDir, err := os.ReadDir(DIR_NAME)
docsDir, err := os.ReadDir(DirName)
if err != nil {
return
}
Expand All @@ -23,7 +23,7 @@ func TestReadDocs(t *testing.T) {
for i := 1; i <= 400; i++ {
wg.Add(1)
go func(num int) {
fileBts, err := os.ReadFile(fmt.Sprintf("%s%s", DIR_NAME, docsDir[num].Name()))
fileBts, err := os.ReadFile(fmt.Sprintf("%s%s", DirName, docsDir[num].Name()))
if err != nil {
fmt.Println(err)
}
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module go-tests

go 1.22

toolchain go1.23.4
go 1.23

require (
github.com/apache/pulsar-client-go v0.10.0
Expand Down
4 changes: 2 additions & 2 deletions net/get_urls_sync_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net

import (
"io/ioutil"
"io"
"log"
"net/http"
"sync"
Expand All @@ -27,7 +27,7 @@ func GetData(url string, wg *sync.WaitGroup) {
if err != nil {
log.Fatalln(err)
}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
Expand Down
28 changes: 18 additions & 10 deletions regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"regexp"
"runtime"
"strings"
"testing"
)
Expand All @@ -19,12 +20,7 @@ func TestReadLogFile(t *testing.T) {

lines := strings.Split(string(logData), "\n")

//var m runtime.MemStats
//runtime.ReadMemStats(&m)
//fmt.Printf("Alloc = %s", formatBytes(m.Alloc))
//fmt.Printf("\tTotalAlloc = %s", formatBytes(m.TotalAlloc))
//fmt.Printf("\tSys = %s", formatBytes(m.Sys))
//fmt.Printf("\tNumGC = %v\n", m.NumGC)
//memStats()

userNames := make(map[string]struct{})

Expand Down Expand Up @@ -73,7 +69,12 @@ func ReadLineByLine() {
return
}
// 2. Ensure the file is closed at the end of the function
defer file.Close()
defer func(file *os.File) {
err := file.Close()
if err != nil {
return
}
}(file)

// 3. Create a new Scanner for the file
scanner := bufio.NewScanner(file)
Expand All @@ -93,10 +94,9 @@ func ReadLineByLine() {

func TestParseLogs(t *testing.T) {

//
var regExp = regexp.MustCompile("^(\\d+\\.\\d+\\.\\d+\\.\\d+) (.*) (.*) (\\[.*\\]) (\".*\") (\".*\") (\".*\")$")

data := "127.0.0.1 158x6583999x2 a.navadiya [08/Mar/2025:02:38:51 -0800] \"GET /rest/internal/2.0/client- HTTP/1.0\" 200 18 6 \"https://jira.ontrq.com/secure/Dashboard.jspa?selectPageId=83502\" \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36\" \"1sx1d6m\""
data := "127.0.0.1 158x6583999x2 a.navaddi [08/Mar/2025:02:38:51 -0800] \"GET /rest/internal/2.0/client- HTTP/1.0\" 200 18 6 \"https://jira.x.com/secure/Dashboard.jspa?selectPageId=83502\" \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36\" \"1sx1d6m\""

matchString := regExp.MatchString(data)

Expand All @@ -110,7 +110,6 @@ func TestParseLogs(t *testing.T) {
//requestIdx := 4
//clientIdx := 5
//sessionIdx := 6
//
//ipData := string(submatch[0][ipIdx])
//reqId := string(submatch[0][reqIdx])
//username := string(submatch[0][userNameIdx])
Expand All @@ -126,3 +125,12 @@ func TestParseLogs(t *testing.T) {

}
}

func memStats() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("Alloc = %s", formatBytes(m.Alloc))
fmt.Printf("\tTotalAlloc = %s", formatBytes(m.TotalAlloc))
fmt.Printf("\tSys = %s", formatBytes(m.Sys))
fmt.Printf("\tNumGC = %v\n", m.NumGC)
}
Loading