Skip to content

Commit

Permalink
Merge pull request #22 from whywaita/refacor/resourcetype
Browse files Browse the repository at this point in the history
ResourceType change string to int, can catch invalid input
  • Loading branch information
whywaita authored Feb 12, 2021
2 parents 4b27fa2 + 2e7017f commit c38cc69
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 67 deletions.
48 changes: 0 additions & 48 deletions pkg/datastore/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"strings"
"time"

pb "github.com/whywaita/myshoes/api/proto"

uuid "github.com/satori/go.uuid"

"github.com/whywaita/myshoes/pkg/gh"
Expand Down Expand Up @@ -81,48 +79,6 @@ func (t *Target) OwnerRepo() (string, string) {
return owner, repo
}

// ResourceType is runner machine spec
type ResourceType string

// ResourceTypes variables
const (
Nano ResourceType = "nano"
Micro = "micro"
Small = "small"
Medium = "medium"
Large = "large"
XLarge = "xlarge"
XLarge2 = "2xlarge"
XLarge3 = "3xlarge"
XLarge4 = "4xlarge"
)

// ToPb convert type of protobuf
func (r ResourceType) ToPb() pb.ResourceType {
switch r {
case Nano:
return pb.ResourceType_Nano
case Micro:
return pb.ResourceType_Micro
case Small:
return pb.ResourceType_Small
case Medium:
return pb.ResourceType_Medium
case Large:
return pb.ResourceType_Large
case XLarge:
return pb.ResourceType_XLarge
case XLarge2:
return pb.ResourceType_XLarge2
case XLarge3:
return pb.ResourceType_XLarge3
case XLarge4:
return pb.ResourceType_XLarge4
}

return pb.ResourceType_Unknown
}

// Status is status for target
type Status string

Expand All @@ -134,10 +90,6 @@ const (
TargetStatusErr = "error"
)

func (r *ResourceType) String() string {
return string(*r)
}

// Job is a runner job
type Job struct {
UUID uuid.UUID `db:"uuid"`
Expand Down
6 changes: 3 additions & 3 deletions pkg/datastore/mysql/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestMySQL_EnqueueJob(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
}); err != nil {
t.Fatalf("failed to create target: %+v", err)
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestMySQL_ListJobs(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
}); err != nil {
t.Fatalf("failed to create target: %+v", err)
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestMySQL_DeleteJob(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
}); err != nil {
t.Fatalf("failed to create target: %+v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/datastore/mysql/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestMySQL_CreateRunner(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
}); err != nil {
t.Fatalf("failed to create target: %+v", err)
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestMySQL_ListRunners(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
}); err != nil {
t.Fatalf("failed to create target: %+v", err)
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestMySQL_GetRunner(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
}); err != nil {
t.Fatalf("failed to create target: %+v", err)
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestMySQL_DeleteRunner(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
}); err != nil {
t.Fatalf("failed to create target: %+v", err)
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/datastore/mysql/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestMySQL_CreateTarget(t *testing.T) {
GHEDomain: sql.NullString{
Valid: false,
},
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
},
want: &datastore.Target{
UUID: testTargetID,
Expand All @@ -48,7 +48,7 @@ func TestMySQL_CreateTarget(t *testing.T) {
Valid: false,
},
Status: datastore.TargetStatusInitialize,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
},
err: false,
},
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestMySQL_GetTarget(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
})
if err != nil {
t.Fatalf("failed to create target: %+v", err)
Expand All @@ -100,7 +100,7 @@ func TestMySQL_GetTarget(t *testing.T) {
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
Status: datastore.TargetStatusInitialize,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
},
err: false,
},
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestMySQL_GetTargetByScope(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
})
if err != nil {
t.Fatalf("failed to create target: %+v", err)
Expand All @@ -148,7 +148,7 @@ func TestMySQL_GetTargetByScope(t *testing.T) {
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
Status: datastore.TargetStatusInitialize,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
},
err: false,
},
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestMySQL_ListTargets(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
}); err != nil {
t.Fatalf("failed to create target: %+v", err)
}
Expand All @@ -196,7 +196,7 @@ func TestMySQL_ListTargets(t *testing.T) {
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
Status: datastore.TargetStatusInitialize,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
},
},
err: false,
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestMySQL_DeleteTarget(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
}); err != nil {
t.Fatalf("failed to create target: %+v", err)
}
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestMySQL_UpdateStatus(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
Status: datastore.TargetStatusActive,
StatusDescription: sql.NullString{
String: "",
Expand All @@ -309,7 +309,7 @@ func TestMySQL_UpdateStatus(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
Status: datastore.TargetStatusRunning,
StatusDescription: sql.NullString{
String: "job-id",
Expand All @@ -325,7 +325,7 @@ func TestMySQL_UpdateStatus(t *testing.T) {
UUID: testTargetID,
Scope: testScopeRepo,
GitHubPersonalToken: testGitHubPersonalToken,
ResourceType: "nano",
ResourceType: datastore.ResourceTypeNano,
}); err != nil {
t.Fatalf("failed to create target: %+v", err)
}
Expand Down
Loading

0 comments on commit c38cc69

Please sign in to comment.