52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewWithRemoteFrameworkVersion(t *testing.T) {
|
|
for _, flag := range [][]string{{"--framework-version", "v0.1.0"}, {"--framework-version=v0.1.0"}} {
|
|
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.1.0") || 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 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, "schema.sql")); 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)
|
|
}
|
|
}
|
|
}
|