Skip to content

Commit

Permalink
chore(refactor): testing around license key fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
mbruzina committed Nov 15, 2022
1 parent 5014f42 commit acf6b98
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 201 deletions.
33 changes: 12 additions & 21 deletions internal/install/discovery/manifest_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,59 @@
package discovery

import (
"context"
"fmt"
"testing"

"github.com/newrelic/newrelic-cli/internal/install/discovery/mocks"

"github.com/stretchr/testify/mock"

"github.com/newrelic/newrelic-cli/internal/install/types"

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

func Test_ShouldSucceedManifestOsDarwin(t *testing.T) {
mockDiscoverer := mocks.NewDiscoverer(t)
mockDiscoverer.On("Discover", mock.Anything).Return(&types.DiscoveryManifest{
manifest := &types.DiscoveryManifest{
OS: "darwin",
PlatformVersion: "10.14",
}, nil)
manifest, _ := mockDiscoverer.Discover(context.Background())
}

err := NewManifestValidator().Validate(manifest)

require.NoError(t, err)
}

func Test_ShouldFailManifestOsDarwinOldVersion(t *testing.T) {
mockDiscoverer := mocks.NewDiscoverer(t)
mockDiscoverer.On("Discover", mock.Anything).Return(&types.DiscoveryManifest{
manifest := &types.DiscoveryManifest{
OS: "darwin",
PlatformVersion: "10.13",
}, nil)
manifest, _ := mockDiscoverer.Discover(context.Background())
}

err := NewManifestValidator().Validate(manifest)

require.Error(t, err)
require.Contains(t, err.Error(), errorPrefix)
require.Contains(t, err.Error(), "darwin")
}

func Test_ShouldFailManifestWindowsVersion(t *testing.T) {
mockDiscoverer := mocks.NewDiscoverer(t)
mockDiscoverer.On("Discover", mock.Anything).Return(&types.DiscoveryManifest{
manifest := &types.DiscoveryManifest{
OS: "windows",
PlatformVersion: "1",
}, nil)
manifest, _ := mockDiscoverer.Discover(context.Background())
}

result := NewManifestValidator().Validate(manifest)

require.Contains(t, result.Error(), errorPrefix)
require.Contains(t, result.Error(), fmt.Sprintf(versionNoLongerSupported, "windows"))
}

func Test_ShouldFailManifestUbuntuVersion(t *testing.T) {
mockDiscoverer := mocks.NewDiscoverer(t)
mockDiscoverer.On("Discover", mock.Anything).Return(&types.DiscoveryManifest{
manifest := &types.DiscoveryManifest{
OS: "linux",
Platform: "ubuntu",
PlatformVersion: "10.14",
}, nil)
manifest, _ := mockDiscoverer.Discover(context.Background())
}

result := NewManifestValidator().Validate(manifest)

require.Contains(t, result.Error(), errorPrefix)
require.Contains(t, result.Error(), fmt.Sprintf(versionNoLongerSupported, "linux/ubuntu"))
}
30 changes: 9 additions & 21 deletions internal/install/discovery/os_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,47 @@
package discovery

import (
"context"
"testing"

"github.com/newrelic/newrelic-cli/internal/install/discovery/mocks"

"github.com/stretchr/testify/mock"

"github.com/newrelic/newrelic-cli/internal/install/types"

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

func Test_FailsOnInvalidOs(t *testing.T) {
mockDiscoverer := mocks.NewDiscoverer(t)
mockDiscoverer.On("Discover", mock.Anything).Return(&types.DiscoveryManifest{
manifest := &types.DiscoveryManifest{
OS: "freebsd",
}, nil)
manifest, _ := mockDiscoverer.Discover(context.Background())
}

err := NewOsValidator().Validate(manifest)

require.Error(t, err)
require.Contains(t, err.Error(), operatingSystemNotSupportedPrefix)
require.Contains(t, err.Error(), "freebsd")
}

func Test_FailsOnNoOs(t *testing.T) {
mockDiscoverer := mocks.NewDiscoverer(t)
mockDiscoverer.On("Discover", mock.Anything).Return(&types.DiscoveryManifest{
manifest := &types.DiscoveryManifest{
OS: "",
}, nil)
manifest, _ := mockDiscoverer.Discover(context.Background())
}

result := NewOsValidator().Validate(manifest)
require.Equal(t, noOperatingSystemDetected, result.Error())
}

func Test_DoesntFailForWindowsOs(t *testing.T) {
mockDiscoverer := mocks.NewDiscoverer(t)
mockDiscoverer.On("Discover", mock.Anything).Return(&types.DiscoveryManifest{
manifest := &types.DiscoveryManifest{
OS: "windows",
}, nil)
manifest, _ := mockDiscoverer.Discover(context.Background())
}

result := NewOsValidator().Validate(manifest)
require.NoError(t, result)
}

func Test_DoesntFailForLinuxOs(t *testing.T) {
mockDiscoverer := mocks.NewDiscoverer(t)
mockDiscoverer.On("Discover", mock.Anything).Return(&types.DiscoveryManifest{
manifest := &types.DiscoveryManifest{
OS: "linux",
}, nil)
manifest, _ := mockDiscoverer.Discover(context.Background())
}

result := NewOsValidator().Validate(manifest)
require.NoError(t, result)
Expand Down
Loading

0 comments on commit acf6b98

Please sign in to comment.