This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from duck8823/rearchitecture
RE: ARCHITECTURE
- Loading branch information
Showing
163 changed files
with
10,153 additions
and
5,900 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,6 @@ vendor | |
# app | ||
/config.yml | ||
release-notes.txt | ||
duci | ||
/duci | ||
duci.exe | ||
dist |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package application | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/duck8823/duci/domain/model/job" | ||
"github.com/duck8823/duci/domain/model/job/target/github" | ||
"net/url" | ||
) | ||
|
||
var ctxKey = "duci_job" | ||
|
||
// BuildJob represents once of job | ||
type BuildJob struct { | ||
ID job.ID | ||
TargetSource *github.TargetSource | ||
TaskName string | ||
TargetURL *url.URL | ||
} | ||
|
||
// ContextWithJob set parent context BuildJob and returns it. | ||
func ContextWithJob(parent context.Context, job *BuildJob) context.Context { | ||
return context.WithValue(parent, &ctxKey, job) | ||
} | ||
|
||
// BuildJobFromContext extract BuildJob from context | ||
func BuildJobFromContext(ctx context.Context) (*BuildJob, error) { | ||
val := ctx.Value(&ctxKey) | ||
if val == nil { | ||
return nil, fmt.Errorf("context value '%s' should not be null", ctxKey) | ||
} | ||
buildJob, ok := val.(*BuildJob) | ||
if !ok { | ||
return nil, fmt.Errorf("invalid type in context '%s'", ctxKey) | ||
} | ||
return buildJob, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package application_test | ||
|
||
import ( | ||
"context" | ||
"github.com/duck8823/duci/application" | ||
"github.com/duck8823/duci/domain/model/job" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/uuid" | ||
"testing" | ||
) | ||
|
||
func TestContextWithJob(t *testing.T) { | ||
// given | ||
want := &application.BuildJob{ | ||
ID: job.ID(uuid.New()), | ||
} | ||
|
||
// and | ||
ctx := application.ContextWithJob(context.Background(), want) | ||
|
||
// when | ||
got := ctx.Value(application.GetCtxKey()) | ||
|
||
// then | ||
if !cmp.Equal(got, want) { | ||
t.Errorf("must be equal, but %+v", cmp.Diff(got, want)) | ||
} | ||
} | ||
|
||
func TestBuildJobFromContext(t *testing.T) { | ||
t.Run("with value", func(t *testing.T) { | ||
// given | ||
want := &application.BuildJob{ | ||
ID: job.ID(uuid.New()), | ||
} | ||
|
||
sut := context.WithValue(context.Background(), application.GetCtxKey(), want) | ||
|
||
// when | ||
got, err := application.BuildJobFromContext(sut) | ||
|
||
// then | ||
if err != nil { | ||
t.Errorf("error must be nil, but got %+v", err) | ||
} | ||
|
||
// and | ||
if !cmp.Equal(got, want) { | ||
t.Errorf("must be equal, but %+v", cmp.Diff(got, want)) | ||
} | ||
}) | ||
|
||
t.Run("without value", func(t *testing.T) { | ||
sut := context.Background() | ||
|
||
// when | ||
got, err := application.BuildJobFromContext(sut) | ||
|
||
// then | ||
if err == nil { | ||
t.Error("error must not be nil") | ||
} | ||
|
||
// and | ||
if got != nil { | ||
t.Errorf("must be nil, but got %+v", got) | ||
} | ||
}) | ||
|
||
} |
Oops, something went wrong.