Skip to content

Commit

Permalink
Made a few corrections. Added some test cov. All for build.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnbdz committed Oct 29, 2024
1 parent 2940279 commit 433026f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
9 changes: 6 additions & 3 deletions entity/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func (s *SBuild) Meta(paths storage.AbsPaths, entityUri string) (entity.Entity,
}

dir, err := s.Entity.FindEntityDir(paths, entityVals)
if !errors.Is(err, entity.ErrorNotFound) &&
!errors.Is(err, entity.ErrorMultipleFound) &&
if !errors.Is(err, entity.ErrorNotFound) && // If the directory or path was not found
!errors.Is(err, entity.ErrorMultipleFound) && // In some cases where there are multiple directory for the same entity with multiple pseudo versions
err != nil {
// Returns an error when it is outside just not found or multiple directories
return entityVals, err
} else if err == nil {
entityVals.AbsPath = dir
Expand Down Expand Up @@ -207,6 +208,8 @@ func (s *SBuild) metaFromRemoteWithVersion(entityUri, entityVersion string) (ent
}
entityVals.IsPseudoVersion = false
}
entityVals.LatestVersion = true
entityUri = fmt.Sprintf("%s@%s", entityUriWithoutVersion, entityVersion)
} else if !s.EntityVersionValidation.Format(entityVersion) &&
!s.EntityVersionValidation.PseudoFormat(entityVersion) {
return entityVals, fmt.Errorf("invalid entity version format: %v", entityVersion)
Expand All @@ -222,7 +225,7 @@ func (s *SBuild) metaFromRemoteWithVersion(entityUri, entityVersion string) (ent
return entityVals, nil
}

// constructOrigin
// constructOrigin generates the last part of the full path from the repository URI host and path with the version
func (s *SBuild) constructOrigin(entityUri, name, version string) string {
return strings.Replace(
entityUri,
Expand Down
60 changes: 53 additions & 7 deletions entity/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ func TestMeta(t *testing.T) {
},
mockEntityVersion: func(mockEntityVersion *version.MockEntityVersion) {
mockEntityVersion.EXPECT().Extract("github.com/example/entity@v1.0.0").Return("v1.0.0", nil)
//mockEntityVersion.EXPECT().List("https://github.com/example/entity").Return([]string{"v1.0.0"}, nil)
//mockEntityVersion.EXPECT().Latest([]string{"v1.0.0"}).Return("v1.0.0", nil)
},
mockEntityVersionVal: func(mockEntityVersionVal *versionValidationPkg.MockEntityVersionValidation) {
// No specific mocks needed for validation in this case
//mockEntityVersionVal.EXPECT().
},
expectEntity: entity.Entity{
Id: "dca736d3-26c4-46b2-be5a-dfbdc09cff6d",
Expand All @@ -72,6 +69,44 @@ func TestMeta(t *testing.T) {
},
hasError: false,
},
{
name: "Valid Entity URI With Latest Version",
inputPaths: storage.AbsPaths{
Entities: "/home/user/.hery/amadla/entity/",
},
inputEntityUri: "github.com/example/entity@latest",
internalEntityDir: "",
internalEntityDirErr: entity.ErrorNotFound, // Not found since `latest` should never be used in directory name (only the latest static version or pseudo version)
mockValidation: func(mockValidation *validation.MockEntityValidation) {
mockValidation.EXPECT().EntityUri("github.com/example/entity@latest").Return(true)
},
mockEntityVersion: func(mockEntityVersion *version.MockEntityVersion) {
mockEntityVersion.EXPECT().Extract("github.com/example/entity@latest").Return("latest", nil)
mockEntityVersion.EXPECT().List("https://github.com/example/entity").Return([]string{"v1.0.0", "v1.0.1"}, nil)
mockEntityVersion.EXPECT().Latest([]string{"v1.0.0", "v1.0.1"}).Return("v1.0.1", nil)
},
mockEntityVersionVal: func(mockEntityVersionVal *versionValidationPkg.MockEntityVersionValidation) {
// No specific mocks needed for validation in this case
//mockEntityVersionVal.EXPECT().
},
expectEntity: entity.Entity{
Id: "dca736d3-26c4-46b2-be5a-dfbdc09cff6d",
Entity: "github.com/example/entity@v1.0.1",
Name: "entity",
RepoUrl: "https://github.com/example/entity",
Origin: "github.com/example/",
Version: "v1.0.1",
LatestVersion: true,
IsPseudoVersion: false,
AbsPath: "/home/user/.hery/amadla/entity/github.com/example/entity@v1.0.1",
Have: false,
Hash: "",
Exist: true,
Schema: nil,
Config: nil,
},
hasError: false,
},
//
// Error
//
Expand Down Expand Up @@ -412,14 +447,20 @@ func TestMetaFromRemoteWithVersion(t *testing.T) {
internalEntityVersionLatest: "",
internalEntityVersionLatestErr: nil,
expectEntity: entity.Entity{
Entity: "github.com/AmadlaOrg/Entity@latest",
Id: "",
Entity: "github.com/AmadlaOrg/Entity@v0.0.0-20240823005443-9b4947da3948",
Name: "Entity",
RepoUrl: "https://github.com/AmadlaOrg/Entity",
Origin: "github.com/AmadlaOrg/Entity@latest",
Origin: "github.com/AmadlaOrg/",
Version: "v0.0.0-20240823005443-9b4947da3948",
LatestVersion: true,
IsPseudoVersion: true,
AbsPath: "",
Have: false,
Hash: "",
Exist: false,
Schema: nil,
Config: nil,
},
hasError: false,
},
Expand All @@ -434,14 +475,19 @@ func TestMetaFromRemoteWithVersion(t *testing.T) {
internalEntityVersionLatest: "v3.0.0",
internalEntityVersionLatestErr: nil,
expectEntity: entity.Entity{
Entity: "github.com/AmadlaOrg/Entity@latest",
Entity: "github.com/AmadlaOrg/Entity@v3.0.0",
Name: "Entity",
RepoUrl: "https://github.com/AmadlaOrg/Entity",
Origin: "github.com/AmadlaOrg/Entity@latest",
Origin: "github.com/AmadlaOrg/",
Version: "v3.0.0",
LatestVersion: true,
IsPseudoVersion: false,
AbsPath: "",
Have: false,
Hash: "",
Exist: false,
Schema: nil,
Config: nil,
},
hasError: false,
},
Expand Down

0 comments on commit 433026f

Please sign in to comment.