Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to go1.17 #309

Merged
merged 3 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ coverage:
echo -n > coverage.txt
for pkg in $(PKGS) ; do go test -coverprofile=profile.out -covermode=atomic $${pkg} && cat profile.out >> coverage.txt; done

package:
mkdir -p $(OUTDIR)/bin
mv bfe $(OUTDIR)/bin
cp -r conf $(OUTDIR)

check:
go get honnef.co/go/tools/cmd/staticcheck
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...

clean:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Let's examine the `config.yaml` fields so you will feel more comfortable editing
| output_binary | /app | output binary artifact inside the runtime container |
| build_command | go build -o {{.output_binary}} | build command inside the runtime container. Note you can reference other configuration fields. When enabling Debugger `-gcflags="all=-N -l"` will be appended to the build command to stop compiler optimization and symbol removing |
| run_command | {.output_binary}} | run command, probably most of the time will just be the binary artifact path |
| runtime_image | golang:1.15.2 | base Docker image for the runtime container |
| runtime_image | golang:1.17 | base Docker image for the runtime container |
| debugger_enabled | false | whether to enable delve debugger inside the container or just use hot-reload |
| debugger_port | 40000 | delve debugger listen port, relevant only if `debugger_enabled` was set |
| expose_ports | [] | list of ports to expose inside the container. Uses the same syntax as docker-compose for mapping between host and container ports(e.g: "8080:8080"). No need to add the delve debugger listen port as it will be auto-added |
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Configurations
output_binary - output binary artifact inside the runtime container (default: "/app")
build_command - build command inside the runtime container (default: "go build -o {{.output_binary}}")
run_command - run command, probably most of the time will just be the binary artifact path (default: "{.output_binary}}")
runtime_image - base Docker image for the runtime container (default: "golang:1.15.2")
runtime_image - base Docker image for the runtime container (default: "golang:1.17")
debugger_enabled - whether to enable delve debugger inside the container or just use hot-reload (default: false)
debugger_port - delve debugger listen port, relevant only if debugger_enabled was set (default: 40000)
expose_ports - list of ports to expose inside the container (default: [])
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package config

