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

Lint local and generated code #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
timeout-minutes: 20
env:
HELM_VERSION: v2.14.3
defaults:
run:
working-directory: ./src/github.com/${{ github.repository }}
steps:
- uses: actions/setup-go@v2
with:
Expand All @@ -30,17 +33,24 @@ jobs:
with:
path: |
~/go/pkg/mod
${{ github.workspace }}/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: echo ${{ github.workspace }}/bin >> $GITHUB_PATH
- run: make templating
- name: Lint Code
uses: golangci/golangci-lint-action@v2
with:
working-directory: ./src/github.com/${{ github.repository }}
- name: Test
working-directory: ./src/github.com/${{ github.repository }}
env:
GOPATH: ${{ github.workspace }}
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"

make test-with-integration ${{ github.event.inputs.make-flags }}
make test-with-integration ${{ github.event.inputs.make-flags }} skip_teardown=true
- name: Lint Generated Code
uses: golangci/golangci-lint-action@v2
with:
working-directory: ./src/github.com/${{ github.repository }}/atlas/test
6 changes: 6 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
run:
skip-dirs:
- templates
linters:
enable:
- goimports
8 changes: 5 additions & 3 deletions atlas/commands/bootstrap/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package bootstrap
import (
"bufio"
"fmt"
"github.com/infobloxopen/atlas-cli/atlas/templates"
"github.com/jinzhu/inflection"
"io"
"log"
"os"
Expand All @@ -13,6 +11,8 @@ import (
"text/template"

"github.com/iancoleman/strcase"
"github.com/infobloxopen/atlas-cli/atlas/templates"
"github.com/jinzhu/inflection"
)

type finalTemplate struct {
Expand Down Expand Up @@ -93,7 +93,9 @@ func expandResource(appName, expandName string, withDatabase bool) error {
log.Fatalf("failed to create cmd/server/servers.go\n%s\n", err)
}

os.MkdirAll("db/migration", os.ModePerm)
if err := os.MkdirAll("db/migration", os.ModePerm); err != nil {
log.Fatalf("failed to create %q: %v", "db/migration", err)
}

for _, res := range r {
err = runTemplate([]templateResource{res}, appName, withDatabase,
Expand Down
2 changes: 1 addition & 1 deletion atlas/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package commands

import (
"flag"
"github.com/infobloxopen/atlas-cli/atlas/commands/update"

"github.com/infobloxopen/atlas-cli/atlas/commands/bootstrap"
"github.com/infobloxopen/atlas-cli/atlas/commands/update"
)

// Command generically represents a command that is runnable via the atlas
Expand Down
3 changes: 2 additions & 1 deletion atlas/commands/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package update
import (
"flag"
"fmt"
"github.com/infobloxopen/atlas-cli/atlas/application"
"os"

"github.com/infobloxopen/atlas-cli/atlas/application"
)

type StructureError struct {
Expand Down
5 changes: 4 additions & 1 deletion atlas/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func main() {
fmt.Printf("Command \"%s\" is not valid. Please choose one of %v\n", os.Args[1], commands.GetCommandNames())
os.Exit(1)
}
command.GetFlagset().Parse(os.Args[2:])
if err := command.GetFlagset().Parse(os.Args[2:]); err != nil {
fmt.Println("failed to parse flags:", err)
os.Exit(1)
}
if err := command.Run(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
8 changes: 6 additions & 2 deletions atlas/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func TestMain(m *testing.M) {
log.Print(string(out))
log.Fatalf("failed to run atlas init-app: %v", err)
}
defer e2eTeardown()
if len(os.Getenv("skip_teardown")) == 0 {
defer e2eTeardown()
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -88,7 +90,9 @@ func TestMain(m *testing.M) {

code := m.Run()
// os.Exit() does not respect defer statements
e2eTeardown()
if len(os.Getenv("skip_teardown")) == 0 {
e2eTeardown()
}
os.Exit(code)
}

Expand Down
116 changes: 58 additions & 58 deletions atlas/templates/cmd/server/config.go.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,65 +81,65 @@ const (

var (
// define flag overrides
flagServerAddress = pflag.String("server.address", defaultServerAddress, "adress of gRPC server")
flagServerPort = pflag.String("server.port", defaultServerPort, "port of gRPC server")

flagGatewayEnable = pflag.Bool("gateway.enable", defaultGatewayEnable, "enable gatway")
flagGatewayAddress = pflag.String("gateway.address", defaultGatewayAddress, "address of gateway server")
flagGatewayPort = pflag.String("gateway.port", defaultGatewayPort, "port of gateway server")
flagGatewayURL = pflag.String("gateway.endpoint", defaultGatewayURL, "endpoint of gateway server")
flagGatewaySwaggerFile = pflag.String("gateway.swaggerFile", defaultGatewaySwaggerFile, "directory of swagger.json file")

flagDatabaseEnable = pflag.Bool("database.enable", defaultDatabaseEnable, "enable database")
flagDatabaseDSN = pflag.String("database.dsn", defaultDatabaseDSN, "DSN of the database")
flagDatabaseType = pflag.String("database.type", defaultDatabaseType, "type of the database")
flagDatabaseAddress = pflag.String("database.address", defaultDatabaseAddress, "address of the database")
flagDatabasePort = pflag.String("database.port", defaultDatabasePort, "port of the database")
flagDatabaseName = pflag.String("database.name", defaultDatabaseName, "name of the database")
flagDatabaseUser = pflag.String("database.user", defaultDatabaseUser, "database username")
flagDatabasePassword = pflag.String("database.password", defaultDatabasePassword, "database password")
flagDatabaseSSL = pflag.String("database.ssl", defaultDatabaseSSL, "database ssl mode")
flagDatabaseOption = pflag.String("database.option", defaultDatabaseOption, "define custom option to db driver")

flagPubsubEnable = pflag.Bool("atlas.pubsub.enable", defaultPubsubEnable, "enable application with pubsub")
flagPubsubAddress = pflag.String("atlas.pubsub.address", defaultPubsubAddress, "address or FQDN of the pubsub service")
flagPubsubPort = pflag.String("atlas.pubsub.port", defaultPubsubPort, "port of the pubsub service")
flagPubsubPublish = pflag.String("atlas.pubsub.publish", defaultPubsubPublish, "publisher topic")
flagPubsubSubscribe = pflag.String("atlas.pubsub.subscribe", defaultPubsubSubscribe, "subscriber topic")
flagPubsubSubscriberID = pflag.String("atlas.pubsub.subscriber.id", defaultPubsubSubscriberID, "subscriber id")


flagAuthzEnable = pflag.Bool("atlas.authz.enable", defaultAuthzEnable, "enable application with authorization")
flagAuthzAddress = pflag.String("atlas.authz.address", defaultAuthzAddress, "address or FQDN of the authorization service")
flagAuthzPort = pflag.String("atlas.authz.port", defaultAuthzPort, "port of the authorization service")

flagAuditEnable = pflag.Bool("atlas.audit.enable", defaultAuditEnable, "enable logging of gRPC requests on Atlas audit service")
flagAuditAddress = pflag.String("atlas.audit.address", defaultAuditAddress, "address or FQDN of Atlas audit log service")
flagAuditPort = pflag.String("atlas.audit.port", defaultAuditPort, "port of Atlas audit log service")

flagTaggingEnable = pflag.Bool("atlas.tagging.enable", defaultTaggingEnable, "enable tagging")
flagTaggingAddress = pflag.String("atlas.tagging.address", defaultTaggingAddress, "address or FQDN of Atlas tagging service")
flagTaggingPort = pflag.String("atlas.tagging.port", defaultTaggingPort, "port of Atlas tagging service")

flagInternalEnable = pflag.Bool("internal.enable", defaultInternalEnable, "enable internal http server")
flagInternalAddress = pflag.String("internal.address", defaultInternalAddress, "address of internal http server")
flagInternalPort = pflag.String("internal.port", defaultInternalPort, "port of internal http server")
flagInternalHealth = pflag.String("internal.health", defaultInternalHealth, "endpoint for health checks")
flagInternalReadiness = pflag.String("internal.readiness", defaultInternalReadiness, "endpoint for readiness checks")

flagConfigDirectory = pflag.String("config.source", defaultConfigDirectory, "directory of the configuration file")
flagConfigFile = pflag.String("config.file", defaultConfigFile, "directory of the configuration file")
flagSecretFile = pflag.String("config.secret.file", defaultSecretFile, "directory of the secrets configuration file")
flagApplicationID = pflag.String("app.id", defaultApplicationID, "identifier for the application")

flagKeepaliveTime = pflag.Int("config.keepalive.time", defaultKeepaliveTime, "default value, in seconds, of the keepalive time")
flagKeepaliveTimeout = pflag.Int("config.keepalive.timeout", defaultKeepaliveTimeout, "default value, in seconds, of the keepalive timeout")

flagLoggingLevel = pflag.String("logging.level", defaultLoggingLevel, "log level of application")
_ = pflag.String("server.address", defaultServerAddress, "adress of gRPC server")
_ = pflag.String("server.port", defaultServerPort, "port of gRPC server")

_ = pflag.Bool("gateway.enable", defaultGatewayEnable, "enable gatway")
_ = pflag.String("gateway.address", defaultGatewayAddress, "address of gateway server")
_ = pflag.String("gateway.port", defaultGatewayPort, "port of gateway server")
_ = pflag.String("gateway.endpoint", defaultGatewayURL, "endpoint of gateway server")
_ = pflag.String("gateway.swaggerFile", defaultGatewaySwaggerFile, "directory of swagger.json file")

_ = pflag.Bool("database.enable", defaultDatabaseEnable, "enable database")
_ = pflag.String("database.dsn", defaultDatabaseDSN, "DSN of the database")
_ = pflag.String("database.type", defaultDatabaseType, "type of the database")
_ = pflag.String("database.address", defaultDatabaseAddress, "address of the database")
_ = pflag.String("database.port", defaultDatabasePort, "port of the database")
_ = pflag.String("database.name", defaultDatabaseName, "name of the database")
_ = pflag.String("database.user", defaultDatabaseUser, "database username")
_ = pflag.String("database.password", defaultDatabasePassword, "database password")
_ = pflag.String("database.ssl", defaultDatabaseSSL, "database ssl mode")
_ = pflag.String("database.option", defaultDatabaseOption, "define custom option to db driver")

_ = pflag.Bool("atlas.pubsub.enable", defaultPubsubEnable, "enable application with pubsub")
_ = pflag.String("atlas.pubsub.address", defaultPubsubAddress, "address or FQDN of the pubsub service")
_ = pflag.String("atlas.pubsub.port", defaultPubsubPort, "port of the pubsub service")
_ = pflag.String("atlas.pubsub.publish", defaultPubsubPublish, "publisher topic")
_ = pflag.String("atlas.pubsub.subscribe", defaultPubsubSubscribe, "subscriber topic")
_ = pflag.String("atlas.pubsub.subscriber.id", defaultPubsubSubscriberID, "subscriber id")


_ = pflag.Bool("atlas.authz.enable", defaultAuthzEnable, "enable application with authorization")
_ = pflag.String("atlas.authz.address", defaultAuthzAddress, "address or FQDN of the authorization service")
_ = pflag.String("atlas.authz.port", defaultAuthzPort, "port of the authorization service")

_ = pflag.Bool("atlas.audit.enable", defaultAuditEnable, "enable logging of gRPC requests on Atlas audit service")
_ = pflag.String("atlas.audit.address", defaultAuditAddress, "address or FQDN of Atlas audit log service")
_ = pflag.String("atlas.audit.port", defaultAuditPort, "port of Atlas audit log service")

_ = pflag.Bool("atlas.tagging.enable", defaultTaggingEnable, "enable tagging")
_ = pflag.String("atlas.tagging.address", defaultTaggingAddress, "address or FQDN of Atlas tagging service")
_ = pflag.String("atlas.tagging.port", defaultTaggingPort, "port of Atlas tagging service")

_ = pflag.Bool("internal.enable", defaultInternalEnable, "enable internal http server")
_ = pflag.String("internal.address", defaultInternalAddress, "address of internal http server")
_ = pflag.String("internal.port", defaultInternalPort, "port of internal http server")
_ = pflag.String("internal.health", defaultInternalHealth, "endpoint for health checks")
_ = pflag.String("internal.readiness", defaultInternalReadiness, "endpoint for readiness checks")

_ = pflag.String("config.source", defaultConfigDirectory, "directory of the configuration file")
_ = pflag.String("config.file", defaultConfigFile, "directory of the configuration file")
_ = pflag.String("config.secret.file", defaultSecretFile, "directory of the secrets configuration file")
_ = pflag.String("app.id", defaultApplicationID, "identifier for the application")

_ = pflag.Int("config.keepalive.time", defaultKeepaliveTime, "default value, in seconds, of the keepalive time")
_ = pflag.Int("config.keepalive.timeout", defaultKeepaliveTimeout, "default value, in seconds, of the keepalive timeout")

_ = pflag.String("logging.level", defaultLoggingLevel, "log level of application")

{{ if .WithProfiler }}
flagProfilerEnabled = pflag.Bool("profiler.enable", defaultProfilerEnabled, "enable profiler by default false")
flagProfilerAddress = pflag.String("profiler.address", defaultProfilerAddress, "address of profiler server")
flagProfilerPort = pflag.String("profiler.port", defaultProfilerPort, "port of profiler server")
_ = pflag.Bool("profiler.enable", defaultProfilerEnabled, "enable profiler by default false")
_ = pflag.String("profiler.address", defaultProfilerAddress, "address of profiler server")
_ = pflag.String("profiler.port", defaultProfilerPort, "port of profiler server")
{{ end }}
)
4 changes: 3 additions & 1 deletion atlas/templates/cmd/server/main.go.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ func ServeExternal(logger *logrus.Logger) error {

func init() {
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
log.Fatal(err)
}
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AddConfigPath(viper.GetString("config.source"))
Expand Down
2 changes: 1 addition & 1 deletion atlas/templates/pkg/svc/zserver_test.go.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestGetVersion(t *testing.T) {
err, test.err,
)
}
res, err := server.GetVersion(context.Background(), &empty.Empty{})
res, _ := server.GetVersion(context.Background(), &empty.Empty{})
if res.Version != test.expected.Version {
t.Errorf("Unexpected version in response: %v - expected: %v",
res.Version, test.expected.Version,
Expand Down