Skip to content

Commit

Permalink
chore(refactor): cleaned up internal/install/discovery package; remov…
Browse files Browse the repository at this point in the history
…ed unneeded receivers on RecipeInstall
  • Loading branch information
mbruzina committed Nov 11, 2022
1 parent 14469af commit 1d40669
Show file tree
Hide file tree
Showing 18 changed files with 592 additions and 476 deletions.
50 changes: 33 additions & 17 deletions internal/install/discovery/manifest_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,65 @@
package discovery

import (
"context"
"fmt"
"github.com/newrelic/newrelic-cli/internal/install/discovery/mocks"
"github.com/newrelic/newrelic-cli/internal/install/types"
"github.com/stretchr/testify/mock"
"testing"

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

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

err := NewManifestValidator().Validate(discover.GetManifest())
err := NewManifestValidator().Validate(manifest)
require.NoError(t, err)
}

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

err := NewManifestValidator().Validate(discover.GetManifest())
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) {
discover := NewMockDiscoverer()
discover.SetOs("windows")
discover.SetPlatformVersion("1")
mockDiscoverer := mocks.NewDiscoverer(t)
mockDiscoverer.On("Discover", mock.Anything).Return(&types.DiscoveryManifest{
OS: "windows",
PlatformVersion: "1",
}, nil)
manifest, _ := mockDiscoverer.Discover(context.Background())

result := NewManifestValidator().Validate(discover.GetManifest())
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) {
discover := NewMockDiscoverer()
discover.SetOs("linux")
discover.SetPlatform("ubuntu")
discover.SetPlatformVersion("12.04")
mockDiscoverer := mocks.NewDiscoverer(t)
mockDiscoverer.On("Discover", mock.Anything).Return(&types.DiscoveryManifest{
OS: "linux",
Platform: "ubuntu",
PlatformVersion: "10.14",
}, nil)
manifest, _ := mockDiscoverer.Discover(context.Background())

result := NewManifestValidator().Validate(discover.GetManifest())
result := NewManifestValidator().Validate(manifest)
require.Contains(t, result.Error(), errorPrefix)
require.Contains(t, result.Error(), fmt.Sprintf(versionNoLongerSupported, "linux/ubuntu"))
}
Binary file not shown.
Binary file not shown.
22 changes: 0 additions & 22 deletions internal/install/discovery/mockProcesses/JavaDaemonTest.java

This file was deleted.

49 changes: 0 additions & 49 deletions internal/install/discovery/mock_discoverer.go

This file was deleted.

57 changes: 0 additions & 57 deletions internal/install/discovery/mock_empty_discoverer.go

This file was deleted.

16 changes: 0 additions & 16 deletions internal/install/discovery/mock_os_validator.go

This file was deleted.

85 changes: 85 additions & 0 deletions internal/install/discovery/mocks/Discoverer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions internal/install/discovery/mocks/Validator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1d40669

Please sign in to comment.