mirror of
https://github.com/hashicorp/packer.git
synced 2026-04-20 21:59:08 -04:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package sliceflag
|
|
|
|
import (
|
|
"flag"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestStringFlag_implements(t *testing.T) {
|
|
var raw interface{}
|
|
raw = new(StringFlag)
|
|
if _, ok := raw.(flag.Value); !ok {
|
|
t.Fatalf("StringFlag should be a Value")
|
|
}
|
|
}
|
|
|
|
// TestStringFlagSet tests for setting the same flag more than once on the CLI
|
|
// like: blah -flag foo -flag bar
|
|
func TestStringFlagSet(t *testing.T) {
|
|
sv := new(StringFlag)
|
|
err := sv.Set("foo")
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
err = sv.Set("bar")
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
expected := []string{"foo", "bar"}
|
|
if !reflect.DeepEqual([]string(*sv), expected) {
|
|
t.Fatalf("Bad: %#v", sv)
|
|
}
|
|
}
|
|
|
|
// TestMultiStringFlag tests for setting the same flag using a comma-separated
|
|
// list of items like: blah -flag=foo,bar
|
|
func TestMultiStringFlag(t *testing.T) {
|
|
sv := new(StringFlag)
|
|
err := sv.Set("chocolate,vanilla")
|
|
if err != nil {
|
|
t.Fatalf("err :%s", err)
|
|
}
|
|
|
|
expected := []string{"chocolate", "vanilla"}
|
|
if !reflect.DeepEqual([]string(*sv), expected) {
|
|
t.Fatalf("Expected: %#v, found: %#v", expected, sv)
|
|
}
|
|
}
|