Skip to content

Commit

Permalink
[#222] addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pzadroga committed Oct 24, 2024
1 parent 55cb7df commit 24d134f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 33 deletions.
19 changes: 4 additions & 15 deletions backend/server/restservice/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,11 @@ func (r *RestAPI) GetSoftwareVersions(ctx context.Context, params general.GetSof
}

// Find the location of the JSON file with software versions metadata.
var jsonFile string
for _, f := range getPotentialVersionsJSONLocations() {
_, err := os.Stat(f)
if err == nil {
jsonFile = f
break
}
}
if jsonFile == "" {
msg := "Cannot find the JSON file with software versions metadata"
log.Error(msg)
rsp := general.NewGetSoftwareVersionsDefault(http.StatusInternalServerError).WithPayload(&models.APIError{
Message: &msg,
})
return rsp
searchPaths := []string{
VersionsJSON, // this is default location of the file in case Stork is installed from packages - most common use case
"etc/versions.json", // this is added in case Stork is built and ran from sources - typical for Stork development
}
jsonFile := storkutil.GetFirstExistingPathOrDefault(VersionsJSON, searchPaths...)

// Open JSON file.
file, err := os.Open(jsonFile)
Expand Down
8 changes: 0 additions & 8 deletions backend/server/restservice/swversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ type ReportAppsVersions struct {
// It needs to be modified by tests so it has to be global variable.
var VersionsJSON = "/etc/stork/versions.json" //nolint:gochecknoglobals

// Get potential locations of versions.json.
func getPotentialVersionsJSONLocations() []string {
return []string{
VersionsJSON, // this is default location of the file in case Stork is installed from packages - most common use case
"etc/versions.json", // this is added in case Stork is built and ran from sources - typical for Stork development
}
}

// Post processes either Kea, Bind9 or Stork version metadata and returns the data in REST API format.
// It returns an error when problem occurs when parsing dates.
func appVersionMetadataToRestAPI(input ReportAppVersionMetadata) (*models.AppVersionMetadata, error) {
Expand Down
11 changes: 1 addition & 10 deletions backend/server/restservice/swversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func TestVersionDetailsToRestAPIError(t *testing.T) {
Esv: esv,
}
resultOne, err1 := versionDetailsToRestAPI(exampleOne)

relDate = "bad date"
eolDate = "2026-12-31"
exampleTwo := ReportVersionDetails{
Version: storkutil.NewSemanticVersion(3, 2, 1),
ReleaseDate: &relDate,
Expand Down Expand Up @@ -195,12 +195,3 @@ func TestAppVersionMetadataToRestAPI(t *testing.T) {
require.Equal(t, "9.18.30", bind.SortedStableVersions[0])
require.Equal(t, "9.20.2", bind.SortedStableVersions[1])
}

// Check if TestGetPotentialVersionsJSONLocations returns paths.
func TestGetPotentialVersionsJSONLocations(t *testing.T) {
// Arrange & Act
paths := getPotentialVersionsJSONLocations()

// Assert
require.Greater(t, len(paths), 1)
}

0 comments on commit 24d134f

Please sign in to comment.