make store a struct and add tests

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-03-25 15:17:35 -07:00
committed by Solomon Hykes
parent 524f77df65
commit 9fec69f3a0
8 changed files with 85 additions and 49 deletions

View File

@@ -22,11 +22,11 @@ var downCmd = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {
lg := logger.New()
// nolint:staticcheck
ctx := lg.WithContext(cmd.Context())
store := dagger.DefaultStore()
routeName := getRouteName(lg, cmd)
route, err := dagger.LookupRoute(ctx, routeName, nil)
route, err := store.LookupRoute(ctx, routeName, nil)
if err != nil {
lg.Fatal().Err(err).Str("route-name", routeName).Msg("failed to lookup route")
}

View File

@@ -23,8 +23,9 @@ var listCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
lg := logger.New()
ctx := lg.WithContext(cmd.Context())
store := dagger.DefaultStore()
routes, err := dagger.ListRoutes(ctx)
routes, err := store.ListRoutes(ctx)
if err != nil {
lg.Fatal().Err(err).Msg("cannot list routes")
}

View File

@@ -22,18 +22,17 @@ var newCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
lg := logger.New()
ctx := lg.WithContext(cmd.Context())
store := dagger.DefaultStore()
// nolint:staticcheck
upRouteFlag, err := cmd.Flags().GetBool("up")
if err != nil {
lg.Fatal().Err(err).Str("flag", "up").Msg("unable to resolve flag")
}
// nolint:staticcheck
routeName := getRouteName(lg, cmd)
// TODO: Implement options: --layout-*, --setup
route, err := dagger.CreateRoute(ctx, routeName, nil)
route, err := store.CreateRoute(ctx, routeName, nil)
if err != nil {
lg.Fatal().Err(err).Msg("failed to create route")
}

View File

@@ -23,11 +23,11 @@ var queryCmd = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {
lg := logger.New()
// nolint:staticcheck
ctx := lg.WithContext(cmd.Context())
store := dagger.DefaultStore()
routeName := getRouteName(lg, cmd)
route, err := dagger.LookupRoute(ctx, routeName, nil)
route, err := store.LookupRoute(ctx, routeName, nil)
if err != nil {
lg.Fatal().Err(err).Str("route-name", routeName).Msg("failed to lookup route")
}

View File

@@ -22,11 +22,11 @@ var upCmd = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {
lg := logger.New()
// nolint:staticcheck
ctx := lg.WithContext(cmd.Context())
store := dagger.DefaultStore()
routeName := getRouteName(lg, cmd)
route, err := dagger.LookupRoute(ctx, routeName, nil)
route, err := store.LookupRoute(ctx, routeName, nil)
if err != nil {
lg.Fatal().Err(err).Str("route-name", routeName).Msg("failed to lookup route")
}