Skip to content

Commit

Permalink
Merge pull request #5 from awakari/split-writer-to-pipeline
Browse files Browse the repository at this point in the history
fix: usage constants
  • Loading branch information
akurilov authored Aug 6, 2023
2 parents f25e11b + 25c2f64 commit 227d052
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestClient_ReadUsage(t *testing.T) {
},
"fail": {
svcPermits: permits.NewServiceMock(),
subj: usage.SubjectPublishMessages,
subj: usage.SubjectPublishEvents,
userId: "fail",
err: permits.ErrInternal,
},
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestClient_ReadUsageLimit(t *testing.T) {
},
"both group and user missing": {
svcLimits: limits.NewServiceMock(),
subj: usage.SubjectPublishMessages,
subj: usage.SubjectPublishEvents,
userId: "group_missing",
},
"group present, user missing": {
Expand All @@ -116,7 +116,7 @@ func TestClient_ReadUsageLimit(t *testing.T) {
},
"fail": {
svcLimits: limits.NewServiceMock(),
subj: usage.SubjectPublishMessages,
subj: usage.SubjectPublishEvents,
userId: "fail",
err: limits.ErrInternal,
},
Expand Down
4 changes: 2 additions & 2 deletions api/grpc/limits/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestService_Get(t *testing.T) {
}{
"ok": {
userId: "user0",
subject: usage.SubjectPublishMessages,
subject: usage.SubjectPublishEvents,
lim: usage.Limit{
Count: 1,
UserId: "user0",
Expand All @@ -37,7 +37,7 @@ func TestService_Get(t *testing.T) {
},
"fail auth": {
userId: "fail_auth",
subject: usage.SubjectPublishMessages,
subject: usage.SubjectPublishEvents,
err: auth.ErrAuth,
},
}
Expand Down
4 changes: 2 additions & 2 deletions api/grpc/permits/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestService_GetUsage(t *testing.T) {
}{
"ok": {
userId: "user0",
subject: usage.SubjectPublishMessages,
subject: usage.SubjectPublishEvents,
out: usage.Usage{
Count: 1,
CountTotal: 2,
Expand All @@ -39,7 +39,7 @@ func TestService_GetUsage(t *testing.T) {
},
"fail auth": {
userId: "fail_auth",
subject: usage.SubjectPublishMessages,
subject: usage.SubjectPublishEvents,
err: auth.ErrAuth,
},
}
Expand Down
4 changes: 2 additions & 2 deletions api/grpc/subject/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ var ErrInvalidSubject = errors.New("unrecognized subject")

func Encode(src usage.Subject) (dst Subject, err error) {
switch src {
case usage.SubjectPublishMessages:
dst = Subject_PublishMessages
case usage.SubjectSubscriptions:
dst = Subject_Subscriptions
case usage.SubjectPublishEvents:
dst = Subject_PublishEvents
default:
err = fmt.Errorf("%w: %s", ErrInvalidSubject, src)
}
Expand Down
32 changes: 16 additions & 16 deletions api/grpc/subject/subject.pb.go

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

6 changes: 3 additions & 3 deletions api/grpc/subject/subject.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ option go_package = "github.com/awakari/client-sdk-go/api/grpc/subject";

enum Subject {
Undefined = 0;
PublishMessages = 1;
Subscriptions = 2;
}
Subscriptions = 1;
PublishEvents = 2;
}
4 changes: 2 additions & 2 deletions int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestPublicApiUsage(t *testing.T) {

// Get the initial Publish Messages API Usage
var usagePubMsgsStart usage.Usage
usagePubMsgsStart, err = client.ReadUsage(ctx, userId, usage.SubjectPublishMessages)
usagePubMsgsStart, err = client.ReadUsage(ctx, userId, usage.SubjectPublishEvents)
assert.Nil(t, err)

// Write a Message
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestPublicApiUsage(t *testing.T) {

// Check the Publish Messages API Usage change
var usagePubMsgs usage.Usage
usagePubMsgs, err = client.ReadUsage(ctx, userId, usage.SubjectPublishMessages)
usagePubMsgs, err = client.ReadUsage(ctx, userId, usage.SubjectPublishEvents)
assert.Nil(t, err)
assert.Equal(t, usagePubMsgsStart.Count+1, usagePubMsgs.Count)
assert.Equal(t, usagePubMsgsStart.CountTotal+1, usagePubMsgs.CountTotal)
Expand Down
4 changes: 2 additions & 2 deletions model/usage/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ type Subject int

const (
SubjectUndefined Subject = iota
SubjectPublishMessages
SubjectSubscriptions
SubjectPublishEvents
)

func (s Subject) String() string {
return [...]string{
"SubjectUndefined",
"SubjectPublishMessages",
"SubjectSubscriptions",
"SubjectPublishEvents",
}[s]
}

0 comments on commit 227d052

Please sign in to comment.