Skip to content

Check version command output #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,4 @@ jobs:
secrets: inherit
permissions:
contents: write
pull-requests: write
pull-requests: write
23 changes: 23 additions & 0 deletions test/integration/install/install_uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ func TestAgentManualInstallUninstall(t *testing.T) {
assert.NoError(t, err)
}

replacer := strings.NewReplacer("nginx-agent-", "v", "SNAPSHOT-", "")
packageVersion := replacer.Replace(os.Getenv("PACKAGE_NAME"))

expectedVersionOutput := fmt.Sprintf("nginx-agent version %s", packageVersion)

// Check agent version command output
versionOutput, err := checkAgentVersion(ctx, testContainer)
assert.Equal(t, expectedVersionOutput, versionOutput)

uninstallLog, err := uninstallAgent(ctx, testContainer, osReleaseContent)
require.NoError(t, err)

Expand Down Expand Up @@ -193,8 +202,22 @@ func createUninstallCommand(osReleaseContent string) []string {
}
}

func checkAgentVersion(ctx context.Context, container *testcontainers.DockerContainer) (string, error) {
exitCode, cmdOut, err := container.Exec(ctx, []string{"nginx-agent", "--version"})
if err != nil {
return "", fmt.Errorf("failed to check agent version: %v", err)
}
stdoutStderr, _ := io.ReadAll(cmdOut)
if exitCode != 0 {
return "", fmt.Errorf("expected error code of 0 from cmd got: %v\n %s", exitCode, stdoutStderr)
}

return strings.Trim(string(stdoutStderr), "%\x00\x01\n"), nil
}

func nginxIsRunning(ctx context.Context, container *testcontainers.DockerContainer) bool {
exitCode, _, err := container.Exec(ctx, []string{"pgrep", "nginx"})

if err != nil || exitCode != 0 {
return false
}
Expand Down
Loading