diff --git a/pkg/cmd/roachprod/ssh/BUILD.bazel b/pkg/cmd/roachprod/ssh/BUILD.bazel index 72504464df19..937134bf678c 100644 --- a/pkg/cmd/roachprod/ssh/BUILD.bazel +++ b/pkg/cmd/roachprod/ssh/BUILD.bazel @@ -1,11 +1,17 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "ssh", srcs = [ + "io.go", "shell.go", - "ssh.go", ], importpath = "github.com/cockroachdb/cockroach/pkg/cmd/roachprod/ssh", visibility = ["//visibility:public"], ) + +go_test( + name = "ssh_test", + srcs = ["io_test.go"], + embed = [":ssh"], +) diff --git a/pkg/cmd/roachprod/ssh/ssh.go b/pkg/cmd/roachprod/ssh/io.go similarity index 100% rename from pkg/cmd/roachprod/ssh/ssh.go rename to pkg/cmd/roachprod/ssh/io.go diff --git a/pkg/cmd/roachprod/ssh/io_test.go b/pkg/cmd/roachprod/ssh/io_test.go new file mode 100644 index 000000000000..c863aa6e25e5 --- /dev/null +++ b/pkg/cmd/roachprod/ssh/io_test.go @@ -0,0 +1,49 @@ +// Copyright 2018 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package ssh + +import ( + "io/ioutil" + "testing" +) + +func TestProgress(t *testing.T) { + output, err := ioutil.TempFile("", "example*") + if err != nil { + t.Fatal(err) + } + defer output.Close() + + b := make([]byte, 10) + var percent float64 + writer := &ProgressWriter{ + Writer: output, + Done: 0, + Total: 50, + Progress: func(currentProgress float64) { + percent = currentProgress + }, + } + for i := 0; i < 4; i++ { + if _, err := writer.Write(b); err != nil { + t.Fatal(err) + } + } + if percent != 0.8 { + t.Errorf("expected progress of 80%% but got %.2f", percent*100) + } + if _, err := writer.Write(b); err != nil { + t.Fatal(err) + } + if percent != 1.0 { + t.Errorf("expected progress of 100%% but got %.2f", percent*100) + } +}