Skip to content

Commit

Permalink
refactor: fix lint warnings (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Aug 31, 2024
2 parents eb4a92a + da29f1d commit 4d3ce53
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/model/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func validate(inputModel authorizationmodel.AuthzModel) validationResult {
return output
}

createdAt := time.Unix(int64(modelID.Time()/1_000), 0).UTC() //nolint:mnd
createdAt := ulid.Time(modelID.Time()).UTC()
output.CreatedAt = &createdAt
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/store/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func importStore(
storeData *storetest.StoreData,
format authorizationmodel.ModelFormat,
storeID string,
maxTuplesPerWrite, maxParallelRequests int,
maxTuplesPerWrite, maxParallelRequests int32,
fileName string,
) (*CreateStoreAndModelResponse, error) {
var (
Expand Down Expand Up @@ -159,8 +159,8 @@ func importStore(
}),
)

for index := 0; index < len(storeData.Tuples); index += maxTuplesPerWrite {
end := index + maxTuplesPerWrite
for index := 0; index < len(storeData.Tuples); index += int(maxTuplesPerWrite) {
end := index + int(maxTuplesPerWrite)
if end > len(storeData.Tuples) {
end = len(storeData.Tuples)
}
Expand Down Expand Up @@ -202,12 +202,12 @@ var importCmd = &cobra.Command{
return fmt.Errorf("failed to get store-id: %w", err)
}

maxTuplesPerWrite, err := cmd.Flags().GetInt("max-tuples-per-write")
maxTuplesPerWrite, err := cmd.Flags().GetInt32("max-tuples-per-write")
if err != nil {
return fmt.Errorf("failed to parse max tuples per write: %w", err)
}

maxParallelRequests, err := cmd.Flags().GetInt("max-parallel-requests")
maxParallelRequests, err := cmd.Flags().GetInt32("max-parallel-requests")
if err != nil {
return fmt.Errorf("failed to parse parallel requests: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/tuple/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ var deleteCmd = &cobra.Command{
return fmt.Errorf("failed to parse input tuples due to %w", err)
}

maxTuplesPerWrite, err := cmd.Flags().GetInt("max-tuples-per-write")
maxTuplesPerWrite, err := cmd.Flags().GetInt32("max-tuples-per-write")
if err != nil {
return fmt.Errorf("failed to parse max tuples per write due to %w", err)
}

maxParallelRequests, err := cmd.Flags().GetInt("max-parallel-requests")
maxParallelRequests, err := cmd.Flags().GetInt32("max-parallel-requests")
if err != nil {
return fmt.Errorf("failed to parse parallel requests due to %w", err)
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/tuple/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ type ImportResponse struct {
func ImportTuples(
fgaClient client.SdkClient,
body client.ClientWriteRequest,
maxTuplesPerWrite int,
maxParallelRequests int,
maxTuplesPerWrite int32,
maxParallelRequests int32,
) (*ImportResponse, error) {
options := client.ClientWriteOptions{
Transaction: &client.TransactionOptions{
Disable: true,
MaxPerChunk: int32(maxTuplesPerWrite),
MaxParallelRequests: int32(maxParallelRequests),
MaxPerChunk: maxTuplesPerWrite,
MaxParallelRequests: maxParallelRequests,
},
}

Expand Down Expand Up @@ -168,12 +168,12 @@ var importCmd = &cobra.Command{
return fmt.Errorf("failed to parse file name due to %w", err)
}

maxTuplesPerWrite, err := cmd.Flags().GetInt("max-tuples-per-write")
maxTuplesPerWrite, err := cmd.Flags().GetInt32("max-tuples-per-write")
if err != nil {
return fmt.Errorf("failed to parse max tuples per write due to %w", err)
}

maxParallelRequests, err := cmd.Flags().GetInt("max-parallel-requests")
maxParallelRequests, err := cmd.Flags().GetInt32("max-parallel-requests")
if err != nil {
return fmt.Errorf("failed to parse parallel requests due to %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/tuple/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ func writeTuplesFromFile(flags *flag.FlagSet, fgaClient *client.OpenFgaClient) e
return errors.New("file name cannot be empty") //nolint:goerr113
}

maxTuplesPerWrite, err := flags.GetInt("max-tuples-per-write")
maxTuplesPerWrite, err := flags.GetInt32("max-tuples-per-write")
if err != nil {
return fmt.Errorf("failed to parse max tuples per write: %w", err)
}

maxParallelRequests, err := flags.GetInt("max-parallel-requests")
maxParallelRequests, err := flags.GetInt32("max-parallel-requests")
if err != nil {
return fmt.Errorf("failed to parse parallel requests: %w", err)
}
Expand Down
6 changes: 4 additions & 2 deletions internal/authorizationmodel/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func getCreatedAtFromModelID(id string) (*time.Time, error) {
return nil, fmt.Errorf("error parsing model id %w", err)
}

createdAt := time.Unix(int64(modelID.Time()/1_000), 0).UTC() //nolint:mnd
createdAt := ulid.Time(modelID.Time()).UTC()

return &createdAt, nil
}
Expand Down Expand Up @@ -131,6 +131,8 @@ func (model *AuthzModel) GetCreatedAt() *time.Time {
if model.ID != nil {
createdAt, _ := getCreatedAtFromModelID(model.GetID())

model.CreatedAt = createdAt

return createdAt
}

Expand Down Expand Up @@ -286,7 +288,7 @@ func (model *AuthzModel) setCreatedAt() {
if *model.ID != "" {
modelID, err := ulid.Parse(*model.ID)
if err == nil {
createdAt := time.Unix(int64(modelID.Time()/1_000), 0).UTC() //nolint:mnd
createdAt := ulid.Time(modelID.Time()).UTC()
model.CreatedAt = &createdAt
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/authorizationmodel/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const (
modelID = "01GVKXGDCV2SMG6TRE9NMBQ2VG"
typeName = "user"
modelCreatedAt = "2023-03-16 00:35:51 +0000 UTC"
modelCreatedAt = "2023-03-16 00:35:51.835 +0000 UTC"
)

func TestReadingInvalidModelFromInvalidJSON(t *testing.T) {
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestReadingValidModelFromJSON(t *testing.T) {
}

if model.CreatedAt.String() != modelCreatedAt {
t.Errorf("Expected %v to equal %v", model.CreatedAt.String(), modelCreatedAt)
t.Errorf("Expected %v to equal %v", model.GetCreatedAt().String(), modelCreatedAt)
}

if model.GetTypeDefinitions()[0].GetType() != typeName {
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestDisplayAsJsonWithFields(t *testing.T) {
}

if jsonModel1.GetCreatedAt().String() != modelCreatedAt {
t.Errorf("Expected %v to equal %v", jsonModel1.CreatedAt.String(), modelCreatedAt)
t.Errorf("Expected %v to equal %v", jsonModel1.GetCreatedAt().String(), modelCreatedAt)
}

if jsonModel1.GetTypeDefinitions()[0].GetType() != typeName {
Expand All @@ -117,7 +117,7 @@ func TestDisplayAsJsonWithFields(t *testing.T) {
}

if jsonModel1.GetCreatedAt().String() != modelCreatedAt {
t.Errorf("Expected %v to equal %v", jsonModel2.CreatedAt.String(), modelCreatedAt)
t.Errorf("Expected %v to equal %v", jsonModel2.GetCreatedAt().String(), modelCreatedAt)
}

if jsonModel2.GetTypeDefinitions() != nil {
Expand Down

0 comments on commit 4d3ce53

Please sign in to comment.