1
0
mirror of https://github.com/vanng822/go-premailer.git synced 2025-02-06 10:23:54 +00:00

Split up cmd. Add an empty test to make sure it build for now

This commit is contained in:
Van Nhu Nguyen 2019-04-05 22:54:02 +02:00
parent 9e5acafb5f
commit fa7a3893b0
6 changed files with 55 additions and 8 deletions

View File

@ -19,4 +19,4 @@ install:
- go get github.com/stretchr/testify/assert
script:
- cd premailer && go test -v
- make test

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
test:
make -j test_premailer test_cmd-server test_cmd-script
test_premailer:
cd premailer && go test -v
test_cmd-%:
cd cmd/$* && go test -v

View File

@ -3,10 +3,11 @@ package main
import (
"flag"
"fmt"
"github.com/vanng822/go-premailer/premailer"
"log"
"os"
"time"
"github.com/vanng822/go-premailer/premailer"
)
func main() {
@ -29,7 +30,10 @@ func main() {
options := premailer.NewOptions()
options.RemoveClasses = removeClasses
options.CssToAttributes = !skipCssToAttributes
prem := premailer.NewPremailerFromFile(inputFile, options)
prem, err := premailer.NewPremailerFromFile(inputFile, options)
if err != nil {
log.Fatal(err)
}
html, err := prem.Transform()
log.Printf("took: %v", time.Now().Sub(start))
if err != nil {

16
cmd/script/main_test.go Normal file
View File

@ -0,0 +1,16 @@
package main
import (
"fmt"
"os"
"testing"
)
func TestMain(m *testing.M) {
fmt.Println("Test starting")
args := os.Args[:]
retCode := m.Run()
os.Args = args
fmt.Println("Test ending")
os.Exit(retCode)
}

16
cmd/server/main_test.go Normal file
View File

@ -0,0 +1,16 @@
package main
import (
"fmt"
"os"
"testing"
)
func TestMain(m *testing.M) {
fmt.Println("Test starting")
args := os.Args[:]
retCode := m.Run()
os.Args = args
fmt.Println("Test ending")
os.Exit(retCode)
}

View File

@ -3,14 +3,15 @@ package main
import (
"flag"
"fmt"
"github.com/unrolled/render"
"github.com/vanng822/go-premailer/premailer"
"github.com/vanng822/r2router"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/unrolled/render"
"github.com/vanng822/go-premailer/premailer"
"github.com/vanng822/r2router"
)
func main() {
@ -46,8 +47,10 @@ func main() {
if cssToAttributes == "false" {
options.CssToAttributes = false
}
pre := premailer.NewPremailerFromString(html, options)
result, _ = pre.Transform()
pre, err := premailer.NewPremailerFromString(html, options)
if err == nil {
result, _ = pre.Transform()
}
} else {
result = ""
}