Skip to content

Commit

Permalink
🐛 fix comments and add tests for latest release (#2544)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuskimmina authored Nov 9, 2023
1 parent 04372f6 commit 3e95c6d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cnquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func GetVersion() string {
return Version
}

// Release represents a GitHub release
// Release represents a release
type Release struct {
Name string `json:"name"`
Version string `json:"version"`
}

var cnqueryGithubReleaseUrl = "https://releases.mondoo.com/cnquery/latest.json?ignoreCache=1"
var cnqueryLatestReleaseUrl = "https://releases.mondoo.com/cnquery/latest.json?ignoreCache=1"

// GetLatestReleaseName fetches the name of the latest release from the specified GitHub repository
// GetLatestReleaseName fetches the name of the latest release from releases.mondoo.com
func GetLatestReleaseName(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
Expand All @@ -79,9 +79,9 @@ func GetLatestReleaseName(url string) (string, error) {
return release.Version, nil
}

// GetLatestVersion returns the latest version available on Github
// GetLatestVersion returns the latest version available on releases.mondoo.com
func GetLatestVersion() (string, error) {
releaseName, err := GetLatestReleaseName(cnqueryGithubReleaseUrl)
releaseName, err := GetLatestReleaseName(cnqueryLatestReleaseUrl)
if err != nil {
return "", err
}
Expand Down
18 changes: 18 additions & 0 deletions cnquery_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package cnquery

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetLatestVersion(t *testing.T) {
version, err := GetLatestVersion()

assert.NoError(t, err)
assert.NotNil(t, version)
assert.Equal(t, cnqueryLatestReleaseUrl, "https://releases.mondoo.com/cnquery/latest.json?ignoreCache=1")
}

0 comments on commit 3e95c6d

Please sign in to comment.