Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental compiler refactor #133

Merged
merged 29 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3f17926
wip experiment to clarify streams, apis and make generators a short-l…
matthewmueller Jun 6, 2022
6f1228b
wip: move generators to framework/
matthewmueller Jun 7, 2022
63ca7c3
add more snapshot tests and simplify app generator
matthewmueller Jun 8, 2022
bfa0057
framework/app: update comment
matthewmueller Jun 8, 2022
51ba9b4
internal/golden: swap out autogold with custom txtar implementation
matthewmueller Jun 11, 2022
c9bb8eb
'bud run' except for hot reload.
matthewmueller Jun 12, 2022
49fe21d
added initial budserver and budproxy to replace hot server, v8pipe an…
matthewmueller Jun 13, 2022
17eb829
design and integrate dev server and client to handle all comms betwee…
matthewmueller Jun 14, 2022
052c67f
got hot reload working again
matthewmueller Jun 16, 2022
eadc9ba
don't log error when context is canceled (from a sigint)
matthewmueller Jun 16, 2022
2c58e0c
finish migrating commands to new CLI
matthewmueller Jun 19, 2022
0fe7501
testing 'bud run' appears to be working now
matthewmueller Jun 19, 2022
7d0effc
controller tests have been refactored
matthewmueller Jun 19, 2022
2bdcd81
add more debug logging. fix fscache. add 'bud tool fs'
matthewmueller Jun 19, 2022
ea60e27
get most framework/ tests passing.
matthewmueller Jun 19, 2022
07ffda0
replaced hot. started planning to simplify the io.
matthewmueller Jun 20, 2022
af7df88
completely broken, but starting to come together.
matthewmueller Jun 21, 2022
a67a2ab
wip pubsub eventing
matthewmueller Jun 21, 2022
c891eed
get the cli commands and hot reload working again
matthewmueller Jun 22, 2022
b961507
do tests actually pass? o_O
matthewmueller Jun 23, 2022
0fa3d8d
merge in updates from main
matthewmueller Jun 23, 2022
a6fbe32
loosen mime type checking to account for inconsistencies across platf…
matthewmueller Jun 23, 2022
38e7afc
move the runtimes into the framework
matthewmueller Jun 24, 2022
6817a12
wip migrating hot reload improvements into compiler refactor
matthewmueller Jun 25, 2022
e91d392
integrate @012e's prompter into the compiler refactor
matthewmueller Jun 25, 2022
7f327e5
rename testlog.Log() to testlog.New(). rename to bud client and serve…
matthewmueller Jun 25, 2022
c123ddb
fix makefile source
matthewmueller Jun 25, 2022
4c4b459
remove installing bud into PATH since we no longer use v8client
matthewmueller Jun 25, 2022
84c6a24
attempt to purge cache, for some reason github actions seem to be tes…
matthewmueller Jun 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ jobs:
livebud/package-lock.json
package-lock.json

# Temporary fix to get the tests working until we pass the V8 client as a
# os.Pipe
# Using GOPRIVATE=* to try and force Go to install the latest from the
# main branch. See: https://github.com/golang/go/issues/53226
- name: Install bud binary into $PATH
run: GOPRIVATE=* go install github.com/livebud/bud@main

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer necessary! There's no more spawning of a v8server when using bud run. Instead we've combined this with an internal local "bud server", that handles server-side rendering, hot reloads, and bundling client-side files.

This bud server is only run with bud run, when you bud build v8 is bundled, there's no hot reloads and all client-side files are pre-build and embedded.

- name: Install bud node_modules
run: npm ci

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ example.hn.watch:
# Go
##

GO_SOURCE := ./internal/... ./package/... ./runtime/...
GO_SOURCE := ./internal/... ./package/... ./framework/...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to combine internal/generator and runtime/generator into one package so that would put all the generators in one place. Framework felt like a better word for this because not all the packages in framework/ used at runtime, though I'm still tempted to change it to generator/


go.tools:
@ go install \
Expand Down
6 changes: 3 additions & 3 deletions example/basic/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ type Controller struct {
}

func (c *Controller) Index() string {
return "hello world."
return "hello world"
}

