Skip to content

Commit

Permalink
verify that the main application container works properly
Browse files Browse the repository at this point in the history
  • Loading branch information
johnabass committed Oct 15, 2021
1 parent d909998 commit 7415e92
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
- Refactored Switch into a simpler interface that removes internal concurrency
- Ensure that as much as possible test logging goes through testing.T
- Added tests for the main DI container

## [v0.1.0]
- README text
Expand Down
14 changes: 6 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ import (
"go.uber.org/fx"
)

func run(args []string) error {
app := fx.New(
func newApp(args []string) *fx.App {
return fx.New(
parseCommandLine(args),
provideLogger(os.Stdout),
provideActions(),
provideSwitchConfig(),
provideSwitch(),
provideHTTP(),
)

app.Run()
return app.Err()
}

func main() {
err := run(os.Args[1:])
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
app := newApp(os.Args[1:])
app.Run()
if app.Err() != nil {
fmt.Fprintf(os.Stderr, "%s\n", app.Err())
os.Exit(1)
}
}
55 changes: 55 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"strconv"
"testing"

"github.com/stretchr/testify/suite"
)

type NewAppSuite struct {
DMSSuite

validParameters [][]string
invalidParameters [][]string
}

func (suite *NewAppSuite) SetupSuite() {
suite.validParameters = [][]string{
{"--exec", "echo 'hi'"},
{"--exec", "echo 'hi'", "--ttl", "10s", "--misses", "4"},
{"--exec", "echo 'hi'", "--exec", "echo 'another'", "--ttl", "12h", "--misses", "2", "--debug"},
}

suite.invalidParameters = [][]string{
{},
{"--foobar"},
{"--exec", "echo 'hi'", "--foobar"},
}
}

func (suite *NewAppSuite) TestNewApp() {
suite.Run("Valid", func() {
for i, validParameters := range suite.validParameters {
suite.Run(strconv.Itoa(i), func() {
app := newApp(validParameters)
suite.Require().NotNil(app)
suite.NoError(app.Err())
})
}
})

suite.Run("Invalid", func() {
for i, invalidParameters := range suite.invalidParameters {
suite.Run(strconv.Itoa(i), func() {
app := newApp(invalidParameters)
suite.Require().NotNil(app)
suite.Error(app.Err())
})
}
})
}

func TestNewApp(t *testing.T) {
suite.Run(t, new(NewAppSuite))
}

0 comments on commit 7415e92

Please sign in to comment.