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
283 changes: 283 additions & 0 deletions commands/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,289 @@ services:
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve merge conflicts.

}

func TestRunAppSpecGet_AuthoritySerialization(t *testing.T) {
exactEmpty := ""
exactDomain := "example.com"
pathPrefixSlash := "/"
pathPrefixEmpty := ""

tests := []struct {
name string
exact *string
pathPrefix *string // nil means use "/"
wantJSON string
wantYAML string
}{
{
name: "authority with empty exact string",
exact: &exactEmpty,
pathPrefix: nil,
wantJSON: `{
"name": "test",
"services": [
{
"name": "service",
"github": {
"repo": "digitalocean/doctl",
"branch": "main"
}
}
],
"ingress": {
"rules": [
{
"match": {
"path": {
"prefix": "/"
},
"authority": {
"exact": ""
}
},
"component": {
"name": "service"
}
}
]
}
}
`,
wantYAML: `ingress:
rules:
- component:
name: service
match:
authority:
exact: ""
path:
prefix: /
name: test
services:
- github:
branch: main
repo: digitalocean/doctl
name: service
`,
},
{
name: "authority with non-empty exact string",
exact: &exactDomain,
pathPrefix: nil,
wantJSON: `{
"name": "test",
"services": [
{
"name": "service",
"github": {
"repo": "digitalocean/doctl",
"branch": "main"
}
}
],
"ingress": {
"rules": [
{
"match": {
"path": {
"prefix": "/"
},
"authority": {
"exact": "example.com"
}
},
"component": {
"name": "service"
}
}
]
}
}
`,
wantYAML: `ingress:
rules:
- component:
name: service
match:
authority:
exact: example.com
path:
prefix: /
name: test
services:
- github:
branch: main
repo: digitalocean/doctl
name: service
`,
},
{
name: "no authority set",
exact: nil,
pathPrefix: nil,
wantJSON: `{
"name": "test",
"services": [
{
"name": "service",
"github": {
"repo": "digitalocean/doctl",
"branch": "main"
}
}
],
"ingress": {
"rules": [
{
"match": {
"path": {
"prefix": "/"
}
},
"component": {
"name": "service"
}
}
]
}
}
`,
wantYAML: `ingress:
rules:
- component:
name: service
match:
path:
prefix: /
name: test
services:
- github:
branch: main
repo: digitalocean/doctl
name: service
`,
},
{
name: "authority with empty exact string and empty path prefix",
exact: &exactEmpty,
pathPrefix: &pathPrefixEmpty,
wantJSON: `{
"name": "test",
"services": [
{
"name": "service",
"github": {
"repo": "digitalocean/doctl",
"branch": "main"
}
}
],
"ingress": {
"rules": [
{
"match": {
"path": {
"prefix": ""
},
"authority": {
"exact": ""
}
},
"component": {
"name": "service"
}
}
]
}
}
`,
wantYAML: `ingress:
rules:
- component:
name: service
match:
authority:
exact: ""
path:
prefix: ""
name: test
services:
- github:
branch: main
repo: digitalocean/doctl
name: service
`,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
var authority *godo.AppIngressSpecRuleStringMatch
if tc.exact != nil {
authority = &godo.AppIngressSpecRuleStringMatch{Exact: tc.exact}
}

pathForMatch := &pathPrefixSlash
if tc.pathPrefix != nil {
pathForMatch = tc.pathPrefix
}

spec := &godo.AppSpec{
Name: "test",
Services: []*godo.AppServiceSpec{
{
Name: "service",
GitHub: &godo.GitHubSourceSpec{
Repo: "digitalocean/doctl",
Branch: "main",
},
},
},
Ingress: &godo.AppIngressSpec{
Rules: []*godo.AppIngressSpecRule{
{
Match: &godo.AppIngressSpecRuleMatch{
Path: &godo.AppIngressSpecRuleStringMatch{Prefix: pathForMatch},
Authority: authority,
},
Component: &godo.AppIngressSpecRuleRoutingComponent{Name: "service"},
},
},
},
}

app := &godo.App{
ID: uuid.New().String(),
Spec: spec,
}

tm.apps.EXPECT().Get(app.ID).Times(2).Return(app, nil)

t.Run("json", func(t *testing.T) {
var buf bytes.Buffer
config.Doit.Set(config.NS, doctl.ArgFormat, "json")
config.Args = append(config.Args, app.ID)
config.Out = &buf

err := RunAppsSpecGet(config)
require.NoError(t, err)
require.Equal(t, tc.wantJSON, buf.String())
})

t.Run("yaml", func(t *testing.T) {
var buf bytes.Buffer
config.Doit.Set(config.NS, doctl.ArgFormat, "yaml")
config.Args = append(config.Args, app.ID)
config.Out = &buf

err := RunAppsSpecGet(config)
require.NoError(t, err)
require.Equal(t, tc.wantYAML, buf.String())
})
})
})
}
}
func TestRunAppsListRegions(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
regions := []*godo.AppRegion{{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.25.0
require (
github.com/blang/semver v3.5.1+incompatible
github.com/creack/pty v1.1.21
github.com/digitalocean/godo v1.187.0
github.com/digitalocean/godo v1.189.0
github.com/docker/cli v24.0.5+incompatible
github.com/docker/docker v25.0.6+incompatible
github.com/docker/docker-credential-helpers v0.7.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.187.0 h1:Ga+pkJdebdhnzWmIjusyehDzm+WZ/joLiXM00tPOXVs=
github.com/digitalocean/godo v1.187.0/go.mod h1:xQsWpVCCbkDrWisHA72hPzPlnC+4W5w/McZY5ij9uvU=
github.com/digitalocean/godo v1.189.0 h1:93hHWsZdbJdkMsfZ21lMkOmd+BPMCTzu/+FIJ5FvAL4=
github.com/digitalocean/godo v1.189.0/go.mod h1:xQsWpVCCbkDrWisHA72hPzPlnC+4W5w/McZY5ij9uvU=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/cli v24.0.5+incompatible h1:WeBimjvS0eKdH4Ygx+ihVq1Q++xg36M/rMi4aXAvodc=
Expand Down
10 changes: 10 additions & 0 deletions vendor/github.com/digitalocean/godo/CHANGELOG.md

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

4 changes: 2 additions & 2 deletions vendor/github.com/digitalocean/godo/apps.gen.go

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

8 changes: 4 additions & 4 deletions vendor/github.com/digitalocean/godo/apps_accessors.go

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

2 changes: 1 addition & 1 deletion vendor/github.com/digitalocean/godo/godo.go

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

12 changes: 7 additions & 5 deletions vendor/github.com/digitalocean/godo/kubernetes.go

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

Loading
Loading