Skip to content

Commit

Permalink
feat(scripts): update install.sh to use packages on macOS (#1127)
Browse files Browse the repository at this point in the history
* feat(scripts): use package install on macOS

Signed-off-by: Justin Kolberg <[email protected]>

* chore: add e2e tests for darwin package install

Signed-off-by: Justin Kolberg <[email protected]>

* chore: remove commented code

Signed-off-by: Justin Kolberg <[email protected]>

* use SumoLogic as package github org, fixed pkg release download link

Signed-off-by: Sean Porter <[email protected]>

* chore(pkg/scripts_test): fix linux lint failures

Signed-off-by: Justin Kolberg <[email protected]>

* chore(pkg/scripts_test): clean up

Signed-off-by: Justin Kolberg <[email protected]>

* chore(pkg/scripts_test): additional clean up

Signed-off-by: Justin Kolberg <[email protected]>

* fix(pkg/scripts_test): missing _ in systemGroup

Signed-off-by: Justin Kolberg <[email protected]>

* fix(pkg/scripts_test): fixes for darwin

Signed-off-by: Justin Kolberg <[email protected]>

* fix(pkg/scripts_test): darwin tests

Signed-off-by: Justin Kolberg <[email protected]>

* fix: don't check for user tags twice on darwin

Signed-off-by: Justin Kolberg <[email protected]>

* chore: replace if conditions with switch

Signed-off-by: Justin Kolberg <[email protected]>

---------

Signed-off-by: Justin Kolberg <[email protected]>
Signed-off-by: Sean Porter <[email protected]>
Co-authored-by: Sean Porter <[email protected]>
  • Loading branch information
amdprophet and portertech authored Jul 5, 2023
1 parent be31fa7 commit c7abae7
Show file tree
Hide file tree
Showing 16 changed files with 1,620 additions and 374 deletions.
319 changes: 29 additions & 290 deletions pkg/scripts_test/check.go

Large diffs are not rendered by default.

166 changes: 166 additions & 0 deletions pkg/scripts_test/check_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package sumologic_scripts_tests

import (
"io/fs"
"os"
"path/filepath"
"regexp"
"strings"

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

func checkConfigFilesOwnershipAndPermissions(ownerName string, ownerGroup string) func(c check) {
return func(c check) {
etcPathGlob := filepath.Join(etcPath, "*")
etcPathNestedGlob := filepath.Join(etcPath, "*", "*")

for _, glob := range []string{etcPathGlob, etcPathNestedGlob} {
paths, err := filepath.Glob(glob)
require.NoError(c.test, err)
for _, path := range paths {
var permissions uint32
info, err := os.Stat(path)
require.NoError(c.test, err)
if info.IsDir() {
if path == etcPath {
permissions = etcPathPermissions
} else {
permissions = configPathDirPermissions
}
} else {
switch path {
case configPath:
// /etc/otelcol-sumo/sumologic.yaml
permissions = configPathFilePermissions
case userConfigPath:
// /etc/otelcol-sumo/conf.d/common.yaml
permissions = commonConfigPathFilePermissions
default:
// /etc/otelcol-sumo/conf.d/*
permissions = confDPathFilePermissions
}
}
PathHasPermissions(c.test, path, permissions)
PathHasOwner(c.test, configPath, ownerName, ownerGroup)
}
}
PathHasPermissions(c.test, configPath, configPathFilePermissions)
}
}

func checkDifferentTokenInLaunchdConfig(c check) {
require.NotEmpty(c.test, c.installOptions.installToken, "installation token has not been provided")

conf, err := getLaunchdConfig(launchdPath)
require.NoError(c.test, err)

require.Equal(c.test, "different"+c.installOptions.installToken, conf.EnvironmentVariables.InstallationToken, "installation token is different than expected")
}

func checkGroupExists(c check) {
exists := dsclKeyExistsForPath(c.test, "/Groups", systemGroup)
require.True(c.test, exists, "group has not been created")
}

func checkGroupNotExists(c check) {
exists := dsclKeyExistsForPath(c.test, "/Groups", systemGroup)
require.False(c.test, exists, "group has been created")
}

func checkHostmetricsOwnershipAndPermissions(ownerName string, ownerGroup string) func(c check) {
return func(c check) {
PathHasOwner(c.test, hostmetricsConfigPath, ownerName, ownerGroup)
PathHasPermissions(c.test, hostmetricsConfigPath, confDPathFilePermissions)
}
}

func checkLaunchdConfigCreated(c check) {
require.FileExists(c.test, launchdPath, "launchd configuration has not been created properly")
}

func checkLaunchdConfigNotCreated(c check) {
require.NoFileExists(c.test, launchdPath, "launchd configuration has been created")
}

func checkPackageCreated(c check) {
re, err := regexp.Compile("Package downloaded to: .*/otelcol-sumo.pkg")
require.NoError(c.test, err)

matchedLine := ""
for _, line := range c.output {
if re.MatchString(line) {
matchedLine = line
}
}
require.NotEmpty(c.test, matchedLine, "package path not in output")

packagePath := strings.TrimPrefix(matchedLine, "Package downloaded to: ")
require.FileExists(c.test, packagePath, "package has not been created")
}

func checkTokenInLaunchdConfig(c check) {
require.NotEmpty(c.test, c.installOptions.installToken, "installation token has not been provided")

conf, err := getLaunchdConfig(launchdPath)
require.NoError(c.test, err)

require.Equal(c.test, c.installOptions.installToken, conf.EnvironmentVariables.InstallationToken, "installation token is different than expected")
}

func checkUserExists(c check) {
exists := dsclKeyExistsForPath(c.test, "/Users", systemUser)
require.True(c.test, exists, "user has not been created")
}

func checkUserNotExists(c check) {
exists := dsclKeyExistsForPath(c.test, "/Users", systemUser)
require.False(c.test, exists, "user has been created")
}

func preActionInstallPackage(c check) {
c.code, c.output, c.errorOutput, c.err = runScript(c)
}

func preActionInstallPackageWithDifferentAPIBaseURL(c check) {
c.installOptions.apiBaseURL = "different" + c.installOptions.apiBaseURL
c.code, c.output, c.errorOutput, c.err = runScript(c)
}

func preActionInstallPackageWithDifferentTags(c check) {
c.installOptions.tags = map[string]string{
"some": "tag",
}
c.code, c.output, c.errorOutput, c.err = runScript(c)
}

func preActionInstallPackageWithNoAPIBaseURL(c check) {
c.installOptions.apiBaseURL = ""
c.code, c.output, c.errorOutput, c.err = runScript(c)
}

func preActionInstallPackageWithNoTags(c check) {
c.installOptions.tags = nil
c.code, c.output, c.errorOutput, c.err = runScript(c)
}

func preActionMockLaunchdConfig(c check) {
f, err := os.Create(launchdPath)
require.NoError(c.test, err)

err = f.Chmod(fs.FileMode(launchdPathFilePermissions))
require.NoError(c.test, err)

conf := NewLaunchdConfig()
err = saveLaunchdConfig(launchdPath, conf)
require.NoError(c.test, err)
}

func preActionWriteDifferentTokenToLaunchdConfig(c check) {
conf, err := getLaunchdConfig(launchdPath)
require.NoError(c.test, err)

conf.EnvironmentVariables.InstallationToken = "different" + c.installOptions.installToken
err = saveLaunchdConfig(launchdPath, conf)
require.NoError(c.test, err)
}
Loading

0 comments on commit c7abae7

Please sign in to comment.