diff --git a/Dockerfile b/Dockerfile index 19aa30c..d009817 100644 --- a/Dockerfile +++ b/Dockerfile @@ -144,7 +144,7 @@ COPY src/plugin_loader.go /tmp/signal-cli-rest-api-src/ RUN ls -la /tmp/signal-cli-rest-api-src RUN cd /tmp/signal-cli-rest-api-src && ${GOPATH}/bin/swag init RUN cd /tmp/signal-cli-rest-api-src && go build -o signal-cli-rest-api main.go -RUN cd /tmp/signal-cli-rest-api-src && go test ./client -v +RUN cd /tmp/signal-cli-rest-api-src && go test ./client -v && go test ./utils -v # build supervisorctl_config_creator RUN cd /tmp/signal-cli-rest-api-src/scripts && go build -o jsonrpc2-helper diff --git a/src/utils/utils.go b/src/utils/utils.go index deec1e7..882309d 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -41,7 +41,7 @@ func IsPhoneNumber(s string) bool { return false } } else { - if c < '0' || c > '9' { + if (c < '0' || c > '9') && (c != ' ') { return false } } diff --git a/src/utils/utils_test.go b/src/utils/utils_test.go new file mode 100644 index 0000000..63160ff --- /dev/null +++ b/src/utils/utils_test.go @@ -0,0 +1,42 @@ +package utils + +import ( + "testing" +) + +func expectEqual(t *testing.T, in1 bool, in2 bool) { + if in1 != in2 { + t.Errorf("got %t, wanted %t", in1, in2) + } +} + +func TestIsPhoneNumber(t *testing.T) { + res := IsPhoneNumber("+12345678") + expectEqual(t, res, true) +} + + +func TestIsPhoneNumberWithSpaces(t *testing.T) { + res := IsPhoneNumber("+ 12345678") + expectEqual(t, res, true) +} + +func TestIsPhoneNumberWithSpaces1(t *testing.T) { + res := IsPhoneNumber("+ 1234 5678") + expectEqual(t, res, true) +} + +func TestIsPhoneNumberWithInvalidCharacters(t *testing.T) { + res := IsPhoneNumber("+123456x") + expectEqual(t, res, false) +} + +func TestIsPhoneNumberWithMissingPrefix(t *testing.T) { + res := IsPhoneNumber("123456x") + expectEqual(t, res, false) +} + +func TestIsPhoneNumberWithInvalidCharactersAndSpaces(t *testing.T) { + res := IsPhoneNumber("+12345 6x") + expectEqual(t, res, false) +}