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

Migrate dep to go modules #69

Merged
merged 23 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/scripts/code-coverage.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
GOPATH=`go env GOPATH 2>/dev/null`
go test ./... -coverprofile cover.out
go test -v ./... -coverprofile cover.out
1 change: 0 additions & 1 deletion .github/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh

go get github.com/alecthomas/gometalinter && gometalinter --install
go generate . ./operations
go install . ./operations
4 changes: 1 addition & 3 deletions .github/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ perform() {
}

check go "needs go from http://golang.org"
check $GOPATH/bin/gometalinter "needs gometalinter from https://github.com/alecthomas/gometalinter"

perform linters gometalinter --fast --aggregate
perform tests go test ./...
perform tests go test -v ./...

echo "\x1B[38;5;2msuccess.\x1B[0m"
22 changes: 16 additions & 6 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,29 @@ jobs:
env:
GOPATH: ${{ github.workspace }}
WORKDIR: src/github.com/${{ github.repository }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

strategy:
matrix:
go: [ '1.21', '1.20', '1.19', '1.18', '1.17' ]
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v4
with:
go-version: "1.15" # Old Go version needed to run "go test"
go-version: ${{ matrix.go }}
cache: false

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
path: ${{ env.WORKDIR }}

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
working-directory: ${{ env.WORKDIR }}

- name: Build
working-directory: ${{ env.WORKDIR }}
run: .github/scripts/setup.sh
Expand All @@ -38,6 +46,8 @@ jobs:

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
with:
projectBaseDir: ${{ env.WORKDIR }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
53 changes: 30 additions & 23 deletions .github/workflows/v1-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,39 @@ jobs:
name: Build
runs-on: ubuntu-latest
env:
GOPATH: ${{ github.workspace }}
WORKDIR: src/github.com/${{ github.repository }}

strategy:
matrix:
go: [ '1.15', '1.14', '1.13', '1.12' ]
go: [ '1.21', '1.20', '1.19', '1.18', '1.17' ]
danfowler marked this conversation as resolved.
Show resolved Hide resolved

steps:

- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
path: ${{ env.WORKDIR }}

- name: Build
working-directory: ${{ env.WORKDIR }}
run: .github/scripts/setup.sh

- name: Test
working-directory: ${{ env.WORKDIR }}
env:
OMISE_PKEY: pkey_test_xxx
OMISE_SKEY: skey_test_xxx
run: .github/scripts/test.sh
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
cache: false

- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0
path: ${{ env.WORKDIR }}

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
working-directory: ${{ env.WORKDIR }}

- name: Build
working-directory: ${{ env.WORKDIR }}
run: .github/scripts/setup.sh

- name: Test
working-directory: ${{ env.WORKDIR }}
env:
OMISE_PKEY: pkey_test_xxx
OMISE_SKEY: skey_test_xxx
GOPATH: ${{ github.workspace }}
run: .github/scripts/test.sh
30 changes: 0 additions & 30 deletions Gopkg.lock

This file was deleted.

25 changes: 0 additions & 25 deletions Gopkg.toml

This file was deleted.

4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"fmt"
"go/build"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -178,7 +178,7 @@ func (c *Client) Do(result interface{}, operation internal.Operation) error {
return err
}

buffer, err := ioutil.ReadAll(resp.Body)
buffer, err := io.ReadAll(resp.Body)
if err != nil {
return &ErrTransport{err, buffer}
}
Expand Down
10 changes: 0 additions & 10 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ import (
r "github.com/stretchr/testify/require"
)

var createTokenOp = &operations.CreateToken{
Name: "Chakrit Wichian",
Number: "4242424242424242",
ExpirationMonth: 2,
ExpirationYear: 2018,
SecurityCode: "123",
City: "Bangkok",
PostalCode: "10210",
}

func TestNewClient(t *testing.T) {
pkey, skey := testutil.Keys()

Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/omise/omise-go

go 1.16

require github.com/stretchr/testify v1.8.4
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion internal/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ type Endpoint string

const (
API Endpoint = "https://api.omise.co"
Vault = "https://vault.omise.co"
Vault Endpoint = "https://vault.omise.co"
)
16 changes: 8 additions & 8 deletions internal/testutil/fixtures_path.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package testutil

import (
"go/build"
"net/http"
"os"
"path/filepath"
"runtime"
"strings"
)

var FixtureBasePath = filepath.Join(
build.Default.GOPATH,
"src",
"github.com/omise/omise-go",
"testdata/fixtures",
)
func FixtureBasePath() string {
_, b, _, _ := runtime.Caller(0)
parentDir := strings.Replace(filepath.Dir(b), "internal/testutil", "", -1)
return filepath.Join(parentDir, "testdata/fixtures")
}

func FixturePath(req *http.Request) (int, string, error) {
fixpath := req.URL.Host + "/" +
req.URL.Path[1:] + "-" + strings.ToLower(req.Method) + ".json"

// resolve exact fixture filename
filename := filepath.Join(FixtureBasePath, fixpath)
filename := filepath.Join(FixtureBasePath(), fixpath)

if _, err := os.Lstat(filename); err != nil {
if !os.IsNotExist(err) {
return 500, "", err
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/fixtures_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type FixturesTransport struct {
}

func NewFixturesTransport() (*FixturesTransport, error) {
backing := http.NewFileTransport(http.Dir(FixtureBasePath))
backing := http.NewFileTransport(http.Dir(FixtureBasePath()))
return &FixturesTransport{backing}, nil
}

Expand Down
7 changes: 4 additions & 3 deletions internal/testutil/fixtures_transport_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package testutil

import (
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -39,10 +40,10 @@ func (test *fixturesHTTPTest) Test(t *testing.T) {
r.Equal(t, test.statusCode, resp.StatusCode)

defer resp.Body.Close()
respBytes, err := ioutil.ReadAll(resp.Body)
respBytes, err := io.ReadAll(resp.Body)
r.NoError(t, err)

fixBytes, err := ioutil.ReadFile(filepath.Join(FixtureBasePath, test.filename))
fixBytes, err := os.ReadFile(filepath.Join(FixtureBasePath(), test.filename))
r.NoError(t, err)
r.Equal(t, string(fixBytes), string(respBytes))
}
Expand Down
7 changes: 3 additions & 4 deletions internal/testutil/recorder_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package testutil
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand All @@ -29,20 +28,20 @@ func (transport *RecorderTransport) RoundTrip(req *http.Request) (*http.Response
return resp, err
}

file, err := os.Create(filepath.Join(FixtureBasePath, fixpath))
file, err := os.Create(filepath.Join(FixtureBasePath(), fixpath))
if err != nil {
return resp, err
}

reader := resp.Body
defer reader.Close()

buffer, err := ioutil.ReadAll(reader)
buffer, err := io.ReadAll(reader)
if err != nil {
return resp, err
}

resp.Body = ioutil.NopCloser(bytes.NewBuffer(buffer))
resp.Body = io.NopCloser(bytes.NewBuffer(buffer))
if _, err := io.Copy(file, bytes.NewBuffer(buffer)); err != nil {
return resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Main(m *testing.M) {
}

func LogObj(t *testing.T, obj interface{}) {
t.Log(fmt.Sprintf("%#v", obj))
t.Logf(fmt.Sprintf("%#v", obj))
}

func Require(t *testing.T, env string) {
Expand Down
4 changes: 2 additions & 2 deletions json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package omise_test

import (
"encoding/json"
"io/ioutil"
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -37,7 +37,7 @@ type JSONRoundtripTest struct {
func (test JSONRoundtripTest) Test(t *testing.T) {
t.Log(reflect.ValueOf(test.value).Elem().Type().Name())

inbytes, err := ioutil.ReadFile("testdata/objects/" + test.srcFile)
inbytes, err := os.ReadFile("testdata/objects/" + test.srcFile)
r.NoError(t, err)

err = json.Unmarshal(inbytes, test.value)
Expand Down
Loading