Skip to content

chore: support to set the version #14

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

Merged
merged 3 commits into from
Jul 12, 2024
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
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ builds:
ldflags:
- -w
- -s
- -X github.com/linuxsuren/api-testing/pkg/version.version={{.Version}} -X github.com/linuxsuren/api-testing/pkg/version.commit={{.Commit}} -X github.com/linuxsuren/api-testing/pkg/version.date={{.Date}}
archives:
- name_template: "{{ .Binary }}-{{ .Os }}-{{ .Arch }}"
builds:
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ WORKDIR /workspace
COPY . .

RUN GOPROXY=${GOPROXY} go mod download
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s" -o atest-store-orm .
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 go build -ldflags "-w -s -X github.com/linuxsuren/api-testing/pkg/version.version=${VERSION}\
-X github.com/linuxsuren/api-testing/pkg/version.date=$(date +%Y-%m-%d)" -o atest-store-orm .

FROM ${BASE_IMAGE}

Expand Down
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd

import (
ext "github.com/linuxsuren/api-testing/pkg/extension"
"github.com/linuxsuren/api-testing/pkg/version"
"github.com/linuxsuren/atest-ext-store-orm/pkg"
"github.com/spf13/cobra"
)
Expand All @@ -31,15 +32,22 @@ func NewRootCommand() (c *cobra.Command) {
RunE: opt.runE,
}
opt.AddFlags(c.Flags())
c.Flags().BoolVarP(&opt.version, "version", "", false, "Print the version then exit")
return
}

func (o *option) runE(c *cobra.Command, args []string) (err error) {
if o.version {
c.Println(version.GetVersion())
c.Println(version.GetDate())
return
}
remoteServer := pkg.NewRemoteServer()
err = ext.CreateRunner(o.Extension, c, remoteServer)
return
}

type option struct {
*ext.Extension
version bool
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.2
toolchain go1.22.4

require (
github.com/linuxsuren/api-testing v0.0.18-0.20240712013124-33c89be15c83
github.com/linuxsuren/api-testing v0.0.18-0.20240712143814-6ce9363d5a07
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
gorm.io/driver/mysql v1.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/linuxsuren/api-testing v0.0.18-0.20240712013124-33c89be15c83 h1:NUGWAWp6fMc9qFERsP0TdJE6lTItEDI6F6v7tDkHNx8=
github.com/linuxsuren/api-testing v0.0.18-0.20240712013124-33c89be15c83/go.mod h1:8G3GZtQmSUHyqA/gZlSdFaDIveHQYbFInTibD7g3hMs=
github.com/linuxsuren/api-testing v0.0.18-0.20240712143814-6ce9363d5a07 h1:NmjqkiR+4KXjWs9H6wGmgQo7r7FJE+RED+E3EwAGsp4=
github.com/linuxsuren/api-testing v0.0.18-0.20240712143814-6ce9363d5a07/go.mod h1:8G3GZtQmSUHyqA/gZlSdFaDIveHQYbFInTibD7g3hMs=
github.com/linuxsuren/go-fake-runtime v0.0.4 h1:y+tvBuw6MKTCav8Bo5HWwaXhBx1Z//VAvqI3gpOWqvw=
github.com/linuxsuren/go-fake-runtime v0.0.4/go.mod h1:zmh6J78hSnWZo68faMA2eKOdaEp8eFbERHi3ZB9xHCQ=
github.com/linuxsuren/unstructured v0.0.1 h1:ilUA8MUYbR6l9ebo/YPV2bKqlf62bzQursDSE+j00iU=
Expand Down
12 changes: 11 additions & 1 deletion pkg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
"github.com/linuxsuren/api-testing/pkg/version"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/driver/sqlite"
)

type dbserver struct {
Expand Down Expand Up @@ -273,6 +273,16 @@ func (s *dbserver) Verify(ctx context.Context, in *server.Empty) (reply *server.
}
return
}

func (s *dbserver) GetVersion(context.Context, *server.Empty) (ver *server.Version, err error) {
ver = &server.Version{
Version: version.GetVersion(),
Commit: version.GetCommit(),
Date: version.GetDate(),
}
return
}

func (s *dbserver) PProf(ctx context.Context, in *server.PProfRequest) (data *server.PProfData, err error) {
log.Println("pprof", in.Name)

Expand Down
42 changes: 42 additions & 0 deletions pkg/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,43 @@ func TestNewRemoteServer(t *testing.T) {
assert.NoError(t, err)
assert.False(t, reply.Ready)
})

t.Run("invalid orm driver", func(t *testing.T) {
remoteServer := NewRemoteServer()
assert.NotNil(t, remoteServer)
defaultCtx := remote.WithIncomingStoreContext(context.TODO(), &atest.Store{
Properties: map[string]string{
"driver": "invalid",
},
})
_, err := remoteServer.ListTestSuite(defaultCtx, &server.Empty{})
assert.Error(t, err)
})

t.Run("invalid mysql config", func(t *testing.T) {
remoteServer := NewRemoteServer()
assert.NotNil(t, remoteServer)
defaultCtx := remote.WithIncomingStoreContext(context.TODO(), &atest.Store{
Properties: map[string]string{
"driver": "mysql",
},
})
_, err := remoteServer.ListTestSuite(defaultCtx, &server.Empty{})
assert.Error(t, err)
})

t.Run("invalid postgres config", func(t *testing.T) {
remoteServer := NewRemoteServer()
assert.NotNil(t, remoteServer)
defaultCtx := remote.WithIncomingStoreContext(context.TODO(), &atest.Store{
Properties: map[string]string{
"driver": "postgres",
},
URL: "0.0.0.0:-123",
})
_, err := remoteServer.ListTestSuite(defaultCtx, &server.Empty{})
assert.Error(t, err)
})
}

func TestSQLite(t *testing.T) {
Expand Down Expand Up @@ -183,4 +220,9 @@ func TestSQLite(t *testing.T) {
_, err := remoteServer.PProf(defaultCtx, &server.PProfRequest{})
assert.NoError(t, err)
})

t.Run("GetVersion", func(t *testing.T) {
_, err := remoteServer.GetVersion(defaultCtx, &server.Empty{})
assert.NoError(t, err)
})
}
Loading