Skip to content

Commit

Permalink
chore(cmd/influx/write): add test for influx write
Browse files Browse the repository at this point in the history
  • Loading branch information
sranka committed Apr 9, 2020
1 parent 64c61b9 commit 9a71054
Show file tree
Hide file tree
Showing 2 changed files with 420 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cmd/influx/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (writeFlags *writeFlagsType) dump(args []string) {
}

// createLineReader uses writeFlags and cli arguments to create a reader that produces line protocol
func (writeFlags *writeFlagsType) createLineReader(args []string) (io.Reader, io.Closer, error) {
func (writeFlags *writeFlagsType) createLineReader(cmd *cobra.Command, args []string) (io.Reader, io.Closer, error) {
readers := make([]io.Reader, 0, 2*len(writeFlags.Headers)+2*len(writeFlags.Files)+1)
closers := make([]io.Closer, 0, len(writeFlags.Files))

Expand Down Expand Up @@ -149,11 +149,11 @@ func (writeFlags *writeFlagsType) createLineReader(args []string) (io.Reader, io
case len(args) == 0:
// either --file or stdin when no arguments are supplied
if len(writeFlags.Files) == 0 {
readers = append(readers, decode(os.Stdin))
readers = append(readers, decode(cmd.InOrStdin()))
}
case args[0] == "-":
// "-" also means stdin
readers = append(readers, decode(os.Stdin))
readers = append(readers, decode(cmd.InOrStdin()))
default:
readers = append(readers, strings.NewReader(args[0]))
}
Expand Down Expand Up @@ -243,7 +243,7 @@ func fluxWriteF(cmd *cobra.Command, args []string) error {
bucketID, orgID := buckets[0].ID, buckets[0].OrgID

// create line reader
r, closer, err := writeFlags.createLineReader(args)
r, closer, err := writeFlags.createLineReader(cmd, args)
if closer != nil {
defer closer.Close()
}
Expand Down Expand Up @@ -271,15 +271,15 @@ func fluxWriteF(cmd *cobra.Command, args []string) error {
func fluxWriteDryrunF(cmd *cobra.Command, args []string) error {
writeFlags.dump(args) // print flags when in Debug mode
// create line reader
r, closer, err := writeFlags.createLineReader(args)
r, closer, err := writeFlags.createLineReader(cmd, args)
if closer != nil {
defer closer.Close()
}
if err != nil {
return err
}
// dry run
_, err = io.Copy(os.Stdout, r)
_, err = io.Copy(cmd.OutOrStdout(), r)
if err != nil {
return fmt.Errorf("failed: %v", err)
}
Expand Down
Loading

0 comments on commit 9a71054

Please sign in to comment.