-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a bunch of unit tests and changed the logic for validation.
- Loading branch information
Showing
15 changed files
with
448 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cmd | ||
package util | ||
|
||
/*type MockStorageService struct { | ||
mock.Mock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package validation | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
// Entities function is for validating passing entities in args | ||
func Entities(entities []string) error { | ||
numEntities := len(entities) | ||
if numEntities == 0 { | ||
return errors.New("no entity URI specified") | ||
} else if numEntities > 60 { | ||
return errors.New("too many entity URIs (the limit is 60)") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package validation | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
) | ||
|
||
func TestEntities(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
entities []string | ||
expectedError error | ||
}{ | ||
{ | ||
name: "No Entities", | ||
entities: []string{}, | ||
expectedError: errors.New("no entity URI specified"), | ||
}, | ||
{ | ||
name: "Valid Entities", | ||
entities: make([]string, 30), // Example of a valid number of entities | ||
expectedError: nil, | ||
}, | ||
{ | ||
name: "Too Many Entities", | ||
entities: make([]string, 61), | ||
expectedError: errors.New("too many entity URIs (the limit is 60)"), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := Entities(tt.entities) | ||
if tt.expectedError != nil { | ||
if err == nil || err.Error() != tt.expectedError.Error() { | ||
t.Errorf("expected error %v, got %v", tt.expectedError, err) | ||
} | ||
} else if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.