Skip to content

Conversation

@fmartingr
Copy link
Contributor

Add testing infrastructure and user synchronization:

  • E2E and integration test framework with testhelper package

    func TestSlackImportE2E(t *testing.T) {
         // Setup: Automatically creates Docker containers (network, PostgreSQL, Mattermost)
         th := testhelper.SetupHelper(t)
         defer th.TearDown()
         
         // th.Client is authenticated API client
         // th.SiteURL is the running Mattermost URL
         // th.AdminUser is the admin account
         
         // Create a team
         team, _, err := th.Client.CreateTeam(&model.Team{
             Name:        "myteam",
             DisplayName: "My Team",
             Type:        model.TeamOpen,
         })
         require.NoError(t, err)
         
         // Import data and verify it worked
         err = th.ImportJSONL("path/to/import.jsonl")
         require.NoError(t, err)
         
         // Validate imported users exist
         validation := th.ValidateImportedUsers([]string{"john.doe", "jane.smith"})
         assert.True(t, validation.Valid)
     }
  • Slack export fixtures and validation utilities

// Build a Slack export programmatically using fluent API
err := slack.NewSlackExportBuilder().
    AddUser(slack.SlackUser{
        Id:       "U001",
        Username: "john.doe",
        Profile: slack.SlackProfile{
            RealName: "John Doe",
            Email:    "john@example.com",
            Title:    "Engineer",
        },
    }).
    AddUser(slack.SlackUser{
        Id:       "U002",
        Username: "jane.smith",
        Profile: slack.SlackProfile{
            Email: "jane@example.com",
        },
    }).
    AddChannel(slack.SlackChannel{
        Id:      "C001",
        Name:    "general",
        Creator: "U001",
        Members: []string{"U001", "U002"},
        Purpose: slack.SlackChannelSub{Value: "General discussion"},
        Topic:   slack.SlackChannelSub{Value: "Welcome!"},
    }).
    AddPost("general", slack.SlackPost{
        User:      "U001",
        Text:      "Hello world!",
        Timestamp: "1577836800.000100",
        Type:      "message",
    }).
    AddPost("general", slack.SlackPost{
        User:      "U002",
        Text:      "Hi everyone!",
        Timestamp: "1577836801.000200",
        Type:      "message",
    }).
    Build(exportPath)

- Introduced new data structures for Slack import lines, including channels, users, and posts.
- Implemented functions to create and validate Slack export ZIP files.
- Added comprehensive integration tests for transforming Slack exports into Mattermost imports, ensuring data integrity and structure.
- Enhanced test helper functions for better setup and verification of Slack export scenarios.
- Added validation checks for channel creators and members to ensure they reference existing users.
- Introduced a SkipValidation method to allow building exports with inconsistent data for testing purposes.
- Renamed integration test functions for clarity and consistency.
- Improved test descriptions to better reflect the functionality being tested.
- Added validation for import files, ensuring correct structure and data integrity.
- Introduced new helper functions for validating import files and handling JSONL data.
- Enhanced test coverage for user and channel imports, including edge cases for missing fields and references.
- Updated search functions to use index-based access for better performance and clarity.
- Modified file opening logic in SyncImportUsers to truncate the output file if it already exists.
- Added a check to prevent processing if the channels slice is nil, enhancing robustness.
- Updated CreateMattermostContainer to return the container object for better management.
- Improved environment variable configuration for Mattermost container, enabling local mode and socket location.
- Refactored ImportBulkData to utilize the mmctl binary for importing JSONL files, enhancing import accuracy and reliability.
- Added job status polling for import processes to ensure completion and error handling.
- Streamlined error handling and logging for better debugging during import operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants