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

Commit

Permalink
autofill platform if not present
Browse files Browse the repository at this point in the history
resolves tetratelabs/func-e#23

Signed-off-by: Liam White <liam@tetrate.io>
  • Loading branch information
liamawhite committed Aug 2, 2019
1 parent ddd71c1 commit 98f2a01
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pkg/manifest/locate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ import (

// NewKey creates a manifest key based on the reference it is given
func NewKey(reference string) (*Key, error) {
r := regexp.MustCompile(`^(.+):(.+)/(.+)$`)
r := regexp.MustCompile(`^([\w\d-\._]+):([\w\d-\._]+)/?([\w\d-\._]+)?$`)
matches := r.FindStringSubmatch(reference)
if len(matches) != 4 {
return nil, fmt.Errorf("reference %v is not of valid format <flavor>:<version>/<platform>", reference)
}

// If platform is empty, fill it in.
if len(matches[3]) == 0 {
matches[3] = platform()
}
return &Key{strings.ToLower(matches[1]), strings.ToLower(matches[2]), platformToEnum(matches[3])}, nil
}

Expand Down
13 changes: 11 additions & 2 deletions pkg/manifest/locate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package manifest

import (
"fmt"
"net/http"
"testing"

Expand All @@ -36,6 +37,12 @@ func TestLocate(t *testing.T) {
want: "standard:1.11.0/linux-glibc",
responseStatusCode: http.StatusOK,
},
{
name: "standard 1.11.0 matches",
reference: "standard:1.11.0",
want: fmt.Sprintf("standard:1.11.0/%v", platform()),
responseStatusCode: http.StatusOK,
},
{
name: "standard-fips1402:1.10.0/linux-glibc matches",
reference: "standard-fips1402:1.10.0/linux-glibc",
Expand Down Expand Up @@ -92,11 +99,13 @@ func TestNewKey(t *testing.T) {
want *Key
wantErr bool
}{
{"flavor:version/platform/platform", nil, true},
{"flavor:version/platform", &Key{Flavor: "flavor", Version: "version", Platform: "PLATFORM"}, false},
{"flavor:version/platform-glibc", &Key{Flavor: "flavor", Version: "version", Platform: "PLATFORM_GLIBC"}, false},
{"fLaVoR:VeRsIoN/pLaTfOrM", &Key{Flavor: "flavor", Version: "version", Platform: "PLATFORM"}, false},
{"flavor:version/", nil, true},
{"flavor:version", nil, true},
{"flavor:version/", &Key{Flavor: "flavor", Version: "version", Platform: platformToEnum(platform())}, false},
{"flavor:version", &Key{Flavor: "flavor", Version: "version", Platform: platformToEnum(platform())}, false},
{"fLaVoR:VeRsIoN", &Key{Flavor: "flavor", Version: "version", Platform: platformToEnum(platform())}, false},
{"flavor:", nil, true},
{"flavor", nil, true},
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/manifest/platform_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package manifest

func platform() string {
return "darwin"
}
5 changes: 5 additions & 0 deletions pkg/manifest/platform_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package manifest

func platform() string {
return "linux-glibc"
}

0 comments on commit 98f2a01

Please sign in to comment.