Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
update typical-go 0.11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
imantung committed Feb 14, 2021
1 parent 3913502 commit fbf81e6
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 68 deletions.
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
github.com/alicebob/miniredis v2.5.0+incompatible
github.com/bmatcuk/doublestar/v2 v2.0.4 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.13.1 // indirect
github.com/docker/go-connections v0.4.0 // indirect
Expand All @@ -21,22 +20,19 @@ require (
github.com/golang-migrate/migrate v3.5.4+incompatible
github.com/golang/mock v1.4.4
github.com/gomodule/redigo v1.8.2 // indirect
github.com/google/go-github v17.0.0+incompatible // indirect
github.com/google/go-github/v33 v33.0.0 // indirect
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
github.com/kelseyhightower/envconfig v1.4.0
github.com/labstack/echo/v4 v4.1.16
github.com/labstack/gommon v0.3.0
github.com/leodido/go-urn v1.2.0 // indirect
github.com/lib/pq v1.4.0
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rs/xid v1.2.1
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.6.1
github.com/typical-go/typical-go v0.11.1
github.com/typical-go/typical-go v0.11.2
github.com/urfave/cli/v2 v2.3.0
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da // indirect
go.uber.org/dig v1.10.0
Expand All @@ -46,5 +42,4 @@ require (
google.golang.org/appengine v1.6.6 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0
rsc.io/quote/v3 v3.1.0 // indirect
)
22 changes: 4 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gG
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/golang-migrate/migrate v3.5.4+incompatible h1:R7OzwvCJTCgwapPCiX6DyBiu2czIUMDCB118gFTKTUA=
github.com/golang-migrate/migrate v3.5.4+incompatible/go.mod h1:IsVUlFN5puWOmXrqjgGUfIRIbU7mr8oNBE2tyERd9Wk=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
Expand All @@ -77,8 +76,6 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-github/v33 v33.0.0 h1:qAf9yP0qc54ufQxzwv+u9H0tiVOnPJxo0lI/JXqw3ZM=
github.com/google/go-github/v33 v33.0.0/go.mod h1:GMdDnVZY/2TsWgp/lkYnpSAh6TrzhANBBwm6k6TTEXg=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
Expand Down Expand Up @@ -156,12 +153,8 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/typical-go/typical-go v0.10.0 h1:TMNgE3El6zsfZutHRIYQ9qSgoKQcfRt2fowqmsWeeA4=
github.com/typical-go/typical-go v0.10.0/go.mod h1:np08BSBfNE4H0D0dTjSx9n8j9WoU/j6yumCQwFEoKII=
github.com/typical-go/typical-go v0.11.0 h1:IL9QZQVUkwQPc7OyXYuAZqBkC2nfnfIrVY2G4UrBRoo=
github.com/typical-go/typical-go v0.11.0/go.mod h1:ELsfwAHa2z0ztxiZNu1HJmg3+fCTmf2xSyw/eiR6bUM=
github.com/typical-go/typical-go v0.11.1 h1:jJkOFQLbzonzZci1GI84ArwvO7y4GUW95/mGE3rM4Ss=
github.com/typical-go/typical-go v0.11.1/go.mod h1:ELsfwAHa2z0ztxiZNu1HJmg3+fCTmf2xSyw/eiR6bUM=
github.com/typical-go/typical-go v0.11.2 h1:in+6FLjT2uvog3Nt7sSKXxJZTG1U10bPGIiYbal82Qo=
github.com/typical-go/typical-go v0.11.2/go.mod h1:ELsfwAHa2z0ztxiZNu1HJmg3+fCTmf2xSyw/eiR6bUM=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
Expand All @@ -176,7 +169,6 @@ github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da h1:NimzV1aGyq29m5u
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA=
go.opentelemetry.io/otel v0.13.0 h1:2isEnyzjjJZq6r2EKMsFj4TxiQiexsM04AVhwbR/oBA=
go.opentelemetry.io/otel v0.13.0/go.mod h1:dlSNewoRYikTkotEnxdmuBHgzT+k/idJSfDv/FxEnOY=
go.uber.org/dig v1.9.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw=
go.uber.org/dig v1.10.0 h1:yLmDDj9/zuDjv3gz8GQGviXMs9TfysIUMUilCpgzUJY=
go.uber.org/dig v1.10.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -187,6 +179,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnk
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
Expand All @@ -201,7 +194,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwL
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0 h1:wBouT66WTYFXdxfVdz9sVWARVd/2vfGcmI45D2gj45M=
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
Expand Down Expand Up @@ -231,16 +223,12 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 h1:YEu4SMq7D0cmT7CBbXfcH0NZeuChAXwsHe/9XueUO6o=
golang.org/x/sys v0.0.0-20200922070232-aee5d888a860/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418 h1:HlFl4V6pEMziuLXyRkm5BIYq1y1GAbb02pRlWvI54OM=
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand All @@ -264,6 +252,7 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc=
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand All @@ -286,10 +275,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
2 changes: 1 addition & 1 deletion pkg/typcfg/envconfig_annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (m *EnvconfigAnnotation) generate(c *Context, target string) error {
}); err != nil {
return err
}
typgo.GoImports(target)
typgo.GoImports(c.Context.Context, target)
return nil
}

