Skip to content

Commit

Permalink
fix lint, e2e test, unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaasman00 committed Jan 30, 2025
1 parent 09cbad2 commit 2dfd7cd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
3 changes: 3 additions & 0 deletions cmd/opampsupervisor/supervisor/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ agent:
OrphanDetectionInterval: DefaultSupervisor().Agent.OrphanDetectionInterval,
ConfigApplyTimeout: DefaultSupervisor().Agent.ConfigApplyTimeout,
BootstrapTimeout: DefaultSupervisor().Agent.BootstrapTimeout,
Signature: DefaultSupervisor().Agent.Signature,
},
Telemetry: DefaultSupervisor().Telemetry,
}
Expand Down Expand Up @@ -625,6 +626,7 @@ telemetry:
HealthCheckPort: 8089,
OpAMPServerPort: 8090,
PassthroughLogs: true,
Signature: DefaultSupervisor().Agent.Signature,
},
Telemetry: Telemetry{
Logs: Logs{
Expand Down Expand Up @@ -659,6 +661,7 @@ agent:
OrphanDetectionInterval: DefaultSupervisor().Agent.OrphanDetectionInterval,
ConfigApplyTimeout: DefaultSupervisor().Agent.ConfigApplyTimeout,
BootstrapTimeout: DefaultSupervisor().Agent.BootstrapTimeout,
Signature: DefaultSupervisor().Agent.Signature,
},
Telemetry: DefaultSupervisor().Telemetry,
}
Expand Down
1 change: 0 additions & 1 deletion cmd/opampsupervisor/supervisor/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

func TestMain(m *testing.M) {

goleak.VerifyTestMain(
m,
// This leaky goroutine seems to come from the cosign dependency tree.
Expand Down
8 changes: 4 additions & 4 deletions cmd/opampsupervisor/supervisor/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (p *packageManager) UpdateContent(ctx context.Context, packageName string,
// Create a backup in case we fail to write the agent
// verify collector backup path is clear
agentBackupPath := filepath.Join(p.storageDir, "collector.bak")
if err := renameFile(p.agentExePath, agentBackupPath); err != nil {
if err = renameFile(p.agentExePath, agentBackupPath); err != nil {
return fmt.Errorf("rename collector exe path to backup path: %w", err)
}

Expand All @@ -226,7 +226,7 @@ func (p *packageManager) UpdateContent(ctx context.Context, packageName string,
}

// open collector destination file
agentFile, err := os.OpenFile(p.agentExePath, os.O_RDWR, 0700)
agentFile, err := os.OpenFile(p.agentExePath, os.O_RDWR|os.O_CREATE, 0o700)
if err != nil {
return fmt.Errorf("open file: %w", err)
}
Expand Down Expand Up @@ -294,7 +294,7 @@ func (p packageManager) SetLastReportedStatuses(statuses *protobufs.PackageStatu
return fmt.Errorf("marshal statuses: %w", err)
}

err = os.WriteFile(p.lastPackageStatusPath(), lastStatusBytes, 0600)
err = os.WriteFile(p.lastPackageStatusPath(), lastStatusBytes, 0o600)
if err != nil {
return fmt.Errorf("write package statues: %w", err)
}
Expand Down Expand Up @@ -399,7 +399,7 @@ func renameFile(srcPath, dstPath string) error {
// verify dstPath is cleared up
if _, err := os.Stat(dstPath); err == nil {
// delete existing file at dstPath
if err := os.Remove(dstPath); err != nil {
if err = os.Remove(dstPath); err != nil {
return fmt.Errorf("remove existing file at destination path: %w", err)
}
} else if !os.IsNotExist(err) {
Expand Down
11 changes: 5 additions & 6 deletions cmd/opampsupervisor/supervisor/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func TestNewPackageManager(t *testing.T) {
storageDir := filepath.Join(tmpDir, "storage")
defaultSigOpts := config.DefaultSupervisor().Agent.Signature

require.NoError(t, os.MkdirAll(storageDir, 0700))
require.NoError(t, os.WriteFile(agentFile, []byte(testAgentFileContents), 0600))
require.NoError(t, os.MkdirAll(storageDir, 0o700))
require.NoError(t, os.WriteFile(agentFile, []byte(testAgentFileContents), 0o600))

pm, err := newPackageManager(agentFile, storageDir, "v0.110.0", &persistentState{}, defaultSigOpts, nil)
require.NoError(t, err)
Expand All @@ -54,7 +54,7 @@ func TestNewPackageManager(t *testing.T) {
storageDir := filepath.Join(tmpDir, "storage")
defaultSigOpts := config.DefaultSupervisor().Agent.Signature

require.NoError(t, os.MkdirAll(storageDir, 0700))
require.NoError(t, os.MkdirAll(storageDir, 0o700))

_, err := newPackageManager(agentFile, storageDir, "v0.110.0", &persistentState{}, defaultSigOpts, nil)
require.ErrorContains(t, err, "open agent:")
Expand All @@ -81,7 +81,6 @@ func TestPackageManager_AllPackagesHash(t *testing.T) {
by, err = pm2.AllPackagesHash()
require.NoError(t, err)
require.Equal(t, allPackagesHash, by)

}

func TestPackageManager_Packages(t *testing.T) {
Expand Down Expand Up @@ -281,8 +280,8 @@ func initPackageManager(t *testing.T, tmpDir string) *packageManager {
storageDir := filepath.Join(tmpDir, "storage")
defaultSigOpts := config.DefaultSupervisor().Agent.Signature

require.NoError(t, os.MkdirAll(storageDir, 0700))
require.NoError(t, os.WriteFile(agentFile, []byte(testAgentFileContents), 0600))
require.NoError(t, os.MkdirAll(storageDir, 0o700))
require.NoError(t, os.WriteFile(agentFile, []byte(testAgentFileContents), 0o600))
ps, err := loadOrCreatePersistentState(filepath.Join(tmpDir, "persistent_state.yaml"))
require.NoError(t, err)

Expand Down
6 changes: 4 additions & 2 deletions cmd/opampsupervisor/supervisor/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ func createNewPersistentState(file string) (*persistentState, error) {
// to/from a hex string.
type hexEncodedBytes []byte

var _ yaml.Marshaler = (*hexEncodedBytes)(nil)
var _ yaml.Unmarshaler = (*hexEncodedBytes)(nil)
var (
_ yaml.Marshaler = (*hexEncodedBytes)(nil)
_ yaml.Unmarshaler = (*hexEncodedBytes)(nil)
)

func (h hexEncodedBytes) MarshalYAML() (any, error) {
return hex.EncodeToString(h), nil
Expand Down

0 comments on commit 2dfd7cd

Please sign in to comment.