Skip to content

Commit

Permalink
Merge branch 'chore/gcs_emulator' into chore/new-method-on-gcs
Browse files Browse the repository at this point in the history
  • Loading branch information
soneda-yuya authored Jan 27, 2025
2 parents 364daa4 + 77698dd commit 2582d68
Show file tree
Hide file tree
Showing 16 changed files with 542 additions and 107 deletions.
3 changes: 2 additions & 1 deletion go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwc
github.com/apache/arrow/go/v12 v12.0.0 h1:xtZE63VWl7qLdB0JObIXvvhGjoVNrQ9ciIHG2OK5cmc=
github.com/apache/thrift v0.16.0 h1:qEy6UW60iVOlUy+b9ZR0d5WzUWYGOo4HfopoyBaNmoY=
github.com/aws/aws-sdk-go v1.35.5 h1:doSEOxC0UkirPcle20Rc+1kAhJ4Ip+GSEeZ3nKl7Qlk=
github.com/aws/smithy-go v1.20.1 h1:4SZlSlMr36UEqC7XOyRVb27XMeZubNcBNN+9IgEPIQw=
github.com/bradfitz/gomemcache v0.0.0-20170208213004-1952afaa557d h1:7IjN4QP3c38xhg6wz8R3YjoU+6S9e7xBc0DAVLLIpHE=
github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk=
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
Expand Down Expand Up @@ -192,6 +191,7 @@ github.com/gobuffalo/packd v0.1.0 h1:4sGKOD8yaYJ+dek1FDkwcxCHA40M4kfKgFHx8N2kwbU
github.com/gobuffalo/packr/v2 v2.2.0 h1:Ir9W9XIm9j7bhhkKE9cokvtTl1vBm62A/fene/ZCj6A=
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754 h1:tpom+2CJmpzAWj5/VEHync2rJGi+epHNIeRSWjzGA+4=
github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ=
github.com/golang/lint v0.0.0-20170918230701-e5d664eb928e h1:ior8LN6127GsA53E9mD9nH/oP/LVbJplmLH5V8o+/Uk=
Expand Down Expand Up @@ -258,6 +258,7 @@ github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 h1:AMFGa4R4MiIpsp
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 h1:+n/aFZefKZp7spd8DFdX7uMikMLXX4oubIzJF4kv/wI=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
github.com/pelletier/go-toml v1.7.0 h1:7utD74fnzVc/cpcyy8sjrlFr5vYpypUixARcHIMIGuI=
github.com/pierrec/lz4/v4 v4.1.15 h1:MO0/ucJhngq7299dKLwIMtgTfbkoSPF6AoMYDd8Q4q0=
github.com/pierrre/gotestcover v0.0.0-20160517101806-924dca7d15f0 h1:i5VIxp6QB8oWZ8IkK8zrDgeT6ORGIUeiN+61iETwJbI=
Expand Down
10 changes: 5 additions & 5 deletions server/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ func aligningJSON(t *testing.T, str string) string {
return string(strBytes)
}

func toJSONString(v interface{}) (string, error) {
jsonData, err := json.Marshal(v)
if err != nil {
return "", fmt.Errorf("failed to marshal JSON: %w", err)
func ValueDump(val *httpexpect.Value) {
if data, ok := val.Raw().(map[string]interface{}); ok {
if text, err := json.MarshalIndent(data, "", " "); err == nil {
fmt.Println(string(text))
}
}
return string(jsonData), nil
}
41 changes: 29 additions & 12 deletions server/e2e/gql_asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,36 @@ func createAsset(t *testing.T, e *httpexpect.Expect, filePath string, coreSuppor
},
"query": CreateAssetMutation,
}
operations, err := toJSONString(requestBody)
assert.Nil(t, err)
return e.POST("/api/graphql").
WithHeader("Origin", "https://example.com").
WithHeader("authorization", "Bearer test").
WithHeader("X-Reearth-Debug-User", uID.String()).
WithMultipart().
WithFormField("operations", operations).
WithFormField("map", `{"0": ["variables.file"]}`).
WithFile("0", filePath).
Expect().
Status(http.StatusOK).
JSON()
return RequestWithMultipart(e, uID.String(), requestBody, filePath)
}

