Skip to content

Commit

Permalink
Revert Namegenerator library
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Borovcanin <[email protected]>
  • Loading branch information
dborovcanin committed Apr 3, 2024
1 parent c0e953d commit 4bbb245
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 29 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21.5
toolchain go1.21.6

require (
github.com/0x6flab/namegenerator v1.2.0
github.com/absmach/callhome v0.14.0
github.com/absmach/mproxy v0.4.2
github.com/absmach/senml v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiV
cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI=
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
github.com/0x6flab/namegenerator v1.2.0 h1:RuHRO7NDGQpZ9ajRFP5ALcl66cyi0hqjs1fXDV+3pZE=
github.com/0x6flab/namegenerator v1.2.0/go.mod h1:h28wadnJ13Q7PxpUzAHckVj9ToyAEdx5T186Zj1kp+k=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down
4 changes: 2 additions & 2 deletions internal/groups/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"github.com/0x6flab/namegenerator"
"github.com/absmach/magistrala"
"github.com/absmach/magistrala/auth"
authmocks "github.com/absmach/magistrala/auth/mocks"
Expand All @@ -22,15 +23,14 @@ import (
mggroups "github.com/absmach/magistrala/pkg/groups"
"github.com/absmach/magistrala/pkg/groups/mocks"
"github.com/absmach/magistrala/pkg/uuid"
"github.com/goombaio/namegenerator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

var (
idProvider = uuid.New()
token = "token"
namegen = namegenerator.NewNameGenerator(time.Now().UTC().UnixNano())
namegen = namegenerator.NewNameGenerator()
validGroup = mggroups.Group{
Name: namegen.Generate(),
Description: namegen.Generate(),
Expand Down
24 changes: 8 additions & 16 deletions pkg/clients/postgres/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"
"time"

"github.com/0x6flab/namegenerator"
ipostgres "github.com/absmach/magistrala/internal/postgres"
"github.com/absmach/magistrala/internal/testsutil"
"github.com/absmach/magistrala/pkg/clients"
Expand All @@ -19,15 +20,14 @@ import (
pgclients "github.com/absmach/magistrala/pkg/clients/postgres"
"github.com/absmach/magistrala/pkg/errors"
repoerr "github.com/absmach/magistrala/pkg/errors/repository"
"github.com/goombaio/namegenerator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
password = "$tr0ngPassw0rd"
emailSuffix = "@example.com"
namegen = namegenerator.NewNameGenerator(time.Now().UTC().UnixNano())
namegen = namegenerator.NewNameGenerator()
)

func TestRetrieveByID(t *testing.T) {
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestRetrieveAll(t *testing.T) {
Identity: namegen.Generate() + emailSuffix,
Secret: password,
},
Tags: generateNames(5),
Tags: namegen.GenerateNames(5),
Metadata: mgclients.Metadata{
"department": namegen.Generate(),
},
Expand Down Expand Up @@ -683,7 +683,7 @@ func TestRetrieveByIDs(t *testing.T) {
Identity: name + emailSuffix,
Secret: password,
},
Tags: generateNames(5),
Tags: namegen.GenerateNames(5),
Metadata: map[string]interface{}{"name": name},
CreatedAt: time.Now().UTC().Truncate(time.Millisecond),
Status: clients.EnabledStatus,
Expand Down Expand Up @@ -1501,23 +1501,23 @@ func TestUpdateTags(t *testing.T) {
desc: "for enabled client",
client: mgclients.Client{
ID: client1.ID,
Tags: generateNames(5),
Tags: namegen.GenerateNames(5),
},
err: nil,
},
{
desc: "for disabled client",
client: mgclients.Client{
ID: client2.ID,
Tags: generateNames(5),
Tags: namegen.GenerateNames(5),
},
err: repoerr.ErrNotFound,
},
{
desc: "for invalid client",
client: mgclients.Client{
ID: testsutil.GenerateUUID(t),
Tags: generateNames(5),
Tags: namegen.GenerateNames(5),
},
err: repoerr.ErrNotFound,
},
Expand Down Expand Up @@ -1825,7 +1825,7 @@ func generateClient(t *testing.T, status mgclients.Status, role mgclients.Role,
Identity: namegen.Generate() + emailSuffix,
Secret: password,
},
Tags: generateNames(5),
Tags: namegen.GenerateNames(5),
Metadata: mgclients.Metadata{
"name": namegen.Generate(),
},
Expand Down Expand Up @@ -1874,11 +1874,3 @@ func getIDs(clis []mgclients.Client) []string {

return ids
}

func generateNames(num int) []string {
ret := make([]string, num)
for i := 0; i < num; i++ {
ret[i] = namegen.Generate()
}
return ret
}
5 changes: 2 additions & 3 deletions things/api/http/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"net/http/httptest"
"strings"
"testing"
"time"

"github.com/0x6flab/namegenerator"
authmocks "github.com/absmach/magistrala/auth/mocks"
"github.com/absmach/magistrala/internal/api"
"github.com/absmach/magistrala/internal/apiutil"
Expand All @@ -27,7 +27,6 @@ import (
httpapi "github.com/absmach/magistrala/things/api/http"
"github.com/absmach/magistrala/things/mocks"
"github.com/go-chi/chi/v5"
"github.com/goombaio/namegenerator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
Expand All @@ -49,7 +48,7 @@ var (
inValidToken = "invalid"
inValid = "invalid"
validID = "d4ebb847-5d0e-4e46-bdd9-b6aceaaa3a22"
namesgen = namegenerator.NewNameGenerator(time.Now().UTC().UnixNano())
namesgen = namegenerator.NewNameGenerator()
)

const contentType = "application/json"
Expand Down
5 changes: 2 additions & 3 deletions things/postgres/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import (
"fmt"
"strings"
"testing"
"time"

"github.com/0x6flab/namegenerator"
"github.com/absmach/magistrala/internal/testsutil"
"github.com/absmach/magistrala/pkg/clients"
"github.com/absmach/magistrala/pkg/errors"
repoerr "github.com/absmach/magistrala/pkg/errors/repository"
"github.com/absmach/magistrala/things/postgres"
"github.com/goombaio/namegenerator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -28,7 +27,7 @@ var (
clientName = "client name"
invalidClientID = "invalidClientID"
invalidDomainID = strings.Repeat("m", maxNameSize+10)
namesgen = namegenerator.NewNameGenerator(time.Now().UTC().UnixNano())
namesgen = namegenerator.NewNameGenerator()
)

func TestClientsSave(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions tools/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"strings"
"time"

"github.com/0x6flab/namegenerator"
sdk "github.com/absmach/magistrala/pkg/sdk/go"
"github.com/gookit/color"
"github.com/goombaio/namegenerator"
"github.com/gorilla/websocket"
"golang.org/x/sync/errgroup"
)
Expand All @@ -31,7 +31,7 @@ const (
)

var (
namesgenerator = namegenerator.NewNameGenerator(time.Now().UTC().UnixNano())
namesgenerator = namegenerator.NewNameGenerator()
msgFormat = `[{"bn":"demo", "bu":"V", "t": %d, "bver":5, "n":"voltage", "u":"V", "v":%d}]`
)

Expand Down
5 changes: 2 additions & 3 deletions users/postgres/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import (
"fmt"
"strings"
"testing"
"time"

"github.com/0x6flab/namegenerator"
"github.com/absmach/magistrala/internal/testsutil"
mgclients "github.com/absmach/magistrala/pkg/clients"
"github.com/absmach/magistrala/pkg/errors"
repoerr "github.com/absmach/magistrala/pkg/errors/repository"
cpostgres "github.com/absmach/magistrala/users/postgres"
"github.com/goombaio/namegenerator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -25,7 +24,7 @@ const maxNameSize = 254
var (
invalidName = strings.Repeat("m", maxNameSize+10)
password = "$tr0ngPassw0rd"
namesgen = namegenerator.NewNameGenerator(time.Now().UTC().UnixNano())
namesgen = namegenerator.NewNameGenerator()
)

func TestClientsSave(t *testing.T) {
Expand Down

0 comments on commit 4bbb245

Please sign in to comment.