-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a setup script for friends posts, integration test started for …
…user feed gen, currently no mental health posts
- Loading branch information
Showing
7 changed files
with
469 additions
and
223 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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
pbcommon "github.com/kic/feed/pkg/proto/common" | ||
pbfeed "github.com/kic/feed/pkg/proto/feed" | ||
"google.golang.org/grpc/metadata" | ||
"io" | ||
"log" | ||
|
||
"google.golang.org/grpc" | ||
|
||
pbusers "github.com/kic/feed/pkg/proto/users" | ||
) | ||
|
||
func postsShouldBeInOrder(authctx context.Context, uid int64, client pbfeed.FeedClient) []*pbcommon.File { | ||
expectedOrder := map[int]string{ | ||
0:"Makefile4", | ||
1:"Makefile5", | ||
2:"Makefile1", | ||
3:"Makefile2", | ||
4:"Makefile6", | ||
5:"Makefile3", | ||
} | ||
|
||
feedRes, err := client.GenerateFeedForUser(authctx, &pbfeed.GenerateFeedForUserRequest{UserID: uid}) | ||
|
||
if err != nil { | ||
log.Fatalf("fail to get user ID: %v", err) | ||
} | ||
|
||
var files []*pbcommon.File | ||
|
||
for { | ||
recv, err := feedRes.Recv() | ||
if err == io.EOF { | ||
break | ||
} | ||
if err != nil { | ||
log.Fatalf("Got an error gneerating feed that should not occur: %v", err) | ||
} | ||
fmt.Printf("feed res: %v\n", recv.FileInfo) | ||
files = append(files, recv.FileInfo) | ||
} | ||
|
||
for idx, file := range files { | ||
|
||
if expectedOrder[idx] != file.FileName { | ||
log.Fatalf("File out of order! %v\nExpected %v", file, expectedOrder[idx] ) | ||
} | ||
} | ||
|
||
return files | ||
} | ||
|
||
func postsShouldHaveMentalHealthInjections() { | ||
|
||
} | ||
|
||
func main() { | ||
conn, err := grpc.Dial("test.api.keeping-it-casual.com:50051", grpc.WithInsecure()) | ||
if err != nil { | ||
log.Fatalf("fail to dial: %v", err) | ||
} | ||
defer conn.Close() | ||
client := pbfeed.NewFeedClient(conn) | ||
userClient := pbusers.NewUsersClient(conn) | ||
|
||
tokRes, err := userClient.GetJWTToken(context.Background(), &pbusers.GetJWTTokenRequest{ | ||
Username: "testuser", | ||
Password: "testpass", | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("fail to get token: %v", err) | ||
} | ||
|
||
md := metadata.Pairs("Authorization", fmt.Sprintf("Bearer %v", tokRes.Token)) | ||
ctx := metadata.NewOutgoingContext(context.Background(), md) | ||
|
||
res, err := userClient.GetUserByUsername(ctx, &pbusers.GetUserByUsernameRequest{Username: "testuser"}) | ||
if err != nil { | ||
log.Fatalf("fail to get user ID: %v", err) | ||
} | ||
|
||
uid := res.User.UserID | ||
|
||
postsShouldBeInOrder(ctx, uid, client) | ||
|
||
postsShouldHaveMentalHealthInjections() | ||
|
||
log.Print("Success") | ||
} |
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,193 @@ | ||
// This provides a script to upload files for the target test users friends so that a feed can be generated | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
|
||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/metadata" | ||
|
||
pbcommon "github.com/kic/feed/pkg/proto/common" | ||
pbmedia "github.com/kic/feed/pkg/proto/media" | ||
pbusers "github.com/kic/feed/pkg/proto/users" | ||
) | ||
|
||
//func | ||
|
||
func main() { | ||
conn, err := grpc.Dial("test.api.keeping-it-casual.com:50051", grpc.WithInsecure()) | ||
if err != nil { | ||
log.Fatalf("fail to dial: %v", err) | ||
} | ||
defer conn.Close() | ||
//client := pbfeed.NewFeedClient(conn) | ||
userClient := pbusers.NewUsersClient(conn) | ||
|
||
tokRes, err := userClient.GetJWTToken(context.Background(), &pbusers.GetJWTTokenRequest{ | ||
Username: "testuser", | ||
Password: "testpass", | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("fail to get token: %v", err) | ||
} | ||
|
||
md := metadata.Pairs("Authorization", fmt.Sprintf("Bearer %v", tokRes.Token)) | ||
ctx := metadata.NewOutgoingContext(context.Background(), md) | ||
|
||
buffer, err := ioutil.ReadFile("Makefile") | ||
|
||
if err != nil { | ||
log.Fatal("cannot read file: ", err) | ||
} | ||
|
||
mediaClient := pbmedia.NewMediaStorageClient(conn) | ||
|
||
req := &pbmedia.UploadFileRequest{ | ||
FileInfo: &pbcommon.File{ | ||
FileName: "Makefile1", | ||
FileLocation: "test", | ||
Metadata: map[string]string{ | ||
"userID": "30", | ||
"ext": "txt", | ||
"caption": "test", | ||
}, | ||
DateStored: &pbcommon.Date{ | ||
Year: 2021, | ||
Month: 3, | ||
Day: 2, | ||
}, | ||
}, | ||
File: buffer, | ||
} | ||
|
||
_, err = mediaClient.UploadFile(ctx, req) | ||
|
||
if err != nil { | ||
log.Fatal("cannot upload image: ", err) | ||
} | ||
|
||
req = &pbmedia.UploadFileRequest{ | ||
FileInfo: &pbcommon.File{ | ||
FileName: "Makefile2", | ||
FileLocation: "test", | ||
Metadata: map[string]string{ | ||
"userID": "30", | ||
"ext": "txt", | ||
"caption": "test", | ||
}, | ||
DateStored: &pbcommon.Date{ | ||
Year: 2021, | ||
Month: 2, | ||
Day: 1, | ||
}, | ||
}, | ||
File: buffer, | ||
} | ||
|
||
_, err = mediaClient.UploadFile(ctx, req) | ||
|
||
if err != nil { | ||
log.Fatal("cannot upload image: ", err) | ||
} | ||
|
||
req = &pbmedia.UploadFileRequest{ | ||
FileInfo: &pbcommon.File{ | ||
FileName: "Makefile3", | ||
FileLocation: "test", | ||
Metadata: map[string]string{ | ||
"userID": "30", | ||
"ext": "txt", | ||
"caption": "test", | ||
}, | ||
DateStored: &pbcommon.Date{ | ||
Year: 2020, | ||
Month: 2, | ||
Day: 1, | ||
}, | ||
}, | ||
File: buffer, | ||
} | ||
|
||
_, err = mediaClient.UploadFile(ctx, req) | ||
|
||
if err != nil { | ||
log.Fatal("cannot upload image: ", err) | ||
} | ||
|
||
req = &pbmedia.UploadFileRequest{ | ||
FileInfo: &pbcommon.File{ | ||
FileName: "Makefile4", | ||
FileLocation: "test", | ||
Metadata: map[string]string{ | ||
"userID": "31", | ||
"ext": "txt", | ||
"caption": "test", | ||
}, | ||
DateStored: &pbcommon.Date{ | ||
Year: 2021, | ||
Month: 5, | ||
Day: 1, | ||
}, | ||
}, | ||
File: buffer, | ||
} | ||
|
||
_, err = mediaClient.UploadFile(ctx, req) | ||
|
||
if err != nil { | ||
log.Fatal("cannot upload image: ", err) | ||
} | ||
|
||
req = &pbmedia.UploadFileRequest{ | ||
FileInfo: &pbcommon.File{ | ||
FileName: "Makefile5", | ||
FileLocation: "test", | ||
Metadata: map[string]string{ | ||
"userID": "31", | ||
"ext": "txt", | ||
"caption": "test", | ||
}, | ||
DateStored: &pbcommon.Date{ | ||
Year: 2021, | ||
Month: 4, | ||
Day: 1, | ||
}, | ||
}, | ||
File: buffer, | ||
} | ||
|
||
_, err = mediaClient.UploadFile(ctx, req) | ||
|
||
if err != nil { | ||
log.Fatal("cannot upload image: ", err) | ||
} | ||
|
||
req = &pbmedia.UploadFileRequest{ | ||
FileInfo: &pbcommon.File{ | ||
FileName: "Makefile6", | ||
FileLocation: "test", | ||
Metadata: map[string]string{ | ||
"userID": "31", | ||
"ext": "txt", | ||
"caption": "test", | ||
}, | ||
DateStored: &pbcommon.Date{ | ||
Year: 2020, | ||
Month: 2, | ||
Day: 1, | ||
}, | ||
}, | ||
File: buffer, | ||
} | ||
|
||
_, err = mediaClient.UploadFile(ctx, req) | ||
|
||
if err != nil { | ||
log.Fatal("cannot upload image: ", err) | ||
} | ||
} |
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
Oops, something went wrong.