add script boilerplate for mock data generation (#1161)

## Description

Introduces a `factory` script to help devs generate
fake m365 data in bulk for testing purposes.  Only
boilerplate at this time.  Any TODO's or not-yet-
implemented statuses are present as placeholders
alone, without official deadlines.

## Type of change

- [x] 🤖 Test

## Issue(s)

* #902

## Test Plan

- [x] 💪 Manual
This commit is contained in:
Keepers 2022-10-14 11:19:40 -06:00 committed by GitHub
parent 65d6780906
commit 39f9c7f50f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 181 additions and 0 deletions

View File

@ -0,0 +1,71 @@
package main
import (
"github.com/spf13/cobra"
. "github.com/alcionai/corso/src/cli/print"
"github.com/alcionai/corso/src/cli/utils"
)
var (
emailsCmd = &cobra.Command{
Use: "emails",
Short: "Generate exchange emails",
RunE: handleExchangeEmailFactory,
}
eventsCmd = &cobra.Command{
Use: "events",
Short: "Generate exchange calendar events",
RunE: handleExchangeCalendarEventFactory,
}
contactsCmd = &cobra.Command{
Use: "contacts",
Short: "Generate exchange contacts",
RunE: handleExchangeContactFactory,
}
)
func addExchangeCommands(parent *cobra.Command) {
parent.AddCommand(emailsCmd)
parent.AddCommand(eventsCmd)
parent.AddCommand(contactsCmd)
}
func handleExchangeEmailFactory(cmd *cobra.Command, args []string) error {
Err(cmd.Context(), ErrNotYetImplemeted)
if utils.HasNoFlagsAndShownHelp(cmd) {
return nil
}
// generate mocked emails
return nil
}
func handleExchangeCalendarEventFactory(cmd *cobra.Command, args []string) error {
Err(cmd.Context(), ErrNotYetImplemeted)
if utils.HasNoFlagsAndShownHelp(cmd) {
return nil
}
// generate mocked events
return nil
}
func handleExchangeContactFactory(cmd *cobra.Command, args []string) error {
//nolint
Err(cmd.Context(), ErrNotYetImplemeted)
if utils.HasNoFlagsAndShownHelp(cmd) {
return nil
}
// generate mocked contacts
return nil
}

View File

@ -0,0 +1,82 @@
package main
import (
"context"
"os"
"github.com/pkg/errors"
"github.com/spf13/cobra"
. "github.com/alcionai/corso/src/cli/print"
)
var factoryCmd = &cobra.Command{
Use: "factory",
Short: "Generate all types of m365 folders",
RunE: handleFactoryRoot,
}
var exchangeCmd = &cobra.Command{
Use: "exchange",
Short: "Generate exchange data",
RunE: handleExchangeFactory,
}
var oneDriveCmd = &cobra.Command{
Use: "onedrive",
Short: "Generate onedrive data",
RunE: handleOneDriveFactory,
}
var (
count int
container string
tenant string
user string
)
// TODO: ErrGenerating = errors.New("not all items were successfully generated")
var ErrNotYetImplemeted = errors.New("not yet implemented")
// ------------------------------------------------------------------------------------------
// CLI command handlers
// ------------------------------------------------------------------------------------------
func main() {
ctx := SetRootCmd(context.Background(), factoryCmd)
// persistent flags that are common to all use cases
fs := factoryCmd.PersistentFlags()
fs.StringVar(&tenant, "tenant", "", "m365 tenant containing the user")
fs.StringVar(&user, "user", "", "m365 user owning the new data")
cobra.CheckErr(factoryCmd.MarkPersistentFlagRequired("user"))
fs.IntVar(&count, "count", 0, "count of items to produce")
cobra.CheckErr(factoryCmd.MarkPersistentFlagRequired("count"))
fs.StringVar(&container, "container", "", "container location of the new data (will create as needed)")
cobra.CheckErr(factoryCmd.MarkPersistentFlagRequired("container"))
factoryCmd.AddCommand(exchangeCmd)
addExchangeCommands(exchangeCmd)
factoryCmd.AddCommand(oneDriveCmd)
addOneDriveCommands(oneDriveCmd)
if err := factoryCmd.ExecuteContext(ctx); err != nil {
os.Exit(1)
}
}
func handleFactoryRoot(cmd *cobra.Command, args []string) error {
Err(cmd.Context(), ErrNotYetImplemeted)
return cmd.Help()
}
func handleExchangeFactory(cmd *cobra.Command, args []string) error {
Err(cmd.Context(), ErrNotYetImplemeted)
return cmd.Help()
}
func handleOneDriveFactory(cmd *cobra.Command, args []string) error {
Err(cmd.Context(), ErrNotYetImplemeted)
return cmd.Help()
}

View File

@ -0,0 +1,28 @@
package main
import (
"github.com/spf13/cobra"
. "github.com/alcionai/corso/src/cli/print"
"github.com/alcionai/corso/src/cli/utils"
)
var filesCmd = &cobra.Command{
Use: "files",
Short: "Generate OneDrive files",
RunE: handleOneDriveFileFactory,
}
func addOneDriveCommands(parent *cobra.Command) {
parent.AddCommand(filesCmd)
}
func handleOneDriveFileFactory(cmd *cobra.Command, args []string) error {
Err(cmd.Context(), ErrNotYetImplemeted)
if utils.HasNoFlagsAndShownHelp(cmd) {
return nil
}
return nil
}