Skip to content

Commit

Permalink
lagi di service :
Browse files Browse the repository at this point in the history
upload, extract, tinggal verify
  • Loading branch information
wejick committed Nov 21, 2020
1 parent d8e0873 commit 2bf4818
Show file tree
Hide file tree
Showing 7 changed files with 550 additions and 105 deletions.
3 changes: 2 additions & 1 deletion internal/artifact/repo/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ type ArtifactList struct {
// Repo interface to operate with artifact
type Repo interface {
GetArtifactList(pageNum int64, rows int64) (ArtifactList, error)
PutTarballToFile(tarball *string) error
PutTarballToFile(tarball *string, taskUUID string) error
ExtractSubmittedTarball(taskUUID string) error
}
171 changes: 171 additions & 0 deletions internal/artifact/repo/artifact_repo_moq.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 40 additions & 1 deletion internal/artifact/repo/file_impl.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package repo

import (
"encoding/base64"
"io/ioutil"
"os"
"path/filepath"
"strings"

model "github.com/blankon/irgsh-go/internal/artifact/model"

tar "github.com/blankon/irgsh-go/pkg/tar"
)

// FileRepo interface with file system based artifact information
Expand Down Expand Up @@ -38,7 +43,36 @@ func (A *FileRepo) GetArtifactList(pageNum int64, rows int64) (artifactsList Art
}

// PutTarballToFile not it's just general function to write string of base64 to file
func (A *FileRepo) PutTarballToFile(tarball *string) (err error) {
func (A *FileRepo) PutTarballToFile(tarball *string, taskUUID string) (err error) {

This comment has been minimized.

Copy link
@herpiko

herpiko Nov 22, 2020

Member

@wejick are you focussing on #75 ? If so, I'll take #96 and then this parameter will be shifted to buffer.

This comment has been minimized.

Copy link
@wejick

wejick Nov 26, 2020

Author Collaborator

I'm confused, don't understand


// create artifact directory
submissionDir := A.generateSubmissionPath(taskUUID)
err = os.MkdirAll(submissionDir, os.ModeDir)
if err != nil {
return
}

// write the tarball
filePath := submissionDir + "/" + taskUUID + ".tar.gz"
buff, err := base64.StdEncoding.DecodeString(*tarball)
if err != nil {
return
}
err = ioutil.WriteFile(filePath, buff, 07440)
if err != nil {
return
}

return
}

// ExtractSubmittedTarball ...
func (A *FileRepo) ExtractSubmittedTarball(taskUUID string) (err error) {
submissionDir := A.generateSubmissionPath(taskUUID)
filePath := submissionDir + "/" + taskUUID + ".tar.gz"

err = tar.ExtractTarball(filePath, submissionDir)

return
}

Expand All @@ -49,3 +83,8 @@ func getArtifactFilename(filePath string) (fileName string) {
}
return
}

func (A *FileRepo) generateSubmissionPath(taskUUID string) (path string) {
path = A.Workdir + "/submissions/" + taskUUID
return
}
37 changes: 36 additions & 1 deletion internal/artifact/repo/file_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func TestMain(m *testing.M) {
file002.Close()

exitVal := m.Run()
// time.Sleep(2 * time.Second)

// clean up test directory
os.RemoveAll("./artifacts")
Expand Down Expand Up @@ -106,3 +105,39 @@ func TestFileRepo_GetArtifactList(t *testing.T) {
})
}
}

func TestFileRepo_generateSubmissionPath(t *testing.T) {
type fields struct {
Workdir string
}
type args struct {
taskUUID string
}
tests := []struct {
name string
fields fields
args args
wantPath string
}{
{
name: "empty",
wantPath: "/submissions/",
},
{
name: "complete",
fields: fields{Workdir: "/home/workingdir"},
args: args{taskUUID: "randomnumberhere"},
wantPath: "/home/workingdir/submissions/randomnumberhere",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
A := &FileRepo{
Workdir: tt.fields.Workdir,
}
if gotPath := A.generateSubmissionPath(tt.args.taskUUID); gotPath != tt.wantPath {
t.Errorf("FileRepo.generateSubmissionPath() = %v, want %v", gotPath, tt.wantPath)
}
})
}
}
13 changes: 12 additions & 1 deletion internal/artifact/service/artifact.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package service

import (
"errors"
"time"

artifactModel "github.com/blankon/irgsh-go/internal/artifact/model"
Expand Down Expand Up @@ -63,7 +64,17 @@ func (A *ArtifactService) SubmitPackage(tarball string) (job SubmissionJob, err

submittedJob.TaskUUID = generateSubmissionUUID(submittedJob.Timestamp)

// err = A.repo.(tarball)
err = A.repo.PutTarballToFile(&tarball, submittedJob.TaskUUID)
if err != nil {
return job, errors.New("Can't store tarball " + err.Error())
}

err = A.repo.ExtractSubmittedTarball(submittedJob.TaskUUID)
if err != nil {
return job, errors.New("Can't extract tarball " + err.Error())
}

// verify the package

return
}
Expand Down
Loading

0 comments on commit 2bf4818

Please sign in to comment.