KhaninArtur commented on a change in pull request #16855:
URL: https://github.com/apache/beam/pull/16855#discussion_r810914328
##########
File path: playground/backend/internal/preparers/python_preparers_test.go
##########
@@ -101,3 +95,129 @@ func Test_addCodeToFile(t *testing.T) {
})
}
}
+
+func Test_saveLogs(t *testing.T) {
+ file, _ := os.Open(correctPyFile)
+ tmp, _ := utils.CreateTempFile(correctPyFile)
+ defer tmp.Close()
+
+ type args struct {
+ from *os.File
+ to *os.File
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ // Call saveLogs method to add logs code to tmp file.
+ name: "Save logs successfully",
+ args: args{
+ from: file,
+ to: tmp,
+ },
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if err := saveLogs(tt.args.from, tt.args.to); (err !=
nil) != tt.wantErr {
+ t.Errorf("saveLogs() error = %v, wantErr %v",
err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func Test_writeToFile(t *testing.T) {
+ tmp, _ := utils.CreateTempFile(correctPyFile)
+ defer tmp.Close()
+ tmp2, _ := os.OpenFile(incorrectPyFile, os.O_CREATE, 0)
+ defer tmp2.Close()
+
+ type args struct {
+ to *os.File
+ str string
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ // Call writeToFile method to successfully add line to
tmp file.
+ name: "Successfully write to file",
+ args: args{
+ to: tmp,
+ str: "just a string",
+ },
+ wantErr: false,
+ },
+ {
+ // Call writeToFile method to write to tmp file which
is open only for reading.
+ // As a result, want to receive error.
+ name: "Write to file which is read-only",
Review comment:
Let's also add a negative test case when we try to write to a
non-existing file.
##########
File path: playground/backend/internal/preparers/python_preparers_test.go
##########
@@ -101,3 +95,129 @@ func Test_addCodeToFile(t *testing.T) {
})
}
}
+
+func Test_saveLogs(t *testing.T) {
+ file, _ := os.Open(correctPyFile)
+ tmp, _ := utils.CreateTempFile(correctPyFile)
+ defer tmp.Close()
+
+ type args struct {
+ from *os.File
+ to *os.File
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ // Call saveLogs method to add logs code to tmp file.
+ name: "Save logs successfully",
Review comment:
Let's also add a negative test case when we try to save logs to a
non-existing file.
##########
File path: playground/backend/internal/preparers/python_preparers_test.go
##########
@@ -101,3 +95,129 @@ func Test_addCodeToFile(t *testing.T) {
})
}
}
+
+func Test_saveLogs(t *testing.T) {
+ file, _ := os.Open(correctPyFile)
+ tmp, _ := utils.CreateTempFile(correctPyFile)
+ defer tmp.Close()
+
+ type args struct {
+ from *os.File
+ to *os.File
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ // Call saveLogs method to add logs code to tmp file.
+ name: "Save logs successfully",
+ args: args{
+ from: file,
+ to: tmp,
+ },
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if err := saveLogs(tt.args.from, tt.args.to); (err !=
nil) != tt.wantErr {
+ t.Errorf("saveLogs() error = %v, wantErr %v",
err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func Test_writeToFile(t *testing.T) {
+ tmp, _ := utils.CreateTempFile(correctPyFile)
+ defer tmp.Close()
+ tmp2, _ := os.OpenFile(incorrectPyFile, os.O_CREATE, 0)
+ defer tmp2.Close()
+
+ type args struct {
+ to *os.File
+ str string
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ // Call writeToFile method to successfully add line to
tmp file.
+ name: "Successfully write to file",
+ args: args{
+ to: tmp,
+ str: "just a string",
+ },
+ wantErr: false,
+ },
+ {
+ // Call writeToFile method to write to tmp file which
is open only for reading.
+ // As a result, want to receive error.
+ name: "Write to file which is read-only",
+ args: args{
+ to: tmp2,
+ str: "just a string",
+ },
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if err := writeToFile(tt.args.to, tt.args.str); (err !=
nil) != tt.wantErr {
+ t.Errorf("writeToFile() error = %v, wantErr
%v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func Test_saveGraph(t *testing.T) {
+ file, _ := os.Open(pyGraphFile)
+ noPipelineFile, _ := os.Open(correctPyFile)
+ tmp, _ := utils.CreateTempFile(pyGraphFile)
+ defer tmp.Close()
+ type args struct {
+ from *os.File
+ tempFile *os.File
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ wantGraph bool
+ }{
+ {
+ // Call saveGraph method to add code (to tmp file)
which will save graph to file.
+ name: "Successfully save graph",
+ args: args{
+ from: file,
+ tempFile: tmp,
+ },
+ wantErr: false,
+ wantGraph: true,
+ },
+ {
+ // There is no pipeline definition at the code and no
graph code will be added.
Review comment:
Let's also add a negative test case when we try to save graph to a
non-existing file.
##########
File path: playground/backend/internal/preparers/scio_preparers_test.go
##########
@@ -13,39 +13,33 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package utils
+package preparers
import "testing"
-func TestSpacesToEqualsOption(t *testing.T) {
+func TestGetScioPreparers(t *testing.T) {
type args struct {
- pipelineOptions string
+ filePath string
}
tests := []struct {
name string
args args
- want string
+ want int
}{
{
- name: "args is empty string",
- args: args{pipelineOptions: ""},
- want: "",
- },
- {
- name: "args with one option",
- args: args{pipelineOptions: "--opt1 valOpt"},
- want: "--opt1=valOpt",
- },
- {
- name: "args with some options",
- args: args{pipelineOptions: "--opt1 valOpt --opt2
valOpt --opt3 valOpt"},
- want: "--opt1=valOpt --opt2=valOpt --opt3=valOpt",
+ // Test case with calling GetPythonPreparers method.
+ // As a result, want to receive slice of preparers with
len = 1
+ name: "get python preparers",
Review comment:
Do you mean SCIO prepares instead of Python?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]