1
0
mirror of https://github.com/ko-build/ko.git synced 2025-07-06 23:36:54 +02:00
Files
ko-build/pkg/commands/config_test.go
Wilson E. Husin c67fb03b79 Pre-parse platform string with StringSliceVar (#551)
* Pre-parse platform string with StringSliceVar

This allows users to declare --platform multiple times and have the
values appended, i.e.:
  ko build --platform=linux/amd64 --platform=linux/arm64
is equivalent to
  ko build --platform=linux/amd64,linux/arm64

As a side effect, platformMatcher.spec and gobuildOpener.platforms are
now of type []string (instead of string) to maintain structure of
information from flag parsing.

* Adjust comments and styling for clarity.

* The flag --platform is now of type strings.

Internally cobra/pflag defines StringSliceVar as "strings" whereas
StringVar is defined as "string".

This change is updated by running hack/update-codegen.sh script.

* Add backwards compatibility for WithPlatforms function signature

Update comments to reflect implementation as well.

* Fix syntax failure on unit test
2022-01-04 14:19:52 -05:00

62 lines
1.6 KiB
Go

/*
Copyright 2021 Google LLC All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package commands
import (
"context"
"fmt"
"testing"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/ko/pkg/commands/options"
)
func TestOverrideDefaultBaseImageUsingBuildOption(t *testing.T) {
namespace := "base"
s, err := registryServerWithImage(namespace)
if err != nil {
t.Fatalf("could not create test registry server: %v", err)
}
defer s.Close()
baseImage := fmt.Sprintf("%s/%s", s.Listener.Addr().String(), namespace)
wantDigest, err := crane.Digest(baseImage)
if err != nil {
t.Fatalf("crane.Digest(%s): %v", baseImage, err)
}
wantImage := fmt.Sprintf("%s@%s", baseImage, wantDigest)
bo := &options.BuildOptions{
BaseImage: wantImage,
Platforms: []string{"all"},
}
baseFn := getBaseImage(bo)
_, res, err := baseFn(context.Background(), "ko://example.com/helloworld")
if err != nil {
t.Fatalf("getBaseImage(): %v", err)
}
digest, err := res.Digest()
if err != nil {
t.Fatalf("res.Digest(): %v", err)
}
gotDigest := digest.String()
if gotDigest != wantDigest {
t.Errorf("got digest %s, wanted %s", gotDigest, wantDigest)
}
}