Skip to content

Commit 3195637

Browse files
committed
Add tests
1 parent cd151c1 commit 3195637

File tree

6 files changed

+110
-1
lines changed

6 files changed

+110
-1
lines changed

.bettercodehub.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
component_depth: 1
2+
languages:
3+
- go

.codeclimate.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
engines:
2+
golint:
3+
enabled: true
4+
gofmt:
5+
enabled: true
6+
govet:
7+
enabled: true
8+
ratings:
9+
paths: []
10+
exclude_paths: []

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
sudo: false
2+
language: go
3+
go:
4+
- 1.x
5+
- tip
6+
matrix:
7+
allow_failures:
8+
- go: tip
9+
before_install:
10+
- go get golang.org/x/tools/cmd/cover
11+
- go get github.com/modocache/gover
12+
- go get github.com/stretchr/testify/assert
13+
before_script:
14+
- go vet ./...
15+
- gofmt -s -l .
16+
script:
17+
- go list -f '{{if len .TestGoFiles}}"go test -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"{{end}}' ./... | xargs -I{} sh -c '{}'
18+
- gover . coverprofile.txt
19+
after_success:
20+
- bash <(curl -s https://codecov.io/bash) -f coverprofile.txt

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Google TTS (Text-To-Speech) for golang
22
----
33

4-
[![GoDoc][1]][2] [![License: MIT][3]][4] [![Release][5]][6] [![Build Status][7]][8] [![Codecov Coverage][11]][12] [![Go Report Card][13]][14] [![Downloads][15]][16]
4+
[![GoDoc][1]][2] [![License: MIT][3]][4] [![Release][5]][6] [![Build Status][7]][8] [![Co decov Coverage][11]][12] [![Go Report Card][13]][14] [![Code Climate][19]][20] [![BCH compliance][21]][22]
55

66
[1]: https://godoc.org/github.com/evalphobia/google-tts-go?status.svg
77
[2]: https://godoc.org/github.com/evalphobia/google-tts-go
@@ -21,6 +21,10 @@ Google TTS (Text-To-Speech) for golang
2121
[16]: https://github.com/evalphobia/google-tts-go/releases
2222
[17]: https://img.shields.io/github/stars/evalphobia/google-tts-go.svg
2323
[18]: https://github.com/evalphobia/google-tts-go/stargazers
24+
[19]: https://codeclimate.com/github/evalphobia/google-tts-go/badges/gpa.svg
25+
[20]: https://codeclimate.com/github/evalphobia/google-tts-go
26+
[21]: https://bettercodehub.com/edge/badge/evalphobia/google-tts-go?branch=master
27+
[22]: https://bettercodehub.com/
2428

2529

2630
google-tts-go is a golang implementation of the token validation of Google Translate.

googletts/token_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package googletts
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"strings"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestGetTTSToken(t *testing.T) {
13+
a := assert.New(t)
14+
15+
tests := []struct {
16+
str string
17+
}{
18+
{"a"},
19+
{"b"},
20+
{"foo"},
21+
{"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."},
22+
{"こんにちは、世界。"},
23+
}
24+
25+
for _, tt := range tests {
26+
target := fmt.Sprintf("%+v", tt)
27+
28+
token, err := GetTTSToken(tt.str)
29+
a.NoError(err, target)
30+
a.NotEmpty(token, err, target)
31+
32+
parts := strings.Split(token, ".")
33+
a.Len(parts, 2, target)
34+
for _, part := range parts {
35+
intVal, err := strconv.Atoi(part)
36+
a.NoError(err, target)
37+
a.NotEqual(0, intVal, target)
38+
}
39+
}
40+
}

googletts/tts_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package googletts
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestGetTTSURL(t *testing.T) {
11+
a := assert.New(t)
12+
13+
tests := []struct {
14+
str string
15+
lang string
16+
}{
17+
{"a", "en"},
18+
{"b", "en"},
19+
{"foo", "en"},
20+
{"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", "en"},
21+
{"こんにちは、世界。", "ja"},
22+
}
23+
24+
for _, tt := range tests {
25+
target := fmt.Sprintf("%+v", tt)
26+
27+
u, err := GetTTSURL(tt.str, tt.lang)
28+
a.NoError(err, target)
29+
a.NotEmpty(u, err, target)
30+
a.Contains(u, "https://translate.google.com/translate_tts?", target)
31+
}
32+
}

0 commit comments

Comments
 (0)