Skip to content

Commit

Permalink
Merge pull request #925 from hairyhenderson/go-1.15-bump
Browse files Browse the repository at this point in the history
Go 1.15 bump and other updates
  • Loading branch information
Dave Henderson authored and GitHub committed Aug 20, 2020
2 parents c0d464d + 32b2da2 commit 6f39778
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 147 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1.1.5-experimental
# syntax=docker/dockerfile:1.1.7-experimental
FROM --platform=linux/amd64 hairyhenderson/upx:3.94 AS upx

FROM --platform=linux/amd64 golang:1.14.4-alpine3.12 AS build
FROM --platform=linux/amd64 golang:1.15.0-alpine3.12 AS build

ARG TARGETOS
ARG TARGETARCH
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.integration
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM vault:1.4.3 AS vault
FROM vault:1.5.0 AS vault

FROM consul:1.8.0 AS consul
FROM consul:1.8.3 AS consul

FROM golang:1.14.6-alpine3.12
FROM golang:1.15.0-alpine3.12

COPY --from=vault /bin/vault /bin/vault
COPY --from=consul /bin/consul /bin/consul
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ build: $(PREFIX)/bin/$(PKG_NAME)_$(GOOS)-$(GOARCH)$(TARGETVARIANT)$(call extensi

ifeq ($(OS),Windows_NT)
test:
$(GO) test -v -coverprofile=c.out ./...
$(GO) test -coverprofile=c.out ./...
else
test:
$(GO) test -v -race -coverprofile=c.out ./...
$(GO) test -race -coverprofile=c.out ./...
endif

integration: build
Expand Down
132 changes: 63 additions & 69 deletions cmd/gomplate/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"os"
"testing"
"time"
Expand Down Expand Up @@ -183,76 +184,69 @@ func TestPickConfigFile(t *testing.T) {
assert.Equal(t, "config.file", cf)
}

func TestApplyEnvVars_PluginTimeout(t *testing.T) {
os.Setenv("GOMPLATE_PLUGIN_TIMEOUT", "bogus")

ctx := context.TODO()
cfg := &config.Config{}
_, err := applyEnvVars(ctx, cfg)
assert.Error(t, err)

cfg = &config.Config{
PluginTimeout: 2 * time.Second,
}
expected := &config.Config{
PluginTimeout: 2 * time.Second,
}
actual, err := applyEnvVars(ctx, cfg)
assert.NoError(t, err)
assert.EqualValues(t, expected, actual)

os.Setenv("GOMPLATE_PLUGIN_TIMEOUT", "2s")
defer os.Unsetenv("GOMPLATE_PLUGIN_TIMEOUT")

cfg = &config.Config{}
actual, err = applyEnvVars(ctx, cfg)
assert.NoError(t, err)
assert.EqualValues(t, expected, actual)

cfg = &config.Config{
PluginTimeout: 100 * time.Millisecond,
}
expected = &config.Config{
PluginTimeout: 100 * time.Millisecond,
}
actual, err = applyEnvVars(ctx, cfg)
assert.NoError(t, err)
assert.EqualValues(t, expected, actual)

}

func TestApplyEnvVars_SuppressEmpty(t *testing.T) {
os.Setenv("GOMPLATE_SUPPRESS_EMPTY", "bogus")
defer os.Unsetenv("GOMPLATE_SUPPRESS_EMPTY")

ctx := context.TODO()
cfg := &config.Config{}
expected := &config.Config{
SuppressEmpty: false,
}
actual, err := applyEnvVars(ctx, cfg)
assert.NoError(t, err)
assert.EqualValues(t, expected, actual)

os.Setenv("GOMPLATE_SUPPRESS_EMPTY", "true")

cfg = &config.Config{}
expected = &config.Config{
SuppressEmpty: true,
func TestApplyEnvVars(t *testing.T) {
data := []struct {
env string
value string
shouldErr bool
input, expected *config.Config
}{
{
"GOMPLATE_PLUGIN_TIMEOUT", "bogus",
true,
&config.Config{}, nil,
},
{
"GOMPLATE_PLUGIN_TIMEOUT", "bogus",
false,
&config.Config{PluginTimeout: 2 * time.Second},
&config.Config{PluginTimeout: 2 * time.Second},
},
{
"GOMPLATE_PLUGIN_TIMEOUT", "2s",
false,
&config.Config{},
&config.Config{PluginTimeout: 2 * time.Second},
},
{
"GOMPLATE_PLUGIN_TIMEOUT", "2s",
false,
&config.Config{PluginTimeout: 100 * time.Millisecond},
&config.Config{PluginTimeout: 100 * time.Millisecond},
},

{
"GOMPLATE_SUPPRESS_EMPTY", "bogus",
false,
&config.Config{},
&config.Config{SuppressEmpty: false},
},
{
"GOMPLATE_SUPPRESS_EMPTY", "true",
false,
&config.Config{},
&config.Config{SuppressEmpty: true},
},
{
"GOMPLATE_SUPPRESS_EMPTY", "false",
false,
&config.Config{SuppressEmpty: true},
&config.Config{SuppressEmpty: true},
},
}
actual, err = applyEnvVars(ctx, cfg)
assert.NoError(t, err)
assert.EqualValues(t, expected, actual)

os.Setenv("GOMPLATE_SUPPRESS_EMPTY", "false")

cfg = &config.Config{
SuppressEmpty: true,
}
expected = &config.Config{
SuppressEmpty: true,
for i, d := range data {
t.Run(fmt.Sprintf("applyEnvVars_%s_%s/%d", d.env, d.value, i), func(t *testing.T) {
os.Setenv(d.env, d.value)

actual, err := applyEnvVars(context.Background(), d.input)
os.Unsetenv(d.env)
if d.shouldErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.EqualValues(t, d.expected, actual)
}
})
}
actual, err = applyEnvVars(ctx, cfg)
assert.NoError(t, err)
assert.EqualValues(t, expected, actual)
}
2 changes: 1 addition & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestEnvGetsUpdatedEnvironment(t *testing.T) {
}

func TestCreateContext(t *testing.T) {
ctx := context.TODO()
ctx := context.Background()
c, err := createTmplContext(ctx, nil, nil)
assert.NoError(t, err)
assert.Empty(t, c)
Expand Down
6 changes: 3 additions & 3 deletions data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ func csvParseArgs(args ...string) (in, delim string, hdr []string) {

// autoIndex - calculates a default string column name given a numeric value
func autoIndex(i int) string {
s := ""
s := &strings.Builder{}
for n := 0; n <= i/26; n++ {
s += string('A' + i%26)
s.WriteRune('A' + rune(i%26))
}
return s
return s.String()
}

// CSV - Unmarshal CSV
Expand Down
8 changes: 6 additions & 2 deletions data/datasource.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package data

import (
"context"
"fmt"
"io"
"mime"
Expand Down Expand Up @@ -80,6 +81,8 @@ func (d *Data) lookupReader(scheme string) (func(*Source, ...string) ([]byte, er

// Data -
type Data struct {
ctx context.Context

Sources map[string]*Source

sourceReaders map[string]func(*Source, ...string) ([]byte, error)
Expand All @@ -105,12 +108,12 @@ func NewData(datasourceArgs, headerArgs []string) (*Data, error) {
if err != nil {
return nil, err
}
data := FromConfig(cfg)
data := FromConfig(context.Background(), cfg)
return data, nil
}

// FromConfig - internal use only!
func FromConfig(cfg *config.Config) *Data {
func FromConfig(ctx context.Context, cfg *config.Config) *Data {
sources := map[string]*Source{}
for alias, d := range cfg.DataSources {
sources[alias] = &Source{
Expand All @@ -127,6 +130,7 @@ func FromConfig(cfg *config.Config) *Data {
}
}
return &Data{
ctx: ctx,
Sources: sources,
extraHeaders: cfg.ExtraHeaders,
}
Expand Down
4 changes: 2 additions & 2 deletions data/datasource_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func overrideFSLoader(fs billy.Filesystem) {
}

func TestOpenFileRepo(t *testing.T) {
ctx := context.TODO()
ctx := context.Background()
repoFS := setupGitRepo(t)
g := gitsource{}

Expand Down Expand Up @@ -349,7 +349,7 @@ func TestOpenFileRepo(t *testing.T) {
}

func TestOpenBareFileRepo(t *testing.T) {
ctx := context.TODO()
ctx := context.Background()
repoFS := setupGitRepo(t)
g := gitsource{}

Expand Down
11 changes: 8 additions & 3 deletions data/datasource_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package data

import (
"context"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -329,11 +330,13 @@ func TestMimeTypeWithArg(t *testing.T) {
}

func TestFromConfig(t *testing.T) {
ctx := context.Background()
cfg := &config.Config{}
expected := &Data{
ctx: ctx,
Sources: map[string]*Source{},
}
assert.EqualValues(t, expected, FromConfig(cfg))
assert.EqualValues(t, expected, FromConfig(ctx, cfg))

cfg = &config.Config{
DataSources: map[string]config.DataSource{
Expand All @@ -343,14 +346,15 @@ func TestFromConfig(t *testing.T) {
},
}
expected = &Data{
ctx: ctx,
Sources: map[string]*Source{
"foo": {
Alias: "foo",
URL: mustParseURL("http://example.com"),
},
},
}
assert.EqualValues(t, expected, FromConfig(cfg))
assert.EqualValues(t, expected, FromConfig(ctx, cfg))

cfg = &config.Config{
DataSources: map[string]config.DataSource{
Expand All @@ -373,6 +377,7 @@ func TestFromConfig(t *testing.T) {
},
}
expected = &Data{
ctx: ctx,
Sources: map[string]*Source{
"foo": {
Alias: "foo",
Expand All @@ -392,5 +397,5 @@ func TestFromConfig(t *testing.T) {
},
},
}
assert.EqualValues(t, expected, FromConfig(cfg))
assert.EqualValues(t, expected, FromConfig(ctx, cfg))
}
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
module github.com/hairyhenderson/gomplate/v3

go 1.14
go 1.15

require (
github.com/Masterminds/goutils v1.1.0
github.com/Shopify/ejson v1.2.2
github.com/aws/aws-sdk-go v1.33.9
github.com/aws/aws-sdk-go v1.34.7
github.com/boltdb/bolt v1.3.1
github.com/docker/libkv v0.2.1
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa
github.com/google/uuid v1.1.1
github.com/gosimple/slug v1.9.0
github.com/hairyhenderson/toml v0.3.1-0.20191004034452-2a4f3b6160f2
github.com/hashicorp/consul/api v1.4.0
github.com/hashicorp/consul/api v1.6.0
github.com/hashicorp/go-sockaddr v1.0.2
github.com/hashicorp/vault/api v1.0.4
github.com/johannesboyne/gofakes3 v0.0.0-20200605082314-e89baa38acc1
github.com/johannesboyne/gofakes3 v0.0.0-20200716060623-6b2b4cb092cc
github.com/joho/godotenv v1.3.0
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.19.0
github.com/spf13/afero v1.3.2
github.com/spf13/afero v1.3.4
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.6.1
github.com/ugorji/go/codec v1.1.7
github.com/zealic/xignore v0.3.3
gocloud.dev v0.20.0
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f
gopkg.in/src-d/go-billy.v4 v4.3.2
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
gotest.tools/v3 v3.0.2
k8s.io/client-go v11.0.0+incompatible
)
Loading

0 comments on commit 6f39778

Please sign in to comment.