import (
"fmt"
"io"
"path"
"reflect"
"fmt"
"strings"

"github.com/moshebe/gebug/pkg/render"
Expand Down
12 changes: 6 additions & 6 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestConfig_Load(t *testing.T) {
name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}} -gcflags="all=-N-l"
runtime_image: golang:1.15.2
runtime_image: golang:1.17
run_command: '{{.output_binary}}'
debugger_port: 40000
expose_ports:
Expand All @@ -32,7 +32,7 @@ expose_ports:
OutputBinaryPath: "/app",
BuildCommand: `go build -o /app -gcflags="all=-N-l"`,
RunCommand: "/app",
RuntimeImage: "golang:1.15.2",
RuntimeImage: "golang:1.17",
DebuggerPort: 40000,
ExposePorts: []string{"8080:8080"},
},
Expand All @@ -43,7 +43,7 @@ expose_ports:
name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}} -gcflags="all=-N-l"
runtime_image: golang:1.15.2
runtime_image: golang:1.17
run_command: '{{.output_binary}}'
debugger_port: 40000
expose_ports:
Expand All @@ -54,7 +54,7 @@ expose_ports:
OutputBinaryPath: "/app",
BuildCommand: `go build -o /app -gcflags="all=-N-l"`,
RunCommand: "/app",
RuntimeImage: "golang:1.15.2",
RuntimeImage: "golang:1.17",
DebuggerPort: 40000,
ExposePorts: []string{"8080:8080"},
},
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestConfig_Write(t *testing.T) {
BuildCommand: "go build -o /app -gcflags=\"all=-N-l\"",
BuildDir: "/app",
RunCommand: "/app",
RuntimeImage: "golang:1.15.2",
RuntimeImage: "golang:1.17",
DebuggerPort: 40000,
DebuggerEnabled: true,
ExposePorts: []string{"8080", "8081:8081"},
Expand All @@ -133,7 +133,7 @@ output_binary: /app
build_command: go build -o /app -gcflags="all=-N-l"
build_dir: /app
run_command: /app
runtime_image: golang:1.15.2
runtime_image: golang:1.17
debugger_enabled: true
debugger_port: 40000
expose_ports:
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var mockConfig = &Config{
OutputBinaryPath: "/app",
BuildCommand: "go build",
RunCommand: "/app",
RuntimeImage: "golang:1.15.2",
RuntimeImage: "golang:1.17",
DebuggerEnabled: false,
DebuggerPort: 0,
ExposePorts: []string{"8080"},
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestConfig_RenderDockerfile(t *testing.T) {
err := mockConfig.RenderDockerfile(out)
assert.NoError(t, err)
assert.Equal(t,
`FROM golang:1.15.2
`FROM golang:1.17
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv
WORKDIR /src
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_docker_compose_0.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}}
runtime_image: golang:1.15.2
runtime_image: golang:1.17
run_command: '{{.output_binary}}'
debugger_port: 40000
debugger_enabled: true
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_docker_compose_1.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}}
runtime_image: golang:1.15.2
runtime_image: golang:1.17
run_command: '{{.output_binary}}'
debugger_port: 40000
debugger_enabled: false
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_docker_compose_2.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}}
runtime_image: golang:1.15.2
runtime_image: golang:1.17
run_command: '{{.output_binary}}'
debugger_port: 40000
debugger_enabled: false
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_docker_compose_3.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}}
runtime_image: golang:1.15.2
runtime_image: golang:1.17
run_command: '{{.output_binary}}'
debugger_port: 40000
debugger_enabled: false
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_docker_compose_4.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}}
run_command: '{{.output_binary}}'
runtime_image: golang:1.15.2
runtime_image: golang:1.17
debugger_enabled: true
debugger_port: 40000
expose_ports: []
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_dockerfile_0.golden
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15.2
FROM golang:1.17
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv
WORKDIR /src
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_dockerfile_0.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}}
runtime_image: golang:1.15.2
runtime_image: golang:1.17
run_command: '{{.output_binary}}'
debugger_port: 40000
debugger_enabled: true
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_dockerfile_1.golden
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15.2
FROM golang:1.17
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv
WORKDIR /src
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_dockerfile_1.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}}
runtime_image: golang:1.15.2
runtime_image: golang:1.17
run_command: '{{.output_binary}}'
debugger_port: 40000
debugger_enabled: false
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_dockerfile_2.golden
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15.2
FROM golang:1.17
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv
WORKDIR /src
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_dockerfile_2.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: my-app
output_binary: /app
build_command: go build -o {{.output_binary}}
build_dir: /src
runtime_image: golang:1.15.2
runtime_image: golang:1.17
run_command: '{{.output_binary}}'
debugger_port: 40000
debugger_enabled: false
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_dockerfile_3.golden
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15.2
FROM golang:1.17
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/go-delve/delve/cmd/dlv
RUN echo "hello" && echo "world"
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/testdata/generate_dockerfile_3.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pre_run_commands:
- ls
build_command: go build -o {{.output_binary}}
build_dir: /src
runtime_image: golang:1.15.2
runtime_image: golang:1.17
run_command: '{{.output_binary}}'
debugger_port: 40000
debugger_enabled: false
Expand Down
2 changes: 1 addition & 1 deletion pkg/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func LoadOrDefault(workDir string) (*config.Config, bool) {
OutputBinaryPath: "/app",
BuildCommand: `go build -o {{.output_binary}}`,
RunCommand: `{{.output_binary}}`,
RuntimeImage: "golang:1.15.2",
RuntimeImage: "golang:1.17",
}

configFilePath := config.FilePath(workDir, config.Path)
Expand Down
11 changes: 5 additions & 6 deletions pkg/setup/ide_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import (
"testing"

"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestIde_detected(t *testing.T) {
AppFs = afero.NewMemMapFs()
assertion := assert.New(t)

createdDirName := ".my_ide"
err := AppFs.Mkdir(createdDirName, 0777)
assertion.NoError(err)
require.NoError(t, err)

_, err = afero.ReadDir(AppFs, createdDirName)
assertion.NoError(err)
require.NoError(t, err)

_, err = afero.ReadDir(AppFs, ".not-exists")
assertion.Error(err)
require.Error(t, err)
}

