-
Notifications
You must be signed in to change notification settings - Fork 51
Support multi user profile build-info collection #360
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| package build | ||
|
|
||
| import ( | ||
| "os" | ||
| "os/user" | ||
| "path/filepath" | ||
| "runtime" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestResolveUserSpecificBuildDirName(t *testing.T) { | ||
|
|
||
| // in windows temporary directories are per-user basis already | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("Skipping on Windows") | ||
| } | ||
| result := resolveUserSpecificBuildDirName() | ||
|
|
||
| // Should contain "jfrog-" prefix | ||
| assert.True(t, strings.Contains(result, BuildsJfrogPath), "Expected path to contain '%s', got: %s", BuildsJfrogPath, result) | ||
|
|
||
| // Should contain "builds" directory | ||
| assert.True(t, strings.Contains(result, BuildsDirPath), "Expected path to contain '%s', got: %s", BuildsDirPath, result) | ||
|
|
||
| // Should have format: jfrog-<username>/builds | ||
| parts := strings.Split(result, string(filepath.Separator)) | ||
| // Handle both forward and backslash separators | ||
| if len(parts) == 1 { | ||
| parts = strings.Split(result, "/") | ||
| } | ||
| assert.Equal(t, 2, len(parts), "Expected 2 path components, got: %v", parts) | ||
| assert.True(t, strings.HasPrefix(parts[0], BuildsJfrogPath), "First component should start with '%s', got: %s", BuildsJfrogPath, parts[0]) | ||
| assert.Equal(t, BuildsDirPath, parts[1], "Second component should be '%s', got: %s", BuildsDirPath, parts[1]) | ||
| } | ||
|
|
||
| func TestResolveUserSpecificBuildDirNameContainsUsername(t *testing.T) { | ||
| currentUser, err := user.Current() | ||
| require.NoError(t, err, "Failed to get current user") | ||
|
|
||
| result := resolveUserSpecificBuildDirName() | ||
|
|
||
| // The path should contain the current username | ||
| expectedPrefix := BuildsJfrogPath + currentUser.Username | ||
| assert.True(t, strings.Contains(result, expectedPrefix), | ||
| "Expected path to contain '%s', got: %s", expectedPrefix, result) | ||
| } | ||
|
|
||
| func TestNewBuildInfoService(t *testing.T) { | ||
| service := NewBuildInfoService() | ||
|
|
||
| // Service should not be nil | ||
| require.NotNil(t, service, "NewBuildInfoService should not return nil") | ||
|
|
||
| // tempDirPath should be set | ||
| assert.NotEmpty(t, service.tempDirPath, "tempDirPath should not be empty") | ||
|
|
||
| // tempDirPath should start with OS temp directory | ||
| assert.True(t, strings.HasPrefix(service.tempDirPath, os.TempDir()), | ||
| "tempDirPath should start with OS temp dir. Got: %s, Expected prefix: %s", | ||
| service.tempDirPath, os.TempDir()) | ||
|
|
||
| // tempDirPath should contain user-specific directory | ||
| assert.True(t, strings.Contains(service.tempDirPath, BuildsJfrogPath), | ||
| "tempDirPath should contain '%s', got: %s", BuildsJfrogPath, service.tempDirPath) | ||
|
|
||
| // buildDirectory should be set | ||
| assert.NotEmpty(t, service.buildDirectory, "buildDirectory should not be empty") | ||
| } | ||
|
|
||
| func TestGetUserSpecificBuildDirName(t *testing.T) { | ||
| service := NewBuildInfoService() | ||
|
|
||
| dirName := service.GetUserSpecificBuildDirName() | ||
|
|
||
| // Should not be empty | ||
| assert.NotEmpty(t, dirName, "GetUserSpecificBuildDirName should not return empty string") | ||
|
|
||
| // Should match the expected format | ||
| assert.True(t, strings.HasPrefix(dirName, BuildsJfrogPath), | ||
| "Directory name should start with '%s', got: %s", BuildsJfrogPath, dirName) | ||
| assert.True(t, strings.HasSuffix(dirName, BuildsDirPath), | ||
| "Directory name should end with '%s', got: %s", BuildsDirPath, dirName) | ||
| } | ||
|
|
||
| func TestGetUserSpecificBuildDirNameLazyInit(t *testing.T) { | ||
| // Create service with empty buildDirectory to test lazy initialization | ||
| service := &BuildInfoService{ | ||
| tempDirPath: "/tmp/test", | ||
| buildDirectory: "", // Empty to trigger lazy init | ||
| } | ||
|
|
||
| dirName := service.GetUserSpecificBuildDirName() | ||
|
|
||
| // Should initialize and return valid directory name | ||
| assert.NotEmpty(t, dirName, "GetUserSpecificBuildDirName should initialize if empty") | ||
| assert.True(t, strings.HasPrefix(dirName, BuildsJfrogPath), | ||
| "Lazily initialized directory should start with '%s', got: %s", BuildsJfrogPath, dirName) | ||
|
|
||
| // Should also update the service's buildDirectory field | ||
| assert.Equal(t, dirName, service.buildDirectory, | ||
| "buildDirectory field should be updated after lazy init") | ||
| } | ||
|
|
||
| func TestMultipleUsersGetDifferentPaths(t *testing.T) { | ||
| // This test verifies that the path includes a user identifier | ||
| // that would be different for different users | ||
| service := NewBuildInfoService() | ||
|
|
||
| path := service.tempDirPath | ||
|
|
||
| // Path should contain username component | ||
| currentUser, err := user.Current() | ||
| require.NoError(t, err) | ||
|
|
||
| expectedUserDir := BuildsJfrogPath + currentUser.Username | ||
| assert.True(t, strings.Contains(path, expectedUserDir), | ||
| "Path should contain user-specific directory '%s', got: %s", expectedUserDir, path) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.