github.com/coreos/mantle@v0.13.0/system/exec/multicall_test.go (about)

     1  // Copyright 2015 CoreOS, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package exec
    16  
    17  import (
    18  	"fmt"
    19  	"os"
    20  	"testing"
    21  )
    22  
    23  var testMulticall Entrypoint
    24  
    25  func init() {
    26  	testMulticall = NewEntrypoint("testMulticall", testMulticallHelper)
    27  }
    28  
    29  func testMulticallHelper(args []string) error {
    30  	fmt.Println(args)
    31  	return nil
    32  }
    33  
    34  func TestMain(m *testing.M) {
    35  	MaybeExec()
    36  	os.Exit(m.Run())
    37  }
    38  
    39  func TestMulticallNoArgs(t *testing.T) {
    40  	cmd := testMulticall.Command()
    41  	out, err := cmd.Output()
    42  	if err != nil {
    43  		t.Error(err)
    44  	}
    45  	if string(out) != "[]\n" {
    46  		t.Errorf("Unexpected output: %q", string(out))
    47  	}
    48  }
    49  
    50  func TestMulticallWithArgs(t *testing.T) {
    51  	cmd := testMulticall.Command("arg1", "020")
    52  	out, err := cmd.Output()
    53  	if err != nil {
    54  		t.Error(err)
    55  	}
    56  	if string(out) != "[arg1 020]\n" {
    57  		t.Errorf("Unexpected output: %q", string(out))
    58  	}
    59  }