func TestIde_SupportedIdes(t *testing.T) {
assert.NotEmpty(t, SupportedIdes(".", 0))
require.NotEmpty(t, SupportedIdes(".", 0))
}
112 changes: 61 additions & 51 deletions pkg/validate/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,76 @@ import (
"fmt"
"testing"

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

type testScenario struct {
input string
wantErr bool
}

func testValidator(t *testing.T, validator Validator, tests []testScenario) {
for i, test := range tests {
func TestNonEmptyValidator(t *testing.T) {
tests := []struct {
input string
err require.ErrorAssertionFunc
}{
{input: "", err: require.Error},
{input: " ", err: require.Error},
{input: " \t", err: require.Error},
{input: " \t\n", err: require.Error},
{input: "hello", err: require.NoError},
{input: "hello-world", err: require.NoError},
{input: "hello world", err: require.NoError},
}
for i, tt := range tests {
t.Run(fmt.Sprintf("%s#%d", t.Name(), i), func(t *testing.T) {
err := validator.Validate(test.input)
if test.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
tt.err(t, NonEmptyValidator{}.Validate(tt.input))
})
}
}

func TestNonEmptyValidator(t *testing.T) {
testValidator(t, NonEmptyValidator{}, []testScenario{
{input: "", wantErr: true},
{input: " ", wantErr: true},
{input: " \t", wantErr: true},
{input: " \t\n", wantErr: true},
{input: "hello", wantErr: false},
{input: "hello-world", wantErr: false},
{input: "hello world", wantErr: false},
})
}

func TestRegexValidator(t *testing.T) {
testValidator(t, RegexValidator{Pattern: `^[A-Za-z0-9]([A-Za-z0-9_-]*[A-Za-z0-9])?$`}, []testScenario{
{input: "", wantErr: true},
{input: " ", wantErr: true},
{input: " \t", wantErr: true},
{input: " \t\n", wantErr: true},
{input: "!hello", wantErr: true},
{input: "hello world", wantErr: true},
{input: "0abc", wantErr: false},
{input: " hello", wantErr: false},
{input: "hello", wantErr: false},
{input: "hello-world", wantErr: false},
})
tests := []struct {
input string
err require.ErrorAssertionFunc
}{
{input: "", err: require.Error},
{input: " ", err: require.Error},
{input: " \t", err: require.Error},
{input: " \t\n", err: require.Error},
{input: "!hello", err: require.Error},
{input: "hello world", err: require.Error},
{input: "0abc", err: require.NoError},
{input: " hello", err: require.NoError},
{input: "hello", err: require.NoError},
{input: "hello-world", err: require.NoError},
}

valiator := RegexValidator{Pattern: `^[A-Za-z0-9]([A-Za-z0-9_-]*[A-Za-z0-9])?$`}
for i, tt := range tests {
t.Run(fmt.Sprintf("%s#%d", t.Name(), i), func(t *testing.T) {
tt.err(t, valiator.Validate(tt.input))
})
}
}

func TestNumericRangeValidator(t *testing.T) {
testValidator(t, NumericRangeValidator{Min: 1, Max: 10}, []testScenario{
{input: "", wantErr: true},
{input: " ", wantErr: true},
{input: " \t", wantErr: true},
{input: " \t\n", wantErr: true},
{input: "!hello", wantErr: true},
{input: "0", wantErr: true},
{input: "a1", wantErr: true},
{input: "11", wantErr: true},
{input: "1", wantErr: false},
{input: "5", wantErr: false},
{input: "10", wantErr: false},
})
tests := []struct {
input string
err require.ErrorAssertionFunc
}{
{input: "", err: require.Error},
{input: " ", err: require.Error},
{input: " \t", err: require.Error},
{input: " \t\n", err: require.Error},
{input: "!hello", err: require.Error},
{input: "0", err: require.Error},
{input: "a1", err: require.Error},
{input: "11", err: require.Error},
{input: "1", err: require.NoError},
{input: "5", err: require.NoError},
{input: "10", err: require.NoError},
}

valiator := NumericRangeValidator{Min: 1, Max: 10}
for i, tt := range tests {
t.Run(fmt.Sprintf("%s#%d", t.Name(), i), func(t *testing.T) {
tt.err(t, valiator.Validate(tt.input))
})
}
}
2 changes: 1 addition & 1 deletion webui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15.5
FROM golang:1.17
RUN apt-get update
RUN apt-get install -y git python jq curl

Expand Down