Skip to content

Commit

Permalink
feat: refactor, added documentation and TTS
Browse files Browse the repository at this point in the history
  • Loading branch information
xavidop committed Nov 1, 2022
1 parent 72023b7 commit da0970c
Show file tree
Hide file tree
Showing 25 changed files with 366 additions and 741 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release Go project
name: Goreleaser

on:
push:
Expand Down
15 changes: 14 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"ENV": "development"
},
"args": [
"profile-nlu", "execute", "--suite", "examples/suite.yaml", "--credentials", "credentials.json"
"profile-nlu", "execute", "examples/suite.yaml", "--credentials", "credentials.json"
]
},
{
Expand All @@ -63,5 +63,18 @@
"cicd", "execute", "cicd-env", "--project-id", "test-cx-346408", "--location-id", "us-central1", "--agent-name", "test-agent", "--credentials", "credentials.json"
]
},
{
"name": "TTS synthesize command",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/main.go",
"env": {
"ENV": "development"
},
"args": [
"tts", "synthesize", "hi", "--locale", "en-US", "--credentials", "credentials.json"
]
},
]
}
120 changes: 118 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,118 @@
# Dialgflow CX tester Tool
Dialogflow utility to test your Dialogflow CX Project
# CXTester
Dialogflow utility to test your Dialogflow CX Project

## Installation

