-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into i256-pgsidecar--wip
- Loading branch information
Showing
10 changed files
with
267 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 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,80 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/oneconcern/datamon/pkg/core" | ||
|
||
"github.com/spf13/cobra" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
var GetBundleCommand = &cobra.Command{ | ||
Use: "get", | ||
Short: "Get bundle info by id", | ||
Long: `Performs a direct lookup of labels by id. | ||
Prints corresponding bundle information if the label exists, | ||
exits with ENOENT status otherwise.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
ctx := context.Background() | ||
remoteStores, err := paramsToRemoteCmdStores(ctx, params) | ||
if err != nil { | ||
logFatalln(err) | ||
return | ||
} | ||
|
||
err = setLatestOrLabelledBundle(ctx, remoteStores.meta) | ||
if err == core.ErrNotFound { | ||
fmt.Fprintf(os.Stderr, "didn't find label %q\n", params.label.Name) | ||
osExit(int(unix.ENOENT)) | ||
return | ||
} | ||
if err != nil { | ||
logFatalln(err) | ||
return | ||
} | ||
bundle := core.New(core.NewBDescriptor(), | ||
core.Repo(params.repo.RepoName), | ||
core.MetaStore(remoteStores.meta), | ||
core.BundleID(params.bundle.ID), | ||
) | ||
|
||
err = core.DownloadMetadata(ctx, bundle) | ||
if err == core.ErrNotFound { | ||
fmt.Fprintf(os.Stderr, "didn't find bundle '%v'\n", params.bundle.ID) | ||
osExit(int(unix.ENOENT)) | ||
return | ||
} | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
logFatalf("error downloading bundle information\n") | ||
} | ||
|
||
var buf bytes.Buffer | ||
err = bundleDescriptorTemplate.Execute(&buf, bundle.BundleDescriptor) | ||
if err != nil { | ||
log.Println("executing template:", err) | ||
} | ||
log.Println(buf.String()) | ||
}, | ||
} | ||
|
||
func init() { | ||
requiredFlags := []string{addRepoNameOptionFlag(GetBundleCommand)} | ||
|
||
addBundleFlag(GetBundleCommand) | ||
addLabelNameFlag(GetBundleCommand) | ||
|
||
for _, flag := range requiredFlags { | ||
err := GetBundleCommand.MarkFlagRequired(flag) | ||
if err != nil { | ||
logFatalln(err) | ||
} | ||
} | ||
|
||
bundleCmd.AddCommand(GetBundleCommand) | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -342,6 +342,29 @@ func TestRepoList(t *testing.T) { | |
require.True(t, testNow.Sub(ll[1].time).Seconds() < 3, "second timestamp bounds after second create") | ||
} | ||
|
||
func TestGetRepo(t *testing.T) { | ||
cleanup := setupTests(t) | ||
defer cleanup() | ||
repoName := internal.RandStringBytesMaskImprSrc(8) | ||
runCmd(t, []string{"repo", | ||
"get", | ||
"--repo", repoName, | ||
}, "attempt get non-exist repo", true) | ||
require.Equal(t, int(unix.ENOENT), exitMocks.exitStatuses[len(exitMocks.exitStatuses)-1], | ||
"ENOENT on nonexistant label") | ||
runCmd(t, []string{"repo", | ||
"create", | ||
"--description", "testing", | ||
"--repo", repoName, | ||
"--name", "tests", | ||
"--email", "[email protected]", | ||
}, "create second test repo", false) | ||
runCmd(t, []string{"repo", | ||
"get", | ||
"--repo", repoName, | ||
}, "get repo", false) | ||
} | ||
|
||
func testUploadBundle(t *testing.T, file uploadTree) { | ||
r, w, err := os.Pipe() | ||
if err != nil { | ||
|
@@ -564,6 +587,41 @@ func TestListBundles(t *testing.T) { | |
} | ||
} | ||
|
||
func TestGetBundle(t *testing.T) { | ||
cleanup := setupTests(t) | ||
defer cleanup() | ||
runCmd(t, []string{"repo", | ||
"create", | ||
"--description", "testing", | ||
"--repo", repo1, | ||
"--name", "tests", | ||
"--email", "[email protected]", | ||
}, "create second test repo", false) | ||
label := internal.RandStringBytesMaskImprSrc(8) | ||
runCmd(t, []string{"bundle", | ||
"get", | ||
"--repo", repo1, | ||
"--label", label, | ||
}, "attempt get non-exist bundle", true) | ||
require.Equal(t, int(unix.ENOENT), exitMocks.exitStatuses[len(exitMocks.exitStatuses)-1], | ||
"ENOENT on nonexistant bundle") | ||
files := testUploadTrees[0] | ||
file := files[0] | ||
runCmd(t, []string{"bundle", | ||
"upload", | ||
"--path", dirPathStr(t, file), | ||
"--message", "label test bundle", | ||
"--repo", repo1, | ||
"--label", label, | ||
"--concurrency-factor", concurrencyFactor, | ||
}, "upload bundle at "+dirPathStr(t, file), false) | ||
runCmd(t, []string{"bundle", | ||
"get", | ||
"--repo", repo1, | ||
"--label", label, | ||
}, "get bundle", false) | ||
} | ||
|
||
func TestGetLabel(t *testing.T) { | ||
cleanup := setupTests(t) | ||
defer cleanup() | ||
|
@@ -579,7 +637,7 @@ func TestGetLabel(t *testing.T) { | |
"get", | ||
"--repo", repo1, | ||
"--label", label, | ||
}, "list labels", true) | ||
}, "attempt get non-exist label", true) | ||
require.Equal(t, int(unix.ENOENT), exitMocks.exitStatuses[len(exitMocks.exitStatuses)-1], | ||
"ENOENT on nonexistant label") | ||
files := testUploadTrees[0] | ||
|
@@ -596,7 +654,7 @@ func TestGetLabel(t *testing.T) { | |
"get", | ||
"--repo", repo1, | ||
"--label", label, | ||
}, "list labels", false) | ||
}, "get label", false) | ||
} | ||
|
||
type labelListEntry struct { | ||
|
This file contains 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 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,59 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/oneconcern/datamon/pkg/core" | ||
|
||
"github.com/spf13/cobra" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
var GetRepoCommand = &cobra.Command{ | ||
Use: "get", | ||
Short: "Get repo info by name", | ||
Long: `Performs a direct lookup of repos by name. | ||
Prints corresponding repo information if the name exists, | ||
exits with ENOENT status otherwise.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
ctx := context.Background() | ||
remoteStores, err := paramsToRemoteCmdStores(ctx, params) | ||
if err != nil { | ||
logFatalln(err) | ||
} | ||
repoDescriptor, err := core.GetRepoDescriptorByRepoName( | ||
remoteStores.meta, params.repo.RepoName) | ||
if err == core.ErrNotFound { | ||
fmt.Fprintf(os.Stderr, "didn't find repo '%v'\n", params.repo.RepoName) | ||
osExit(int(unix.ENOENT)) | ||
return | ||
} | ||
if err != nil { | ||
logFatalf("error downloading repo information: %v\n", err) | ||
} | ||
|
||
var buf bytes.Buffer | ||
err = repoDescriptorTemplate.Execute(&buf, repoDescriptor) | ||
if err != nil { | ||
log.Println("executing template:", err) | ||
} | ||
log.Println(buf.String()) | ||
}, | ||
} | ||
|
||
func init() { | ||
requiredFlags := []string{addRepoNameOptionFlag(GetRepoCommand)} | ||
|
||
for _, flag := range requiredFlags { | ||
err := GetRepoCommand.MarkFlagRequired(flag) | ||
if err != nil { | ||
logFatalln(err) | ||
} | ||
} | ||
|
||
repoCmd.AddCommand(GetRepoCommand) | ||
} |
This file contains 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 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 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
Oops, something went wrong.