func createAssetFromFileData(t *testing.T, e *httpexpect.Expect, fileData []byte, coreSupport bool, teamId string) *httpexpect.Value {
tempFile, err := os.CreateTemp("", "requestBody-*.json")
if err != nil {
t.Fatalf("failed to create temp file: %v", err)
}
if _, err := tempFile.Write(fileData); err != nil {
t.Fatalf("failed to write to temp file: %v", err)
}
defer func() {
if cerr := tempFile.Close(); cerr != nil && err == nil {
err = cerr
}
if err := os.Remove(tempFile.Name()); err != nil {
t.Logf("failed to remove temp file: %v", err)
}
}()
requestBody := map[string]interface{}{
"operationName": "CreateAsset",
"variables": map[string]interface{}{
"teamId": teamId,
"coreSupport": coreSupport,
"file": nil,
},
"query": CreateAssetMutation,
}
return RequestWithMultipart(e, uID.String(), requestBody, tempFile.Name())
}

const GetAssetsQuery = `query GetAssets($teamId: ID!, $pagination: Pagination, $keyword: String, $sort: AssetSort) {
Expand Down
36 changes: 36 additions & 0 deletions server/e2e/gql_nlslayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,42 @@ func addNLSLayerSimple(e *httpexpect.Expect, sId string, title string, index int
return requestBody, res, layerId
}

func addNLSLayerSimpleByGeojson(e *httpexpect.Expect, sId string, url string, title string, index int) *httpexpect.Value {
requestBody := GraphQLRequest{
OperationName: "AddNLSLayerSimple",
Query: `mutation AddNLSLayerSimple($input: AddNLSLayerSimpleInput!) {
addNLSLayerSimple(input: $input) {
layers {
id
__typename
}
__typename
}
}`,
Variables: map[string]any{
"input": map[string]any{
"sceneId": sId,
"config": map[string]any{
"data": map[string]any{
"url": url,
"type": "geojson",
"value": nil,
"geojson": map[string]any{
"useAsResource": false,
},
},
},
"visible": true,
"layerType": "simple",
"title": title,
"index": index,
},
},
}

return Request(e, uID.String(), requestBody)
}

func removeNLSLayer(e *httpexpect.Expect, layerId string) (GraphQLRequest, *httpexpect.Value) {
requestBody := GraphQLRequest{
OperationName: "RemoveNLSLayer",
Expand Down
15 changes: 2 additions & 13 deletions server/e2e/gql_project_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,9 @@ func importProject(t *testing.T, e *httpexpect.Expect, filePath string) *httpexp
}
}`,
}
operations, err := toJSONString(requestBody)

assert.Nil(t, err)
r := e.POST("/api/graphql").
WithHeader("Origin", "https://example.com").
WithHeader("authorization", "Bearer test").
WithHeader("X-Reearth-Debug-User", uID.String()).
WithMultipart().
WithFormField("operations", operations).
WithFormField("map", `{"0": ["variables.file"]}`).
WithFile("0", filePath).
Expect().
Status(http.StatusOK).
JSON().
Object()
r := RequestWithMultipart(e, uID.String(), requestBody, filePath).Object()
projectData := r.Value("data").Object().Value("importProject").Object().Value("projectData")
projectData.NotNull()
return projectData.Object()
Expand Down
199 changes: 199 additions & 0 deletions server/e2e/gql_validate_geojson_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package e2e

import (
"testing"
)

