Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 91 additions & 5 deletions pkg/api/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,30 @@ func TestRustMapsClient_GenerateCustom(t *testing.T) {

var response *RustMapsGenerateResponse
if req.MapParameters.Seed == "1" {
w.WriteHeader(http.StatusOK)
response = &RustMapsGenerateResponse{
Meta: RustMapsGenerateResponseMeta{
Status: "complete",
StatusCode: 200,
Errors: []string{},
},
}
} else if req.MapParameters.Seed == "1111" {
response = &RustMapsGenerateResponse{
Meta: RustMapsGenerateResponseMeta{
Status: "complete",
StatusCode: 201,
Errors: []string{},
},
}
} else if req.MapParameters.Seed == "11" {
response = &RustMapsGenerateResponse{
Meta: RustMapsGenerateResponseMeta{
Status: "complete",
StatusCode: 400,
Errors: []string{},
},
}
} else if req.MapParameters.Seed == "2" {
w.WriteHeader(http.StatusUnauthorized)
response = &RustMapsGenerateResponse{
Meta: RustMapsGenerateResponseMeta{
Status: "complete",
Expand All @@ -44,7 +58,6 @@ func TestRustMapsClient_GenerateCustom(t *testing.T) {
},
}
} else if req.MapParameters.Seed == "3" {
w.WriteHeader(http.StatusForbidden)
response = &RustMapsGenerateResponse{
Meta: RustMapsGenerateResponseMeta{
Status: "complete",
Expand All @@ -53,7 +66,6 @@ func TestRustMapsClient_GenerateCustom(t *testing.T) {
},
}
} else if req.MapParameters.Seed == "4" {
w.WriteHeader(http.StatusConflict)
response = &RustMapsGenerateResponse{
Meta: RustMapsGenerateResponseMeta{
Status: "complete",
Expand All @@ -62,7 +74,6 @@ func TestRustMapsClient_GenerateCustom(t *testing.T) {
},
}
} else {
w.WriteHeader(http.StatusInternalServerError)
response = &RustMapsGenerateResponse{
Meta: RustMapsGenerateResponseMeta{
Status: "error",
Expand All @@ -71,6 +82,7 @@ func TestRustMapsClient_GenerateCustom(t *testing.T) {
},
}
}
w.WriteHeader(response.Meta.StatusCode)
json.NewEncoder(w).Encode(response)
return
}
Expand Down Expand Up @@ -118,6 +130,55 @@ func TestRustMapsClient_GenerateCustom(t *testing.T) {
},
},
},
{
name: "GenerateCustom 201",
fields: fields{
apiURL: mockServer.URL,
apiKey: "test",
rateLimiter: &RateLimiter{},
},
args: args{
log: zap.NewNop(),
m: &types.Map{
Size: 3500,
Seed: "1111",
Staging: false,
SavedConfig: "default",
},
},
want: &RustMapsGenerateResponse{
Meta: RustMapsGenerateResponseMeta{
Status: "complete",
StatusCode: 201,
Errors: []string{},
},
},
},
{
name: "GenerateCustom 400",
fields: fields{
apiURL: mockServer.URL,
apiKey: "test",
rateLimiter: &RateLimiter{},
},
args: args{
log: zap.NewNop(),
m: &types.Map{
Size: 3500,
Seed: "11",
Staging: false,
SavedConfig: "default",
},
},
want: &RustMapsGenerateResponse{
Meta: RustMapsGenerateResponseMeta{
Status: "complete",
StatusCode: 400,
Errors: []string{},
},
},
wantErr: true,
},
{
name: "GenerateCustom 401",
fields: fields{
Expand Down Expand Up @@ -189,6 +250,31 @@ func TestRustMapsClient_GenerateCustom(t *testing.T) {
},
{
name: "GenerateCustom 500",
fields: fields{
apiURL: mockServer.URL,
apiKey: "test",
rateLimiter: &RateLimiter{},
},
args: args{
log: zap.NewNop(),
m: &types.Map{
Size: 3500,
Seed: "111",
Staging: false,
SavedConfig: "default",
},
},
want: &RustMapsGenerateResponse{
Meta: RustMapsGenerateResponseMeta{
Status: "complete",
StatusCode: 400,
Errors: []string{},
},
},
wantErr: true,
},
{
name: "GenerateCustom 500 part 2",
fields: fields{
apiURL: "http://localhost",
apiKey: "test",
Expand Down
12 changes: 12 additions & 0 deletions pkg/rustmaps/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (g *Generator) Download(log *zap.Logger, version string) error {
imageWithIconsTarget := filepath.Join(downloadsDir, fmt.Sprintf("%s_icons.png", prefix))
thumbnailTarget := filepath.Join(downloadsDir, fmt.Sprintf("%s_thumbnail.png", prefix))
downloadLinksTarget := filepath.Join(downloadsDir, fmt.Sprintf("%s_download_links.json", prefix))
mapSpecsTarget := filepath.Join(downloadsDir, fmt.Sprintf("%s_specs.json", prefix))
// create a json file next to the rest that contains the download urls
log.Info("Downloading assets", zap.String("seed", m.Seed), zap.String("map_id", m.MapID))
links := DownloadLinks{
Expand All @@ -162,6 +163,17 @@ func (g *Generator) Download(log *zap.Logger, version string) error {
return err
}

mapSpecsData, err := json.MarshalIndent(status, "", " ")
if err != nil {
log.Error("Error marshalling JSON", zap.Error(err))
return err
}
log.Info("Writing map specs", zap.String("target", mapSpecsTarget))
if err := os.WriteFile(mapSpecsTarget, mapSpecsData, 0644); err != nil {
log.Error("Error writing JSON file", zap.Error(err))
return err
}

if err := g.DownloadFile(log, status.Data.DownloadURL, mapTarget); err != nil {
log.Error("Error downloading map", zap.String("seed", m.Seed), zap.Error(err))
return err
Expand Down