98 lines
3.2 KiB
Go
98 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewWithRemoteFrameworkVersion(t *testing.T) {
|
|
for _, flag := range [][]string{{"--framework-version", "v0.22.0-preview"}, {"--framework-version=v0.22.0-preview"}} {
|
|
project := filepath.Join(t.TempDir(), "billing")
|
|
args := append([]string{"--module", "example.com/billing"}, flag...)
|
|
if err := runNew(append(args, project)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
content, err := os.ReadFile(filepath.Join(project, "go.mod"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(content), "go-omni v0.22.0-preview") || strings.Contains(string(content), "replace ") {
|
|
t.Fatalf("CLI did not pin remote dependency: %s", content)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNewRejectsEmptyFrameworkVersion(t *testing.T) {
|
|
for _, args := range [][]string{{"--framework-version"}, {"--framework-version="}, {"--framework-version", " "}} {
|
|
if err := runNew(args); err == nil {
|
|
t.Fatalf("accepted missing framework version: %v", args)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAddModuleCLI(t *testing.T) {
|
|
for _, equals := range []bool{false, true} {
|
|
project := filepath.Join(t.TempDir(), "billing")
|
|
if err := runNew([]string{"--module", "example.com/billing", project}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
args := []string{"orders", "--dir", project}
|
|
if equals {
|
|
args = []string{"--dir=" + project, "orders"}
|
|
}
|
|
if err := runAdd(args); err == nil || !strings.Contains(err.Error(), ".api imports") {
|
|
t.Fatalf("expected contract-driven module guidance: %v", err)
|
|
}
|
|
}
|
|
for _, args := range [][]string{nil, {"orders", "--dir"}, {"orders", "--dir="}, {"orders", "extra"}, {"orders", "--unknown"}} {
|
|
if err := runAdd(args); err == nil {
|
|
t.Fatalf("accepted invalid arguments %v", args)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNewMySQLDatabaseOptions(t *testing.T) {
|
|
for _, flag := range [][]string{{"--database", "mysql"}, {"--database=mysql"}} {
|
|
project := filepath.Join(t.TempDir(), "billing")
|
|
args := append([]string{"--module", "example.com/billing"}, flag...)
|
|
if err := runNew(append(args, project)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(project, "internal/svc/serviceContext.go")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
for _, args := range [][]string{{"--database"}, {"--database="}, {"--database", " "}} {
|
|
if err := runNew(args); err == nil {
|
|
t.Fatalf("accepted missing database type: %v", args)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestModuleOptionCLI(t *testing.T) {
|
|
for _, flags := range [][]string{
|
|
{"--log-output", "file", "--log-format", "json", "--storage", "local"},
|
|
{"--log-output=stdout", "--log-format=text", "--storage=none"},
|
|
} {
|
|
project := filepath.Join(t.TempDir(), "demo")
|
|
args := append([]string{"--module", "example.com/demo"}, flags...)
|
|
if err := runNew(append(args, project)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(project, "etc/config.yaml")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
for _, args := range [][]string{
|
|
{"--storage"}, {"--storage="}, {"--storage", "--force"},
|
|
{"--log-output"}, {"--log-output="}, {"--log-format="},
|
|
{"--storage", "unknown", "demo"}, {"--log-format", "xml", "demo"},
|
|
} {
|
|
if err := runNew(args); err == nil {
|
|
t.Fatal("invalid module option accepted", args)
|
|
}
|
|
}
|
|
}
|