From f50a3a4d5553b826adb862877b434372574695d5 Mon Sep 17 00:00:00 2001 From: eleven26 Date: Tue, 4 Apr 2023 11:17:12 +0800 Subject: [PATCH] Add integration tests to workflow. --- .github/workflows/go.yml | 33 ++++++++++++++++++++++++++++++++- drivers/minio/minio_test.go | 9 ++++++++- drivers/minio/store.go | 13 +++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 4955225..fa753fc 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -8,7 +8,7 @@ on: jobs: - build: + unit-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -25,3 +25,34 @@ jobs: uses: codecov/codecov-action@v3 with: files: ./coverage.xml + + integration-test: + runs-on: ubuntu-latest + needs: unit-test + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.18 + + - name: Start UP MinIO + uses: infleet/minio-action@v0.0.1 + with: + port: "9000" + version: "latest" + username: ${{ secrets.MINIO_SERVER_ACCESS_KEY }} + password: ${{ secrets.MINIO_SERVER_SECRET_KEY }} + + - name: Create .goss.yml + env: + GOSS_YML: ${{ secrets.GOSS_YML }} + run: | + cat < ~/.goss.yml + $GOSS_YML + EOF + + - name: Integration Test + run: | + make integration diff --git a/drivers/minio/minio_test.go b/drivers/minio/minio_test.go index e9bd941..f4a7117 100644 --- a/drivers/minio/minio_test.go +++ b/drivers/minio/minio_test.go @@ -53,6 +53,11 @@ func init() { testdata = filepath.Join(utils.RootDir(), "testdata") fooPath = filepath.Join(testdata, "foo.txt") localFooPath = filepath.Join(testdata, "foo1.txt") + + err = store.CreateBucketIfNotExists() + if err != nil { + log.Fatal(err) + } } func setUp(t *testing.T) { @@ -216,7 +221,7 @@ func TestFiles(t *testing.T) { assert.Equal(t, today, files[0].LastModified().Format("2006-01-02")) } -func aTestAb(t *testing.T) { +func putFiles(t *testing.T) { dir := "test_all/" for i := 1; i <= 200; i++ { @@ -226,6 +231,8 @@ func aTestAb(t *testing.T) { } func TestFilesWithMultiPage(t *testing.T) { + putFiles(t) + // Testdata was prepared before. dir := "test_all/" diff --git a/drivers/minio/store.go b/drivers/minio/store.go index f84264c..6e42f0a 100644 --- a/drivers/minio/store.go +++ b/drivers/minio/store.go @@ -29,6 +29,19 @@ func (s *Store) Put(key string, r io.Reader) error { return err } +func (s *Store) CreateBucketIfNotExists() error { + exists, err := s.client.BucketExists(context.Background(), s.config.Bucket) + if err != nil { + return err + } + + if !exists { + return s.client.MakeBucket(context.Background(), s.config.Bucket, minio.MakeBucketOptions{}) + } + + return nil +} + func (s *Store) putFile(key string, f *os.File) error { fi, err := f.Stat() if err != nil {