Skip to content

Commit

Permalink
add test to validation function
Browse files Browse the repository at this point in the history
  • Loading branch information
rvrangel committed Apr 27, 2021
1 parent f1e1664 commit 66c7b9c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions go/vt/mysqlctl/xtrabackupengine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package mysqlctl

import (
"bytes"
"fmt"
"io"
"math/rand"
"strings"
"testing"

"vitess.io/vitess/go/vt/logutil"
Expand Down Expand Up @@ -115,3 +117,40 @@ func TestStripeRoundTrip(t *testing.T) {
// Test block size and stripe count that don't evenly divide data size.
test(6000, 7)
}

func TestValidateExternalDecompressor(t *testing.T) {
tests := []struct {
cmdName string
path string
errStr string
}{
// this should not find an executable
{"non_existent_cmd", "", "executable file not found"},
// we expect ls to be on PATH as it is a basic command part of busybox and most containers
{"ls", "ls", ""},
}

for i, tt := range tests {
t.Run(fmt.Sprintf("Test #%d", i+1), func(t *testing.T) {
CmdName := tt.cmdName

path, err := validateExternalDecompressor(CmdName)

if tt.path != "" {
if !strings.HasSuffix(path, tt.path) {
t.Errorf("Expected path \"%s\" to include \"%s\"", path, tt.path)
}
}

if tt.errStr == "" {
if err != nil {
t.Errorf("Expected result \"%v\", got \"%v\"", "<nil>", err)
}
} else {
if !strings.Contains(fmt.Sprintf("%v", err), tt.errStr) {
t.Errorf("Expected result \"%v\", got \"%v\"", tt.errStr, err)
}
}
})
}
}

0 comments on commit 66c7b9c

Please sign in to comment.