Skip to content

Commit

Permalink
Add DNSNames
Browse files Browse the repository at this point in the history
  • Loading branch information
onee-only committed Jul 16, 2024
1 parent 559a887 commit 8b31279
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 1 deletion.
8 changes: 8 additions & 0 deletions a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
go run cmd/gen-work/main.go \
--n=5000 \
--storepath=. \
--taskID=0c4747d5-41ea-4ac8-82c7-b18aab504671 \
--sectionID=2ee048bc-9af9-410d-8f37-80634bb73bdd \
--method=GET \
--path=/boards \
--templateID=26e95678-a66f-48f1-b265-f0835a505edd
201 changes: 201 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
package main

import (
"context"
"fmt"
"io"
"os"

"github.com/google/uuid"
"github.com/oneee-playground/r2d2-tester/internal/work"
"github.com/oneee-playground/r2d2-tester/internal/work/storage"
)

func loadContent(path string) ([]byte, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}

b, err := io.ReadAll(file)
if err != nil {
return nil, err
}

return b, nil
}

func main() {
storage := storage.NewFSStorage(".")

taskID := uuid.MustParse("0c4747d5-41ea-4ac8-82c7-b18aab504671")
sectionID := uuid.MustParse("2ee048bc-9af9-410d-8f37-80634bb73bdd")

id := uuid.New()
fmt.Println(id)

bodySchema, err := loadContent("input-schema.json")
if err != nil {
panic(err)
}

template := &work.Template{
Id: id[:],
SchemaTable: map[uint32]*work.TemplatedSchema{
200: {
Headers: map[string]string{
"Content-Type": "application/json",
},
BodySchema: bodySchema,
},
},
}

err = storage.InsertTemplate(context.Background(), taskID, sectionID, template)
if err != nil {
panic(err)
}

return

// taskID := uuid.MustParse("0c4747d5-41ea-4ac8-82c7-b18aab504671")
// sectionID := uuid.MustParse("515be74f-ab64-49e0-b10a-b0fbf14e42bf")

// workID := uuid.New()
// work1 := &work.Work{
// Id: workID[:],
// Input: &work.Input{
// Method: "POST",
// Path: "/boards",
// Body: []byte(`{"title":"First Board!","description":"Hello World!"}`),
// },
// ExpectedValue: &work.Expected{Status: http.StatusCreated},
// Timeout: durationpb.New(time.Second),
// }

// err := storage.InsertWork(context.Background(), taskID, sectionID, work1)
// if err != nil {
// panic(err)
// }

// workID = uuid.New()
// work2 := &work.Work{
// Id: workID[:],
// Input: &work.Input{
// Method: "GET",
// Path: "/boards",
// },
// ExpectedValue: &work.Expected{
// Status: http.StatusOK,
// Headers: map[string]string{
// "Content-Type": "application/json",
// },
// Body: []byte(`[{"id":1,"title":"First Board!"}]`),
// },
// Timeout: durationpb.New(time.Second),
// }

// err = storage.InsertWork(context.Background(), taskID, sectionID, work2)
// if err != nil {
// panic(err)
// }

// workID = uuid.New()
// work3 := &work.Work{
// Id: workID[:],
// Input: &work.Input{
// Method: "GET",
// Path: "/boards/1",
// },
// ExpectedValue: &work.Expected{
// Status: http.StatusOK,
// Headers: map[string]string{
// "Content-Type": "application/json",
// },
// Body: []byte(`{"id":1,"title":"First Board!","description":"Hello World!"}`),
// },
// Timeout: durationpb.New(time.Second),
// }

// err = storage.InsertWork(context.Background(), taskID, sectionID, work3)
// if err != nil {
// panic(err)
// }

// workID = uuid.New()
// work4 := &work.Work{
// Id: workID[:],
// Input: &work.Input{
// Method: "PUT",
// Path: "/boards/1",
// Body: []byte(`{"title":"First Board?","description":"Hello World?"}`),
// },
// ExpectedValue: &work.Expected{Status: http.StatusOK},
// Timeout: durationpb.New(time.Second),
// }

// err = storage.InsertWork(context.Background(), taskID, sectionID, work4)
// if err != nil {
// panic(err)
// }

// workID = uuid.New()
// work5 := &work.Work{
// Id: workID[:],
// Input: &work.Input{
// Method: "GET",
// Path: "/boards/1",
// },
// ExpectedValue: &work.Expected{
// Status: http.StatusOK,
// Headers: map[string]string{
// "Content-Type": "application/json",
// },
// Body: []byte(`{"id":1,"title":"First Board?","description":"Hello World?"}`),
// },
// Timeout: durationpb.New(time.Second),
// }

// err = storage.InsertWork(context.Background(), taskID, sectionID, work5)
// if err != nil {
// panic(err)
// }

// workID = uuid.New()
// work6 := &work.Work{
// Id: workID[:],
// Input: &work.Input{
// Method: "DELETE",
// Path: "/boards/1",
// },
// ExpectedValue: &work.Expected{Status: http.StatusNoContent},
// Timeout: durationpb.New(time.Second),
// }

// err = storage.InsertWork(context.Background(), taskID, sectionID, work6)
// if err != nil {
// panic(err)
// }

// workID = uuid.New()
// work7 := &work.Work{
// Id: workID[:],
// Input: &work.Input{
// Method: "GET",
// Path: "/boards",
// },
// ExpectedValue: &work.Expected{
// Status: http.StatusOK,
// Headers: map[string]string{
// "Content-Type": "application/json",
// },
// Body: []byte(`[]`),
// },
// Timeout: durationpb.New(time.Second),
// }

// err = storage.InsertWork(context.Background(), taskID, sectionID, work7)
// if err != nil {
// panic(err)
// }
}
20 changes: 20 additions & 0 deletions input-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "array",
"items": [
{
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "string"
}
},
"required": [
"id",
"title"
]
}
]
}
5 changes: 4 additions & 1 deletion internal/exec/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/go-connections/nat"
"github.com/google/uuid"
"github.com/influxdata/influxdb-client-go/api/write"
Expand Down Expand Up @@ -108,7 +109,9 @@ func (e *Executor) setupResources(
// primary process should be connected to the test network.
e.Log.Info("resource is primary. connecting to test network")

if err := e.Docker.NetworkConnect(ctx, e.TestNetwork, con.ID, nil); err != nil {
if err := e.Docker.NetworkConnect(ctx, e.TestNetwork, con.ID, &network.EndpointSettings{
DNSNames: []string{resource.Name},
}); err != nil {
return errors.Wrap(err, "connecting primary process to test network")
}
}
Expand Down

0 comments on commit 8b31279

Please sign in to comment.