You can download the latest release from [here](https://github.com/xavidop/dialogflow-cx-test-runner/releases)

### Homebrew

If you use the package manager Homebrew, you can install this utility following these steps:

1. Add my Hombre tab:
```bash
brew tap xavidop/tap [email protected]:xavidop/homebrew-tap.git
brew update
```
1. Install the CLI:
```bash
brew install cxtester
```
# Usage

```bash
Usage:
cxtester [flags]
cxtester [command]

Available Commands:
cicd Actions on CICD testings
completion Generate the autocompletion script for the specified shell
help Help about any command
profile-nlu Actions on testing
tts Actions on text-to-speech commands
version Get cxtester version

Flags:
-c, --credentials string verbose error output (with stack trace)
-h, --help help for cxtester
-o, --output string Output Format (default text)
-u, --skip-update-check Skip the check for updates check run before every command
-v, --verbose verbose error output (with stack trace)
```

## Profile NLU Test Suites

To run test suites, you can execute the following command

```bash
Usage:
cxtester profile-nlu execute [suite-file] [flags]

Aliases:
execute, execute, e, exe, exec

Flags:
-h, --help help for execute

Global Flags:
-c, --credentials string verbose error output (with stack trace)
-o, --output string Output Format (default "text")
-u, --skip-update-check Skip the check for updates check run before every command
-v, --verbose verbose error output (with stack trace)
```

Example: `cxtester profile-nlu execute "examples/suite.yaml" --credentials credentials.json`

You can find a suite example [here](/examples/)

## CICD for your Dialogflow CX environments

To execute a CICD pipeline you can execute the following command

```bash
Usage:
cxtester cicd execute [environment] [flags]

Aliases:
execute, execute, e, exe, exec

Flags:
-a, --agent-name string Dialogflow CX Agent Name
-h, --help help for execute
-l, --location-id string Dialogflow CX Location ID of the Project
-p, --project-id string Dialogflow CX Project ID

Global Flags:
-c, --credentials string verbose error output (with stack trace)
-o, --output string Output Format (default text)
-u, --skip-update-check Skip the check for updates check run before every command
-v, --verbose verbose error output (with stack trace)
```

Example: `cxtester cicd execute "<your-env>" --project-id <your-project-id> --location-id <your-location-id> --agent-name <your-agent-name> --credentials, credentials.json`

## Text-to-Speech

To transform your text to speech, you can execute the following command:

```bash
Usage:
cxtester tts synthesize [input] [flags]

Aliases:
synthesize, synth, s

Flags:
-h, --help help for synthesize
-i, --input string Input text to synthesize
-l, --locale string Input locale
-o, --output string Output file name (default "output.mp3")

Global Flags:
-c, --credentials string verbose error output (with stack trace)
-u, --skip-update-check Skip the check for updates check run before every command
-v, --verbose verbose error output (with stack trace)
```

Example: `cxtester tts synthesize "hi" -l en-US -o output.mp3 --credentials credentials.json`
3 changes: 2 additions & 1 deletion cmd/cicd/cicd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package env
package cicd

import (
"os"
Expand All @@ -13,6 +13,7 @@ var cicdCmd = &cobra.Command{
Aliases: []string{"cicd", "ci", "cd"},
Short: "Actions on CICD testings",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
os.Exit(0)
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
Expand Down
12 changes: 3 additions & 9 deletions cmd/cicd/execute.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package env
package cicd

import (
"os"
Expand All @@ -14,19 +14,13 @@ var executeCmd = &cobra.Command{
Use: "execute [environment]",
Aliases: []string{"execute", "e", "exe", "exec"},
Short: "Executes a CICD pipeline for a specific environment",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// Get the information
locationID, _ := cmd.Flags().GetString("location-id")
projectID, _ := cmd.Flags().GetString("project-id")
agentName, _ := cmd.Flags().GetString("agent-name")
envName := ""

if len(args) == 1 {
envName = args[0]
} else {
cmd.Help()
os.Exit(0)
}
envName := args[0]

if err := cicd.ExecutePipeline(envName, locationID, projectID, agentName); err != nil {
global.Log.Errorf(err.Error())
Expand Down
9 changes: 5 additions & 4 deletions cmd/profilenlu/execute.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package env
package profilenlu

import (
"os"
Expand All @@ -11,11 +11,13 @@ import (

// executeCmd represents the execute command
var executeCmd = &cobra.Command{
Use: "execute",
Use: "execute [suite-file]",
Aliases: []string{"execute", "e", "exe", "exec"},
Short: "Execute a suite",
Args: cobra.ExactArgs(1),

Run: func(cmd *cobra.Command, args []string) {
suite, _ := cmd.Flags().GetString("suite")
suite := args[0]

if err := profilenlu.ExecuteSuite(suite); err != nil {
global.Log.Errorf(err.Error())
Expand All @@ -32,5 +34,4 @@ var executeCmd = &cobra.Command{
func init() {
profilenluCmd.AddCommand(executeCmd)

executeCmd.Flags().StringP("suite", "s", "suite.yaml", "Suite yaml file")
}
3 changes: 2 additions & 1 deletion cmd/profilenlu/profilenlu.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package env
package profilenlu

import (
"os"
Expand All @@ -13,6 +13,7 @@ var profilenluCmd = &cobra.Command{
Aliases: []string{"test", "t", "tests"},
Short: "Actions on testing",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
os.Exit(0)
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
cmdcicd "github.com/xavidop/dialogflow-cx-test-runner/cmd/cicd"
"github.com/xavidop/dialogflow-cx-test-runner/cmd/cmdutils"
cmdprofilenlu "github.com/xavidop/dialogflow-cx-test-runner/cmd/profilenlu"
cmdtts "github.com/xavidop/dialogflow-cx-test-runner/cmd/tts"
"github.com/xavidop/dialogflow-cx-test-runner/internal/global"
)

Expand Down Expand Up @@ -48,6 +49,7 @@ func init() {
// Add the subcommands
cmdprofilenlu.Register(rootCmd)
cmdcicd.Register(rootCmd)
cmdtts.Register(rootCmd)

// Add the subcommands
rootCmd.PersistentFlags().BoolVarP(&global.Verbose, "verbose", "v", false, "verbose error output (with stack trace)")
Expand Down
43 changes: 43 additions & 0 deletions cmd/tts/synthesize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package tts

import (
"os"
"strings"

"github.com/spf13/cobra"
"github.com/xavidop/dialogflow-cx-test-runner/cmd/cmdutils"
"github.com/xavidop/dialogflow-cx-test-runner/internal/global"
"github.com/xavidop/dialogflow-cx-test-runner/pkg/tts"
)

// synthesizeCmd represents the execute synthesis command
var synthesizeCmd = &cobra.Command{
Use: "synthesize [input]",
Aliases: []string{"synth", "s"},
Short: "Executes a CICD pipeline for a specific environment",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// Get the information
locale, _ := cmd.Flags().GetString("locale")
input := strings.Join(args, " ")
output, _ := cmd.Flags().GetString("output")

if err := tts.Synthesize(input, locale, output); err != nil {
global.Log.Errorf(err.Error())
os.Exit(1)
}
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
cmdutils.PreRun(cmd.Name())
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
},
}

func init() {
ttsCmd.AddCommand(synthesizeCmd)

synthesizeCmd.Flags().StringP("locale", "l", "", "Input locale")
synthesizeCmd.Flags().StringP("input", "i", "", "Input text to synthesize")
synthesizeCmd.Flags().StringP("output", "o", "output.mp3", "Output file name")
}
28 changes: 28 additions & 0 deletions cmd/tts/tts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tts

import (
"os"

"github.com/spf13/cobra"
"github.com/xavidop/dialogflow-cx-test-runner/cmd/cmdutils"
)

// ttsCmd represents the tts root command
var ttsCmd = &cobra.Command{
Use: "tts",
Aliases: []string{"tts", "text-to-speech", "cd"},
Short: "Actions on text-to-speech commands",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
os.Exit(0)
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
cmdutils.PreRun(cmd.Name())
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
},
}

func Register(rootCmd *cobra.Command) {
rootCmd.AddCommand(ttsCmd)
}
Binary file removed examples/tests/audio/hello.flac
Binary file not shown.
Binary file removed examples/tests/audio/hello.mp3
Binary file not shown.
Binary file removed examples/tests/audio/hi.flac
Binary file not shown.
Binary file modified examples/tests/audio/hi.mp3
Binary file not shown.
Binary file added examples/tests/audio/hi.wav
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/tests/test_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ checks:
- id: test_1_3
input:
type: audio
audio: ./audio/hello.flac
audio: ./audio/hi.mp3
validate:
intent: hi_intent
26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ module github.com/xavidop/dialogflow-cx-test-runner
go 1.19

require (
cloud.google.com/go/dialogflow v1.16.1
cloud.google.com/go/dialogflow v1.18.0
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/uuid v1.3.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
google.golang.org/api v0.97.0
google.golang.org/genproto v0.0.0-20220926220553-6981cbe3cfce // indirect
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
google.golang.org/api v0.100.0
google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e
)

require (
cloud.google.com/go/texttospeech v1.4.0
github.com/google/go-github/v47 v47.1.0
github.com/hajimehoshi/go-mp3 v0.3.3
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
)

require (
cloud.google.com/go v0.104.0 // indirect
cloud.google.com/go/compute v1.7.0 // indirect
cloud.google.com/go/compute v1.10.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.5.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/grpc v1.50.1 // indirect
)
Loading

0 comments on commit da0970c

Please sign in to comment.