Expand Down
28 changes: 19 additions & 9 deletions pkg/typcfg/envconfig_annotation_test.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package typcfg_test

import (
"flag"
"io/ioutil"
"os"
"reflect"
"strings"
"testing"

"github.com/stretchr/testify/require"
"github.com/typical-go/typical-go/pkg/typast"
"github.com/typical-go/typical-go/pkg/typgo"
"github.com/typical-go/typical-rest-server/pkg/typcfg"
"github.com/urfave/cli/v2"
)

func TestCfgAnnotation_Annotate(t *testing.T) {
typgo.ProjectPkg = "github.com/user/project"
defer os.RemoveAll("internal")

defer typgo.PatchBash([]*typgo.RunExpectation{})(t)

EnvconfigAnnotation := &typcfg.EnvconfigAnnotation{}
c, out := typgo.DummyContext()
var out strings.Builder
c := &typgo.Context{Stdout: &out}
defer c.PatchBash([]*typgo.MockBash{})(t)
ac := &typast.Context{
Context: c,
Summary: &typast.Summary{
Expand Down Expand Up @@ -70,12 +73,12 @@ func LoadSomeSample() (*a.SomeSample, error) {
}
`, string(b))

require.Equal(t, "some-project:dummy> Generate @envconfig to internal/generated/envcfg/envcfg.go\n", out.String())
require.Equal(t, "> Generate @envconfig to internal/generated/envcfg/envcfg.go\n> go build -o /bin/goimports golang.org/x/tools/cmd/goimports\n", out.String())

}

func TestCfgAnnotation_Annotate_GenerateDotEnvAndUsageDoc(t *testing.T) {
defer typgo.PatchBash(nil)(t)

defer os.Clearenv()
defer os.RemoveAll("folder")

Expand All @@ -86,7 +89,13 @@ func TestCfgAnnotation_Annotate_GenerateDotEnvAndUsageDoc(t *testing.T) {
UsageDoc: "some-usage.md",
}

c, out := typgo.DummyContext()
var out strings.Builder
c := &typgo.Context{
Context: cli.NewContext(nil, &flag.FlagSet{}, nil),
Descriptor: &typgo.Descriptor{},
Stdout: &out,
}
defer c.PatchBash(nil)(t)
ac := &typast.Context{
Context: c,
Summary: &typast.Summary{Annots: []*typast.Annot{
Expand Down Expand Up @@ -120,19 +129,20 @@ func TestCfgAnnotation_Annotate_GenerateDotEnvAndUsageDoc(t *testing.T) {
require.Equal(t, "some-text", os.Getenv("SS_SOMEFIELD1"))
require.Equal(t, "9876", os.Getenv("SS_SOMEFIELD2"))

require.Equal(t, "some-project:dummy> Generate @envconfig to folder/some-target\nsome-project:dummy> New keys added in '.env33': SS_SOMEFIELD1 SS_SOMEFIELD2\nsome-project:dummy> Generate 'some-usage.md'\n", out.String())
require.Equal(t, ":> Generate @envconfig to folder/some-target\n:> go build -o /bin/goimports golang.org/x/tools/cmd/goimports\n:> New keys added in '.env33': SS_SOMEFIELD1 SS_SOMEFIELD2\n:> Generate 'some-usage.md'\n", out.String())
}

func TestCfgAnnotation_Annotate_Predefined(t *testing.T) {
defer typgo.PatchBash(nil)(t)

defer os.RemoveAll("predefined")

EnvconfigAnnotation := &typcfg.EnvconfigAnnotation{
TagName: "@some-tag",
Template: "some-template",
Target: "predefined/cfg-target",
}
c, _ := typgo.DummyContext()
c := &typgo.Context{}
defer c.PatchBash(nil)(t)
ac := &typast.Context{
Context: c,
Summary: &typast.Summary{
Expand Down
6 changes: 4 additions & 2 deletions pkg/typcfg/generate_and_load_dotenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package typcfg_test
import (
"io/ioutil"
"os"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -17,7 +18,8 @@ func TestCreateAndLoadDotEnv_EnvFileExist(t *testing.T) {

defer os.Remove(target)

c, out := typgo.DummyContext()
var out strings.Builder
c := &typgo.Context{Stdout: &out}
cc := &typcfg.Context{
Context: &typast.Context{
Context: c,
Expand All @@ -37,5 +39,5 @@ func TestCreateAndLoadDotEnv_EnvFileExist(t *testing.T) {

b, _ := ioutil.ReadFile(target)
require.Equal(t, "key1=val111\nkey2=val222\nkey3=val3\n", string(b))
require.Equal(t, "some-project:dummy> New keys added in 'some-env': key3\n", out.String())
require.Equal(t, "> New keys added in 'some-env': key3\n", out.String())
}
60 changes: 29 additions & 31 deletions pkg/typdocker/docker_tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,90 +12,88 @@ import (
)

func TestCmdUp(t *testing.T) {
defer typgo.PatchBash([]*typgo.RunExpectation{
c := &typgo.Context{}
defer c.PatchBash([]*typgo.MockBash{
{CommandLine: "docker-compose up --remove-orphans -d"},
})(t)

c, _ := typgo.DummyContext()
err := typdocker.DockerUp(c)
require.NoError(t, err)
}

func TestCmdUp_WithPipe(t *testing.T) {
defer typgo.PatchBash([]*typgo.RunExpectation{
{CommandLine: "docker ps -q"},
{CommandLine: "docker-compose up --remove-orphans -d"},
})(t)

flagSet := &flag.FlagSet{}
flagSet.Bool("wipe", true, "")
c := cli.NewContext(nil, flagSet, nil)
c.Command = &cli.Command{}
cc := cli.NewContext(nil, flagSet, nil)
cc.Command = &cli.Command{}

err := typdocker.DockerUp(&typgo.Context{
Context: c,
c := &typgo.Context{
Context: cc,
Descriptor: &typgo.Descriptor{},
Stdout: &strings.Builder{},
})
}
defer c.PatchBash([]*typgo.MockBash{
{CommandLine: "docker ps -q"},
{CommandLine: "docker-compose up --remove-orphans -d"},
})(t)

err := typdocker.DockerUp(c)

require.NoError(t, err)
}

func TestCmdUp_WithPipeError(t *testing.T) {
defer typgo.PatchBash([]*typgo.RunExpectation{})(t)

flagSet := &flag.FlagSet{}
flagSet.Bool("wipe", true, "")

c := cli.NewContext(nil, flagSet, nil)
c.Command = &cli.Command{Name: "dummy"}
cc := cli.NewContext(nil, flagSet, nil)
cc.Command = &cli.Command{Name: "dummy"}

err := typdocker.DockerUp(&typgo.Context{
Context: c,
c := &typgo.Context{
Context: cc,
Descriptor: &typgo.Descriptor{},
Stdout: &strings.Builder{},
})
}
defer c.PatchBash([]*typgo.MockBash{})(t)

err := typdocker.DockerUp(c)

require.EqualError(t, err, "Docker-ID: typgo-mock: no run expectation for \"docker ps -q\"")
}

func TestCmdWipe(t *testing.T) {
t.Run("success", func(t *testing.T) {
defer typgo.PatchBash([]*typgo.RunExpectation{
c := &typgo.Context{}
defer c.PatchBash([]*typgo.MockBash{
{CommandLine: "docker ps -q", OutputBytes: []byte("pid-1\npid-2")},
{CommandLine: "docker kill pid-1"},
{CommandLine: "docker kill pid-2"},
})(t)

c, _ := typgo.DummyContext()
require.NoError(t, typdocker.DockerWipe(c))
})

t.Run("when ps error", func(t *testing.T) {
defer typgo.PatchBash([]*typgo.RunExpectation{})(t)

c, _ := typgo.DummyContext()
c := &typgo.Context{}
defer c.PatchBash([]*typgo.MockBash{})(t)
err := typdocker.DockerWipe(c)
require.EqualError(t, err, "Docker-ID: typgo-mock: no run expectation for \"docker ps -q\"")
})

t.Run("when kill error", func(t *testing.T) {
defer typgo.PatchBash([]*typgo.RunExpectation{
c := &typgo.Context{}
defer c.PatchBash([]*typgo.MockBash{
{CommandLine: "docker ps -q", OutputBytes: []byte("pid-1\npid-2")},
})(t)

c, _ := typgo.DummyContext()
err := typdocker.DockerWipe(c)
require.EqualError(t, err, "Fail to kill #pid-1: typgo-mock: no run expectation for \"docker kill pid-1\"")
})

}

func TestCmdDown(t *testing.T) {
defer typgo.PatchBash([]*typgo.RunExpectation{
c := &typgo.Context{}
defer c.PatchBash([]*typgo.MockBash{
{CommandLine: "docker-compose down -v"},
})(t)

c, _ := typgo.DummyContext()
require.NoError(t, typdocker.DockerDown(c))
}
2 changes: 1 addition & 1 deletion pkg/typrepo/entity_annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (m *EntityAnnotation) process(c *typast.Context, ent *EntityTmplData) error
if err := tmplkit.WriteFile(path, tmpl, ent); err != nil {
return err
}
typgo.GoImports(path)
typgo.GoImports(c.Context, path)
return nil
}

Expand Down

0 comments on commit fbf81e6

Please sign in to comment.