Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

spec: Define ACString type and use it for labels values #590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions actool/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"

"github.com/appc/spec/discovery"
"github.com/appc/spec/schema/types"
)

var (
Expand Down Expand Up @@ -49,10 +50,10 @@ func runDiscover(args []string) (exit int) {
for _, name := range args {
app, err := discovery.NewAppFromString(name)
if app.Labels["os"] == "" {
app.Labels["os"] = runtime.GOOS
app.Labels["os"] = types.ACString(runtime.GOOS)
}
if app.Labels["arch"] == "" {
app.Labels["arch"] = runtime.GOARCH
app.Labels["arch"] = types.ACString(runtime.GOARCH)
}
if err != nil {
stderr("%s: %s", name, err)
Expand Down
2 changes: 1 addition & 1 deletion discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func createTemplateVars(app App) []string {
// If a label is called "name", it will be ignored as it appears after
// in the slice
for n, v := range app.Labels {
tplVars = append(tplVars, fmt.Sprintf("{%s}", n), v)
tplVars = append(tplVars, fmt.Sprintf("{%s}", n), v.String())
}
return tplVars
}
Expand Down
26 changes: 13 additions & 13 deletions discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp/foobar",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestDiscoverEndpoints(t *testing.T) {
false,
App{
Name: "example.com/myapp/foobar/bazzer",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestDiscoverEndpoints(t *testing.T) {
false,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
Expand Down Expand Up @@ -351,7 +351,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
Expand Down Expand Up @@ -389,7 +389,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
},
},
Expand Down Expand Up @@ -419,7 +419,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{},
Labels: map[types.ACIdentifier]types.ACString{},
},
[]ACIEndpoint{
ACIEndpoint{
Expand All @@ -446,7 +446,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"name": "labelcalledname",
"version": "1.0.0",
},
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
Expand Down Expand Up @@ -516,7 +516,7 @@ func TestDiscoverEndpoints(t *testing.T) {
true,
App{
Name: "example.com/myapp",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
"os": "linux",
"arch": "amd64",
Expand Down
18 changes: 11 additions & 7 deletions discovery/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (

type App struct {
Name types.ACIdentifier
Labels map[types.ACIdentifier]string
Labels map[types.ACIdentifier]types.ACString
}

func NewApp(name string, labels map[types.ACIdentifier]string) (*App, error) {
func NewApp(name string, labels map[types.ACIdentifier]types.ACString) (*App, error) {
if labels == nil {
labels = make(map[types.ACIdentifier]string, 0)
labels = make(map[types.ACIdentifier]types.ACString, 0)
}
acn, err := types.NewACIdentifier(name)
if err != nil {
Expand All @@ -55,7 +55,7 @@ func NewApp(name string, labels map[types.ACIdentifier]string) (*App, error) {
func NewAppFromString(app string) (*App, error) {
var (
name string
labels map[types.ACIdentifier]string
labels map[types.ACIdentifier]types.ACString
)

preparedApp, err := prepareAppString(app)
Expand All @@ -66,7 +66,7 @@ func NewAppFromString(app string) (*App, error) {
if err != nil {
return nil, err
}
labels = make(map[types.ACIdentifier]string, 0)
labels = make(map[types.ACIdentifier]types.ACString, 0)
for key, val := range v {
if len(val) > 1 {
return nil, fmt.Errorf("label %s with multiple values %q", key, val)
Expand All @@ -79,7 +79,11 @@ func NewAppFromString(app string) (*App, error) {
if err != nil {
return nil, err
}
labels[*labelName] = val[0]
acsv, err := types.NewACString(val[0])
if err != nil {
return nil, err
}
labels[*labelName] = *acsv
}
a, err := NewApp(name, labels)
if err != nil {
Expand Down Expand Up @@ -112,7 +116,7 @@ func checkColon(app string) error {
func (a *App) Copy() *App {
ac := &App{
Name: a.Name,
Labels: make(map[types.ACIdentifier]string, 0),
Labels: make(map[types.ACIdentifier]types.ACString, 0),
}
for k, v := range a.Labels {
ac.Labels[k] = v
Expand Down
18 changes: 9 additions & 9 deletions discovery/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestNewAppFromString(t *testing.T) {

&App{
Name: "example.com/reduce-worker",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
},
},
Expand All @@ -44,7 +44,7 @@ func TestNewAppFromString(t *testing.T) {

&App{
Name: "example.com/reduce-worker",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"channel": "alpha",
"label": "value",
},
Expand All @@ -57,7 +57,7 @@ func TestNewAppFromString(t *testing.T) {

&App{
Name: "example.com/app",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.2.3",
"special": "!*'();@&+$/?#[]",
"channel": "beta",
Expand Down Expand Up @@ -133,14 +133,14 @@ func TestAppString(t *testing.T) {
{
&App{
Name: "example.com/reduce-worker",
Labels: map[types.ACIdentifier]string{},
Labels: map[types.ACIdentifier]types.ACString{},
},
"example.com/reduce-worker",
},
{
&App{
Name: "example.com/reduce-worker",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
},
},
Expand All @@ -149,7 +149,7 @@ func TestAppString(t *testing.T) {
{
&App{
Name: "example.com/reduce-worker",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"channel": "alpha",
"label": "value",
},
Expand Down Expand Up @@ -178,14 +178,14 @@ func TestAppCopy(t *testing.T) {
{
&App{
Name: "example.com/reduce-worker",
Labels: map[types.ACIdentifier]string{},
Labels: map[types.ACIdentifier]types.ACString{},
},
"example.com/reduce-worker",
},
{
&App{
Name: "example.com/reduce-worker",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"version": "1.0.0",
},
},
Expand All @@ -194,7 +194,7 @@ func TestAppCopy(t *testing.T) {
{
&App{
Name: "example.com/reduce-worker",
Labels: map[types.ACIdentifier]string{
Labels: map[types.ACIdentifier]types.ACString{
"channel": "alpha",
"label": "value",
},
Expand Down
2 changes: 1 addition & 1 deletion schema/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (im *ImageManifest) assertValid() error {
return nil
}

func (im *ImageManifest) GetLabel(name string) (val string, ok bool) {
func (im *ImageManifest) GetLabel(name string) (val types.ACString, ok bool) {
return im.Labels.Get(name)
}

Expand Down
Loading