Skip to content

Commit

Permalink
v0.1.7 inline org create and misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Nov 12, 2024
1 parent 3d6f325 commit e75e108
Show file tree
Hide file tree
Showing 38 changed files with 893 additions and 627 deletions.
18 changes: 15 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package api

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=api -generate=types -o ./openapi.gen.go ../../config/openapi.yml
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --package=api -generate=types -o ./openapi.gen.go ../../config/openapi.yml

import (
"bytes"
Expand Down Expand Up @@ -204,9 +204,21 @@ func (s *Session) CreateEAB(ctx context.Context, chainSlug, orgSlug, realmSlug,
return &eabOutput, nil
}

func (s *Session) CreateService(ctx context.Context, orgSlug, serviceSlug, serverType string, localhostPort *int) (*Service, error) {
func (s *Session) CreateOrg(ctx context.Context, orgName string) (*Organization, error) {
orgInput := CreateOrgJSONRequestBody{
Name: orgName,
}

var orgOutput Organization
if err := s.post(ctx, "/orgs", orgInput, &orgOutput); err != nil {
return nil, err
}
return &orgOutput, nil
}

func (s *Session) CreateService(ctx context.Context, orgSlug, serviceName, serverType string, localhostPort *int) (*Service, error) {
serviceInput := CreateServiceJSONRequestBody{
Name: serviceSlug,
Name: serviceName,
ServerType: serverType,
LocalhostPort: localhostPort,
}
Expand Down
11 changes: 10 additions & 1 deletion api/openapi.gen.go

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

2 changes: 1 addition & 1 deletion api/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
package api

import (
_ "github.com/deepmap/oapi-codegen/cmd/oapi-codegen"
_ "github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen"
)
4 changes: 2 additions & 2 deletions component/models/selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package models

import (
"fmt"
"reflect"
"strings"

"github.com/charmbracelet/bubbles/list"
Expand Down Expand Up @@ -144,7 +143,8 @@ func (m *Selector[T]) View() string {
return b.String()
}

if reflect.ValueOf(m.chosen.Value).IsZero() {
var zeroT T
if m.chosen.Value == zeroT {
fmt.Fprintln(&b, ui.StepDone(
fmt.Sprintf("Selected %s.", ui.Emphasize(m.chosen.String)),
))
Expand Down
63 changes: 63 additions & 0 deletions component/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,69 @@ func TestSelector(t *testing.T) {
uitest.TestGolden(t, drv.Golden())
})

t.Run("orgs solo creatable", func(t *testing.T) {
if srv.IsProxy() {
t.Skip("selector tests unsupported in proxy mode")
}

cfg.Test.Prefer = map[string]cli.ConfigTestPrefer{
"/v0/orgs": {
Example: "solo",
},
}
ctx = cli.ContextWithConfig(ctx, cfg)

drv, tm := uitest.TestTUI(ctx, t)

choicec := make(chan api.Organization, 1)
errc := make(chan error, 1)
go func() {
selector := component.Selector[api.Organization]{
Prompt: "Which organization do you want for this test?",
Flag: "--org",

Creatable: true,

Fetcher: &component.Fetcher[api.Organization]{
FetchFn: func() ([]api.Organization, error) { return anc.GetOrgs(ctx) },
},
}

org, err := selector.Choice(ctx, drv)
if err != nil {
errc <- err
return
}

choicec <- *org
errc <- tm.Quit()
}()

uitest.WaitForGoldenContains(t, drv, errc,
"? Which organization do you want for this test?",
)

tm.Send(tea.KeyMsg{
Type: tea.KeyDown,
})
tm.Send(tea.KeyMsg{
Type: tea.KeyEnter,
})

org := <-choicec

if want, got := "", org.Slug; want != got {
t.Errorf("Want org choice: %q, Got: %q", want, got)
}

if err := <-errc; err != nil {
t.Error(err)
}

tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second*3))
uitest.TestGolden(t, drv.Golden())
})

t.Run("orgs double", func(t *testing.T) {
if srv.IsProxy() {
t.Skip("selector tests unsupported in proxy mode")
Expand Down
12 changes: 12 additions & 0 deletions component/testdata/TestSelector/orgs_solo_creatable.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
─── Fetcher[github.com/anchordotdev/cli/api.Organization] ──────────────────────
* Fetching organizations…⠋
─── Selector[github.com/anchordotdev/cli/api.Organization] ─────────────────────
? Which organization do you want for this test?
> Solo Org Slug (solo-org-slug)
Create New Organization
─── Selector[github.com/anchordotdev/cli/api.Organization] ─────────────────────
? Which organization do you want for this test?
Solo Org Slug (solo-org-slug)
> Create New Organization
─── Selector[github.com/anchordotdev/cli/api.Organization] ─────────────────────
- Selected Create New Organization.
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Config struct {

Org struct {
APID string `env:"ORG" toml:"apid,omitempty"`
Name string `env:"ORG_NAME" toml:",omitempty,readonly"`
} `toml:"org,omitempty"`

Realm struct {
Expand Down
38 changes: 19 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ require (
github.com/atotto/clipboard v0.1.4
github.com/aymanbagabas/go-udiff v0.2.0
github.com/benburkert/dns v0.0.0-20190225204957-d356cf78cdfc
github.com/brianvoe/gofakeit/v7 v7.0.4
github.com/brianvoe/gofakeit/v7 v7.1.2
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.1.0
github.com/charmbracelet/lipgloss v0.13.0
github.com/charmbracelet/bubbletea v1.1.2
github.com/charmbracelet/lipgloss v1.0.0
github.com/charmbracelet/x/exp/teatest v0.0.0-20240222131549-03ee51df8bea
github.com/cli/browser v1.3.0
github.com/deepmap/oapi-codegen v1.16.3
github.com/fatih/structtag v1.2.0
github.com/go-test/deep v1.1.1
github.com/gofrs/flock v0.12.1
Expand All @@ -24,13 +23,14 @@ require (
github.com/mcuadros/go-defaults v1.2.0
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/muesli/termenv v0.15.2
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
github.com/oapi-codegen/runtime v1.1.1
github.com/pelletier/go-toml/v2 v2.2.3
github.com/r3labs/diff/v3 v3.0.1
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
github.com/zalando/go-keyring v0.2.5
github.com/zalando/go-keyring v0.2.6
golang.org/x/crypto v0.28.0
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81
golang.org/x/sync v0.8.0
Expand All @@ -40,25 +40,25 @@ require (
)

require (
al.essio.dev/pkg/shellescape v1.5.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/x/ansi v0.2.3 // indirect
github.com/charmbracelet/x/ansi v0.4.2 // indirect
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/danieljoos/wincred v1.2.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/getkin/kin-openapi v0.118.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/getkin/kin-openapi v0.127.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/yaml v0.1.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -67,19 +67,19 @@ require (
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/perimeterx/marshmallow v1.1.4 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/sahilm/fuzzy v0.1.1 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.34.3-0.20240830093551-013dd178dc9a // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/tools v0.24.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit e75e108

Please sign in to comment.