func TestValidateGeoJsonOfAssets(t *testing.T) {
e := Server(t, baseSeeder)

teamId := wID.String()
pId := createProject(e, "test")
_, _, sId := createScene(e, pId)

tests := []struct {
name string
data []byte
hasError bool
}{
{
name: "Valid Feature",
data: []byte(`
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [100.0, 0.0]
},
"properties": {}
}
`),
hasError: false,
},
{
name: "Valid FeatureCollection",
data: []byte(`
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [100.0, 0.0]
},
"properties": {}
}
]
}
`),
hasError: false,
},
{
name: "Valid Point coordinates",
data: []byte(`
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [100.0]
},
"properties": {}
}
]
}
`),
hasError: false,
},
{
name: "Invalid BBox",
data: []byte(`
{
"type": "FeatureCollection",
"bbox": [100.0, 0.0, 101.0, 1.0],
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [100.0, 0.0]
},
"properties": {}
}
]
}
`),
hasError: false,
},
{
name: "Missing Geometry",
data: []byte(`
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {}
}
]
}
`),
hasError: true,
},
{
name: "Invalid MultiPoint coordinates",
data: []byte(`
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "MultiPoint",
"coordinates": [[100.0, 0.0], [200.0]]
},
"properties": {}
}
]
}
`),
hasError: true,
},
{
name: "Invalid LineString coordinates",
data: []byte(`
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[100.0, 0.0]]
},
"properties": {}
}
]
}
`),
hasError: true,
},
{
name: "Polygon with invalid ring",
data: []byte(`
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]]
},
"properties": {}
}
]
}
`),
hasError: false,
},
{
name: "Unsupported Geometry type",
data: []byte(`
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "UnsupportedType",
"coordinates": [100.0, 0.0]
},
"properties": {}
}
]
}
`),
hasError: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res := createAssetFromFileData(t, e, []byte(tt.data), true, teamId)
title := res.Path("$.data.createAsset.asset.name").Raw().(string)
url := res.Path("$.data.createAsset.asset.url").Raw().(string)
res = addNLSLayerSimpleByGeojson(e, sId, url, title, 0)
// ValueDump(res)
if tt.hasError {
res.Object().Value("errors").Array().NotEmpty()
} else {
res.Object().NotContainsKey("errors")
}
})
}

}
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ require (
github.com/labstack/echo/v4 v4.11.4
github.com/mitchellh/mapstructure v1.5.0
github.com/oklog/ulid v1.3.1
github.com/paulmach/go.geojson v1.4.0
github.com/pkg/errors v0.9.1
github.com/ravilushqa/otelgqlgen v0.15.0
github.com/reearth/orb v0.0.0-20250123044717-f6f70ce16355
github.com/reearth/reearthx v0.0.0-20241128091912-9b8bc8adfdd7
github.com/samber/lo v1.39.0
github.com/spf13/afero v1.11.0
Expand Down
4 changes: 2 additions & 2 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/paulmach/go.geojson v1.4.0 h1:5x5moCkCtDo5x8af62P9IOAYGQcYHtxz2QJ3x1DoCgY=
github.com/paulmach/go.geojson v1.4.0/go.mod h1:YaKx1hKpWF+T2oj2lFJPsW/t1Q5e1jQI61eoQSTwpIs=
github.com/pelletier/go-toml v1.0.1-0.20170904195809-1d6b12b7cb29/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
github.com/pierrre/gotestcover v0.0.0-20160517101806-924dca7d15f0/go.mod h1:4xpMLz7RBWyB+ElzHu8Llua96TRCB3YwX+l5EP1wmHk=
Expand All @@ -509,6 +507,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/ravilushqa/otelgqlgen v0.15.0 h1:U85nrlweMXTGaMChUViYM39/MXBZVeVVlpuHq+6eECQ=
github.com/ravilushqa/otelgqlgen v0.15.0/go.mod h1:o+1Eju0VySmgq2BP8Vupz2YrN21Bj7D7imBqu3m2uB8=
github.com/reearth/orb v0.0.0-20250123044717-f6f70ce16355 h1:hmQfd74d4+CdE7vz72n8OPAFocOwVo6yoczZ8eLYKi4=
github.com/reearth/orb v0.0.0-20250123044717-f6f70ce16355/go.mod h1:YWoaA2PfCxtfLyH9+pz5tZh9kwKbPEbRoaIA/DSCt10=
github.com/reearth/reearthx v0.0.0-20241128091912-9b8bc8adfdd7 h1:WyDySGPgHtNXlOu3cPfuQyWM7xbpJc0Cm2a5Ti/2ZwM=
github.com/reearth/reearthx v0.0.0-20241128091912-9b8bc8adfdd7/go.mod h1:/ByvE9o0WANHL2nhOyZjOXWwY8cCgze0OmwyNzxcYoA=
github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s=
Expand Down
2 changes: 1 addition & 1 deletion server/internal/usecase/interactor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewContainer(r *repo.Container, g *gateway.Container,
Asset: NewAsset(r, g),
Dataset: NewDataset(r, g),
Layer: NewLayer(r),
NLSLayer: NewNLSLayer(r),
NLSLayer: NewNLSLayer(r, g),
Style: NewStyle(r),
Plugin: NewPlugin(r, g),
Policy: NewPolicy(r),
Expand Down
Loading

0 comments on commit 2582d68

Please sign in to comment.