Skip to content

Commit

Permalink
Merge pull request #37 from carolynvs/fix-schema
Browse files Browse the repository at this point in the history
Fix schema command
  • Loading branch information
carolynvs-msft authored Mar 24, 2020
2 parents 597a442 + 87a3e4b commit 7d39f43
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 187 deletions.
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,27 @@ ifndef HAS_PACKR2
$(GO) get -u github.com/gobuffalo/packr/v2/packr2
endif

xbuild-all:
xbuild-all: generate
$(foreach OS, $(SUPPORTED_PLATFORMS), \
$(foreach ARCH, $(SUPPORTED_ARCHES), \
$(MAKE) $(MAKE_OPTS) CLIENT_PLATFORM=$(OS) CLIENT_ARCH=$(ARCH) MIXIN=$(MIXIN) xbuild; \
))
$(MAKE) clean-packr

xbuild: $(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT)
$(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT):
mkdir -p $(dir $@)
GOOS=$(CLIENT_PLATFORM) GOARCH=$(CLIENT_ARCH) $(XBUILD) -o $@ ./cmd/$(MIXIN)

test: test-unit
test: test-unit test-integration

test-unit: build
$(GO) test ./...
$(GO) test ./pkg/...

test-integration: xbuild
# Test against the cross-built client binary that we will publish
cp $(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT) $(BINDIR)/$(MIXIN)$(FILE_EXT)
$(GO) test -tags=integration ./tests/...

publish: bin/porter$(FILE_EXT)
# AZURE_STORAGE_CONNECTION_STRING will be used for auth in the following commands
Expand All @@ -91,5 +97,8 @@ install:
install $(BINDIR)/$(MIXIN)$(FILE_EXT) $(PORTER_HOME)/mixins/$(MIXIN)/$(MIXIN)$(FILE_EXT)
install $(BINDIR)/$(MIXIN)-runtime$(FILE_EXT) $(PORTER_HOME)/mixins/$(MIXIN)/$(MIXIN)-runtime$(FILE_EXT)

clean:
clean: clean-packr
-rm -fr bin/

clean-packr: packr2
cd pkg/$(MIXIN) && packr2 clean
7 changes: 6 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ steps:
displayName: 'Set up the Go workspace'

- script: |
make build test
make build test-unit
workingDirectory: '$(modulePath)'
displayName: 'Unit Test'

Expand All @@ -39,6 +39,11 @@ steps:
workingDirectory: '$(modulePath)'
displayName: 'Cross Compile'

- script: |
make test-integration
workingDirectory: '$(modulePath)'
displayName: 'Integration Test'

- script: |
AZURE_STORAGE_CONNECTION_STRING=$(AZURE_STORAGE_CONNECTION_STRING) make publish
workingDirectory: '$(modulePath)'
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKe
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jinzhu/gorm v1.9.11/go.mod h1:bu/pK8szGZ2puuErfU0RwyeNdsf3e6nCX/noXaVxkfw=
Expand All @@ -222,6 +223,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kisielk/sqlstruct v0.0.0-20150923205031-648daed35d49/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
github.com/kisom/goutils v1.1.0/go.mod h1:+UBTfd78habUYWFbNWTJNG+jNG/i/lGURakr4A/yNRw=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
2 changes: 1 addition & 1 deletion pkg/terraform/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (m *Mixin) PrintSchema() error {
}

func (m *Mixin) GetSchema() (string, error) {
b, err := m.schema.Find("terraform.json")
b, err := m.schema.Find("schema.json")
if err != nil {
return "", err
}
Expand Down
File renamed without changes.
180 changes: 0 additions & 180 deletions pkg/terraform/schema/terraform.json

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/terraform/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestMixin_PrintSchema(t *testing.T) {

gotSchema := m.TestContext.GetOutput()

wantSchema, err := ioutil.ReadFile("testdata/schema.json")
wantSchema, err := ioutil.ReadFile("schema/schema.json")
require.NoError(t, err)

assert.Equal(t, string(wantSchema), gotSchema)
Expand Down
2 changes: 2 additions & 0 deletions pkg/terraform/terraform.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:generate packr2

package terraform

import (
Expand Down
36 changes: 36 additions & 0 deletions tests/schema_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// +build integration

package tests

import (
"bytes"
"os"
"os/exec"
"testing"

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

// Add a test that checked that the schema was packed into the binary
// properly. Requires a make clean xbuild-all first.
func TestSchema(t *testing.T) {
schemaBackup := "../pkg/terraform/schema/schema.json.bak"
schemaPath := "../pkg/terraform/schema/schema.json"

defer os.Rename(schemaBackup, schemaPath)
err := os.Rename(schemaPath, schemaBackup)
require.NoError(t, err, "failed to sabotage the schema.json")

output := &bytes.Buffer{}
cmd := exec.Command("terraform", "schema")
cmd.Path = "../bin/mixins/terraform/terraform"
cmd.Stdout = output
cmd.Stderr = output

err = cmd.Start()
require.NoError(t, err, "failed to start the terraform schema command")

err = cmd.Wait()
t.Log(output)
require.NoError(t, err, "terraform schema failed")
}

0 comments on commit 7d39f43

Please sign in to comment.