Skip to content

Commit

Permalink
next seven
Browse files Browse the repository at this point in the history
Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com>
  • Loading branch information
schristoff committed May 16, 2024
1 parent 283613e commit 23d870b
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 53 deletions.
2 changes: 1 addition & 1 deletion pkg/exec/builder/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (h IgnoreErrorHandler) HandleError(ctx context.Context, err ExitError, stdo
for _, allowMatch := range h.Output.Regex {
expression, regexErr := regexp.Compile(allowMatch)
if regexErr != nil {
span.Error(fmt.Errorf("Could not ignore failed command because the Regex specified by the mixin step definition (%q) is invalid:%s", allowMatch, regexErr.Error()))
err := span.Error(fmt.Errorf("Could not ignore failed command because the Regex specified by the mixin step definition (%q) is invalid:%s", allowMatch, regexErr.Error()))
return err
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/exec/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func TestPrintVersion(t *testing.T) {
opts := version.Options{}
err := opts.Validate()
require.NoError(t, err)
m.PrintVersion(opts)
err = m.PrintVersion(opts)
require.NoError(t, err)

gotOutput := m.TestConfig.TestContext.GetOutput()
wantOutput := "exec v1.2.3 (abc123) by Porter Authors"
Expand All @@ -38,7 +39,8 @@ func TestPrintJsonVersion(t *testing.T) {
opts.RawFormat = string(printer.FormatJson)
err := opts.Validate()
require.NoError(t, err)
m.PrintVersion(opts)
err = m.PrintVersion(opts)
require.NoError(t, err)

gotOutput := m.TestConfig.TestContext.GetOutput()
wantOutput := `{
Expand Down
10 changes: 7 additions & 3 deletions pkg/pkgmgmt/client/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,18 @@ func (fs *FileSystem) downloadFile(ctx context.Context, url url.URL, destPath st
return log.Error(fmt.Errorf("unable to check if directory exists %s: %w", parentDir, err))
}

cleanup := func() {}
cleanup := func() error { return nil }
if !parentDirExists {
err = fs.FileSystem.MkdirAll(parentDir, pkg.FileModeDirectory)
if err != nil {
return log.Error(fmt.Errorf("unable to create parent directory %s: %w", parentDir, err))
}
cleanup = func() {
fs.FileSystem.RemoveAll(parentDir) // If we can't download the file, don't leave traces of it
cleanup = func() error {
// If we can't download the file, don't leave traces of it
if err = fs.FileSystem.RemoveAll(parentDir); err != nil {
return err
}
return nil
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/pkgmgmt/client/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func (r *Runner) Run(ctx context.Context, commandOpts pkgmgmt.CommandOptions) er
}
go func() {
defer stdin.Close()
io.WriteString(stdin, commandOpts.Input)
if _, err := io.WriteString(stdin, commandOpts.Input); err != nil {
span.Error(err)
}
}()
}

Expand Down
214 changes: 171 additions & 43 deletions pkg/pkgmgmt/feed/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,73 +15,191 @@ import (
)

func TestGenerate(t *testing.T) {
var err error
ctx := context.Background()
tc := portercontext.NewTestContext(t)
tc.AddTestFile("testdata/atom-template.xml", "template.xml")

tc.FileSystem.Create("bin/v1.2.3/helm-darwin-amd64")
tc.FileSystem.Create("bin/v1.2.3/helm-darwin-arm64")
tc.FileSystem.Create("bin/v1.2.3/helm-linux-amd64")
tc.FileSystem.Create("bin/v1.2.3/helm-linux-arm64")
tc.FileSystem.Create("bin/v1.2.3/helm-windows-amd64.exe")
tc.FileSystem.Create("bin/v1.2.3/helm-windows-arm64.exe")
_, err = tc.FileSystem.Create("bin/v1.2.3/helm-darwin-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v1.2.3/helm-darwin-arm64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v1.2.3/helm-linux-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v1.2.3/helm-linux-arm64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v1.2.3/helm-windows-amd64.exe")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v1.2.3/helm-windows-arm64.exe")
if err != nil {
require.NoError(t, err)
}

// Force the up3 timestamps to stay the same for each test run
up3, _ := time.Parse("2006-Jan-02", "2013-Feb-03")
tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-amd64", up3, up3)
tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-arm64", up3, up3)
tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-amd64", up3, up3)
tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-arm64", up3, up3)
tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-amd64.exe", up3, up3)
tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-arm64.exe", up3, up3)
err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-amd64", up3, up3)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-arm64", up3, up3)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-amd64", up3, up3)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-arm64", up3, up3)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-amd64.exe", up3, up3)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-arm64.exe", up3, up3)
if err != nil {
require.NoError(t, err)
}

tc.FileSystem.Create("bin/v1.2.4/helm-darwin-amd64")
tc.FileSystem.Create("bin/v1.2.4/helm-linux-amd64")
tc.FileSystem.Create("bin/v1.2.4/helm-windows-amd64.exe")
_, err = tc.FileSystem.Create("bin/v1.2.4/helm-darwin-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v1.2.4/helm-linux-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v1.2.4/helm-windows-amd64.exe")
if err != nil {
require.NoError(t, err)
}

up4, _ := time.Parse("2006-Jan-02", "2013-Feb-04")
tc.FileSystem.Chtimes("bin/v1.2.4/helm-darwin-amd64", up4, up4)
tc.FileSystem.Chtimes("bin/v1.2.4/helm-linux-amd64", up4, up4)
tc.FileSystem.Chtimes("bin/v1.2.4/helm-windows-amd64.exe", up4, up4)
err = tc.FileSystem.Chtimes("bin/v1.2.4/helm-darwin-amd64", up4, up4)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/v1.2.4/helm-linux-amd64", up4, up4)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/v1.2.4/helm-windows-amd64.exe", up4, up4)
if err != nil {
require.NoError(t, err)
}

tc.FileSystem.Create("bin/v1.2.3/exec-darwin-amd64")
tc.FileSystem.Create("bin/v1.2.3/exec-linux-amd64")
tc.FileSystem.Create("bin/v1.2.3/exec-windows-amd64.exe")
_, err = tc.FileSystem.Create("bin/v1.2.3/exec-darwin-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v1.2.3/exec-linux-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v1.2.3/exec-windows-amd64.exe")
if err != nil {
require.NoError(t, err)
}

up2, _ := time.Parse("2006-Jan-02", "2013-Feb-02")
tc.FileSystem.Chtimes("bin/v1.2.3/exec-darwin-amd64", up2, up2)
tc.FileSystem.Chtimes("bin/v1.2.3/exec-linux-amd64", up2, up2)
tc.FileSystem.Chtimes("bin/v1.2.3/exec-windows-amd64.exe", up2, up2)
err = tc.FileSystem.Chtimes("bin/v1.2.3/exec-darwin-amd64", up2, up2)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/v1.2.3/exec-linux-amd64", up2, up2)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/v1.2.3/exec-windows-amd64.exe", up2, up2)
if err != nil {
require.NoError(t, err)
}

tc.FileSystem.Create("bin/canary/exec-darwin-amd64")
tc.FileSystem.Create("bin/canary/exec-linux-amd64")
tc.FileSystem.Create("bin/canary/exec-windows-amd64.exe")
_, err = tc.FileSystem.Create("bin/canary/exec-darwin-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/canary/exec-linux-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/canary/exec-windows-amd64.exe")
if err != nil {
require.NoError(t, err)
}

up10, _ := time.Parse("2006-Jan-02", "2013-Feb-10")
tc.FileSystem.Chtimes("bin/canary/exec-darwin-amd64", up10, up10)
tc.FileSystem.Chtimes("bin/canary/exec-linux-amd64", up10, up10)
tc.FileSystem.Chtimes("bin/canary/exec-windows-amd64.exe", up10, up10)
err = tc.FileSystem.Chtimes("bin/canary/exec-darwin-amd64", up10, up10)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/canary/exec-linux-amd64", up10, up10)
if err != nil {
require.NoError(t, err)
}
err = tc.FileSystem.Chtimes("bin/canary/exec-windows-amd64.exe", up10, up10)
if err != nil {
require.NoError(t, err)
}

// Create extraneous release directories that should be ignored
tc.FileSystem.Create("bin/v0.34.0-1-gda/helm-darwin-amd64")
tc.FileSystem.Create("bin/v0.34.0-2-g1234567/helm-linux-amd64")
tc.FileSystem.Create("bin/v0.34.0-3-g12345/helm-windows-amd64.exe")
_, err = tc.FileSystem.Create("bin/v0.34.0-1-gda/helm-darwin-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v0.34.0-2-g1234567/helm-linux-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/v0.34.0-3-g12345/helm-windows-amd64.exe")
if err != nil {
require.NoError(t, err)
}

tc.FileSystem.Create("bin/latest/helm-darwin-amd64")
tc.FileSystem.Create("bin/latest/helm-linux-amd64")
tc.FileSystem.Create("bin/latest/helm-windows-amd64.exe")
_, err = tc.FileSystem.Create("bin/latest/helm-darwin-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/latest/helm-linux-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/latest/helm-windows-amd64.exe")
if err != nil {
require.NoError(t, err)
}

tc.FileSystem.Create("bin/canary-v1/exec-darwin-amd64")
tc.FileSystem.Create("bin/canary-v1/exec-linux-amd64")
tc.FileSystem.Create("bin/canary-v1/exec-windows-amd64.exe")
_, err = tc.FileSystem.Create("bin/canary-v1/exec-darwin-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/canary-v1/exec-linux-amd64")
if err != nil {
require.NoError(t, err)
}
_, err = tc.FileSystem.Create("bin/canary-v1/exec-windows-amd64.exe")
if err != nil {
require.NoError(t, err)
}

opts := GenerateOptions{
AtomFile: "atom.xml",
SearchDirectory: "bin",
TemplateFile: "template.xml",
}
f := NewMixinFeed(tc.Context)
err := f.Generate(ctx, opts)
err = f.Generate(ctx, opts)
require.NoError(t, err)
err = f.Save(opts)
require.NoError(t, err)
Expand Down Expand Up @@ -142,9 +260,19 @@ func TestGenerate_RegexMatch(t *testing.T) {
porterCtx.AddTestFile("testdata/atom-template.xml", "template.xml")

if tc.mixinName != "" {
porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-darwin-amd64", tc.mixinName))
porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-linux-amd64", tc.mixinName))
porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-windows-amd64.exe", tc.mixinName))
var err error
_, err = porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-darwin-amd64", tc.mixinName))
if err != nil {
require.NoError(t, err)
}
_, err = porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-linux-amd64", tc.mixinName))
if err != nil {
require.NoError(t, err)
}
_, err = porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-windows-amd64.exe", tc.mixinName))
if err != nil {
require.NoError(t, err)
}
}

opts := GenerateOptions{
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/pluggable/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (c *PluginConnection) Start(ctx context.Context, pluginCfg io.Reader) error
pluginErr = ": plugin stderr was " + pluginErr
}
err = fmt.Errorf("could not connect to the %s plugin%s: %w", c.key, pluginErr, err)
span.Error(err) // Emit the error before trying to close the connection
err = span.Error(err) // Emit the error before trying to close the connection
c.Close(ctx)
return err
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/portercontext/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ func TestContext_LogToFile(t *testing.T) {
_, log := c.StartRootSpan(context.Background(), t.Name())
log.Info("a thing happened")
log.Warn("a weird thing happened")
log.Error(errors.New("a bad thing happened"))
//throwing away error here because it is a test
// we do not return it
_ = log.Error(errors.New("a bad thing happened"))

log.EndSpan()
c.Close()

Expand Down
5 changes: 4 additions & 1 deletion workshop/porter-tf-aci/azure/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ func handle(w http.ResponseWriter, r *http.Request) {
http.Error(w, "couldn't find MYSQL FQDN", http.StatusInternalServerError)
}

w.Write([]byte(fmt.Sprintf("Hello, I'm a webserver that wants to connect to a MYSQL at %s", sqlFQDN)))
_, err := w.Write([]byte(fmt.Sprintf("Hello, I'm a webserver that wants to connect to a MYSQL at %s", sqlFQDN)))
if err != nil {
log.Fatal(err)
}
}

func main() {
Expand Down

0 comments on commit 23d870b

Please sign in to comment.