func (c *Controller) Show(id string) string {
return "shows/" + id
func (c *Controller) Show(id string) (string, error) {
return "shows/" + id, nil
}
2 changes: 0 additions & 2 deletions example/basic/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ go 1.18

replace github.com/livebud/bud => ../..

require github.com/livebud/bud v0.0.0-00010101000000-000000000000

require (
github.com/ajg/form v1.5.2-0.20200323032839-9aeb3cf462e1 // indirect
github.com/armon/go-radix v1.0.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions example/basic/view/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

<style>
h1 {
background: blue;
margin: 0;
background: whitesmoke;
border-bottom: 2px dashed red;
padding: 20px;
color: white;
color: red;
}
</style>
10 changes: 7 additions & 3 deletions example/hn/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import (
"github.com/matthewmueller/hackernews"
)

func New(hn *hackernews.Client) *Controller {
return &Controller{hn}
}

type Controller struct {
HN *hackernews.Client
hn *hackernews.Client
}

func (c *Controller) Index(ctx context.Context) (stories []*hackernews.Story, err error) {
return c.HN.FrontPage(ctx)
return c.hn.FrontPage(ctx)
}

// Show a comment
func (c *Controller) Show(ctx context.Context, id int) (story *hackernews.Story, err error) {
return c.HN.Find(ctx, id)
return c.hn.Find(ctx, id)
}
6 changes: 1 addition & 5 deletions example/hn/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ require (
github.com/armon/go-radix v1.0.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/evanw/esbuild v0.14.11 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 // indirect
github.com/matthewmueller/gotext v0.0.0-20210424201144-265ed61725ac // indirect
github.com/matthewmueller/text v0.0.0-20210424201111-ec1e4af8dfe8 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/otiai10/copy v1.7.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/timewasted/go-accept-headers v0.0.0-20130320203746-c78f304b1b09 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
)
Expand Down
18 changes: 5 additions & 13 deletions example/hn/go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
github.com/Bowery/prompt v0.0.0-20190916142128-fa8279994f75/go.mod h1:4/6eNcqZ09BZ9wLK3tZOjBA1nDj+B0728nlX5YRlSmQ=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
github.com/Songmu/prompter v0.5.1/go.mod h1:CS3jEPD6h9IaLaG6afrl1orTgII9+uDWuw95dr6xHSw=
github.com/ajg/form v1.5.2-0.20200323032839-9aeb3cf462e1 h1:8Qzi+0Uch1VJvdrOhJ8U8FqoPLbUdETPgMqGJ6DSMSQ=
github.com/ajg/form v1.5.2-0.20200323032839-9aeb3cf462e1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand All @@ -17,9 +17,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/evanw/esbuild v0.14.11 h1:bw50N4v70Dqf/B6Wn+3BM6BVttz4A6tHn8m8Ydj9vxk=
github.com/evanw/esbuild v0.14.11/go.mod h1:GG+zjdi59yh3ehDn4ZWfPcATxjPDUH53iU4ZJbp7dkY=
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 h1:Uc+IZ7gYqAf/rSGFplbWBSHaGolEQlNLgMgSE3ccnIQ=
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813/go.mod h1:P+oSoE9yhSRvsmYyZsshflcR6ePWYLql6UU1amW13IM=
Expand Down Expand Up @@ -50,12 +48,10 @@ github.com/matthewmueller/text v0.0.0-20210424201111-ec1e4af8dfe8/go.mod h1:vtPa
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE=
github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI=
github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -97,8 +93,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 h1:bRb386wvrE+oBNdF1d/Xh9mQrfQ4ecYhW5qJ5GvTGT4=
golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -110,12 +104,10 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
45 changes: 45 additions & 0 deletions framework/app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package app

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app is the new entrypoint into the program. In the previous bud, there was a generated main and program. This was over-engineering at this point in bud's journey, so I opted to simplify things for the time being.

import (
"context"
_ "embed"

"github.com/livebud/bud/framework"
"github.com/livebud/bud/package/di"
"github.com/livebud/bud/package/overlay"

"github.com/livebud/bud/internal/gotemplate"
"github.com/livebud/bud/package/gomod"
)

//go:embed app.gotext
var template string

var generator = gotemplate.MustParse("framework/app/app.gotext", template)

func Generate(state *State) ([]byte, error) {
return generator.Generate(state)
}

func New(injector *di.Injector, module *gomod.Module, flag *framework.Flag) *Generator {
return &Generator{flag, injector, module}
}

type Generator struct {
flag *framework.Flag
injector *di.Injector
module *gomod.Module
}

func (g *Generator) GenerateFile(ctx context.Context, fsys overlay.F, file *overlay.File) error {
state, err := Load(fsys, g.injector, g.module, g.flag)
if err != nil {
return err
}
code, err := Generate(state)
if err != nil {
return err
}
file.Data = code
return nil
}
88 changes: 88 additions & 0 deletions framework/app/app.gotext
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package main

{{- if $.Imports }}

import (
{{- range $import := $.Imports }}
{{$import.Name}} "{{$import.Path}}"
{{- end }}
)
{{- end }}

func main() {
os.Exit(run(context.Background(), os.Args[1:]...))
}

// Run the cli
func run(ctx context.Context, args ...string) int {
if err := parse(ctx, args...); err != nil {
if errors.Is(err, context.Canceled) {
return 0
}
console.Error(err.Error())
return 1
}
return 0
}

// Parse the arguments
func parse(ctx context.Context, args ...string) error {
cli := commander.New("bud")
app := new(App)
cli.Flag("listen", "address to listen to").String(&app.Listen).Default(":3000")
cli.Flag("log", "filter logs with a pattern").Short('L').String(&app.Log).Default("info")
cli.Run(app.Run)
return cli.Parse(ctx, args)
}

// App command
type App struct {
Listen string
Log string
}

// logger creates a structured log that supports filtering
func (a *App) logger() (log.Interface, error) {
handler, err := filter.Load(console.New(os.Stderr), a.Log)
if err != nil {
return nil, err
}
return log.New(handler), nil
}

// Run your app
func (a *App) Run(ctx context.Context) error {
log, err := a.logger()
if err != nil {
return err
}
budClient, err := budclient.Try(os.Getenv("BUD_LISTEN"))
if err != nil {
return err
}
{{- if $.Provider.Variable "github.com/livebud/bud/package/gomod.*Module" }}
// Load the module dependency
module, err := gomod.Find(".")
if err != nil {
return err
}
{{- end }}
// Load the web server
webServer, err := loadWeb(
{{/* Order matters. Ordered by package name */}}
{{- if $.Provider.Variable "context.Context" }}ctx,{{ end }}
{{- if $.Provider.Variable "github.com/livebud/bud/package/budclient.Client" }}budClient,{{ end }}
{{- if $.Provider.Variable "github.com/livebud/bud/package/gomod.*Module" }}module,{{ end }}
{{- if $.Provider.Variable "github.com/livebud/bud/package/log.Interface" }}log,{{ end }}
)
if err != nil {
return err
}
// Inform bud that we're ready
budClient.Publish("app:ready", nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bud client talks to the server during bud run and informs the server that the app is ready. This allows tests to be less flaky and fail faster.

// Start serving requests
log.Debug("app: listening on", "listen", a.Listen)
return webServer.Serve(ctx, a.Listen)
}

{{ $.Provider.Function }}
32 changes: 32 additions & 0 deletions framework/app/app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package app_test

import (
"context"
"testing"

"github.com/livebud/bud/internal/cli/testcli"
"github.com/livebud/bud/internal/is"
"github.com/livebud/bud/internal/testdir"
)

func TestWelcome(t *testing.T) {
is := is.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
dir := t.TempDir()
td := testdir.New(dir)
is.NoErr(td.Write(ctx))
cli := testcli.New(dir)
is.NoErr(td.NotExists("bud/app"))
app, err := cli.Start(ctx, "run")
is.NoErr(err)
res, err := app.Get("/")
is.NoErr(err)
is.Equal(res.Status(), 200)
is.In(res.Body().String(), "Hey Bud")
is.In(res.Body().String(), "Hey Bud") // should work multiple times
is.Equal(app.Stdout(), "")
is.Equal(app.Stderr(), "")
is.NoErr(td.Exists("bud/app"))
is.NoErr(app.Close())
}
Loading